blob: 9a7dc405e7edc20db44058c0c95a084bc3280790 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 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
Don Skidmore8c5afd62013-03-01 07:09:43 +000066#define DRV_VERSION "3.13.10-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070067const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000068static const char ixgbe_copyright[] =
Don Skidmore434c5e32013-01-08 05:02:28 +000069 "Copyright (c) 1999-2013 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070070
71static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070072 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000073 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e2010-11-16 19:27:16 -080074 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070075};
76
77/* ixgbe_pci_tbl - PCI Device ID Table
78 *
79 * Wildcard entries (PCI_ANY_ID) should come last
80 * Last entry must be all 0s
81 *
82 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
83 * Class, Class Mask, private data (not used) }
84 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000085static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700115 /* required last entry */
116 {0, }
117};
118MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
119
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400120#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800121static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000122 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800123static struct notifier_block dca_notifier = {
124 .notifier_call = ixgbe_notify_dca,
125 .next = NULL,
126 .priority = 0
127};
128#endif
129
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000130#ifdef CONFIG_PCI_IOV
131static unsigned int max_vfs;
132module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000133MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000134 "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 +0000135#endif /* CONFIG_PCI_IOV */
136
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000137static unsigned int allow_unsupported_sfp;
138module_param(allow_unsupported_sfp, uint, 0);
139MODULE_PARM_DESC(allow_unsupported_sfp,
140 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
141
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000142#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
143static int debug = -1;
144module_param(debug, int, 0);
145MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
146
Auke Kok9a799d72007-09-15 14:07:45 -0700147MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
148MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
149MODULE_LICENSE("GPL");
150MODULE_VERSION(DRV_VERSION);
151
Jacob Kellerb8e82002013-04-09 07:20:09 +0000152static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
153 u32 reg, u16 *value)
154{
155 int pos = 0;
156 struct pci_dev *parent_dev;
157 struct pci_bus *parent_bus;
158
159 parent_bus = adapter->pdev->bus->parent;
160 if (!parent_bus)
161 return -1;
162
163 parent_dev = parent_bus->self;
164 if (!parent_dev)
165 return -1;
166
167 pos = pci_find_capability(parent_dev, PCI_CAP_ID_EXP);
168 if (!pos)
169 return -1;
170
171 pci_read_config_word(parent_dev, pos + reg, value);
172 return 0;
173}
174
175static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
176{
177 struct ixgbe_hw *hw = &adapter->hw;
178 u16 link_status = 0;
179 int err;
180
181 hw->bus.type = ixgbe_bus_type_pci_express;
182
183 /* Get the negotiated link width and speed from PCI config space of the
184 * parent, as this device is behind a switch
185 */
186 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
187
188 /* assume caller will handle error case */
189 if (err)
190 return err;
191
192 hw->bus.width = ixgbe_convert_bus_width(link_status);
193 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
194
195 return 0;
196}
197
Alexander Duyck70864002011-04-27 09:13:56 +0000198static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
199{
200 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
201 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
202 schedule_work(&adapter->service_task);
203}
204
205static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
206{
207 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
208
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000209 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000210 smp_mb__before_clear_bit();
211 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
212}
213
Taku Izumidcd79ae2010-04-27 14:39:53 +0000214struct ixgbe_reg_info {
215 u32 ofs;
216 char *name;
217};
218
219static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
220
221 /* General Registers */
222 {IXGBE_CTRL, "CTRL"},
223 {IXGBE_STATUS, "STATUS"},
224 {IXGBE_CTRL_EXT, "CTRL_EXT"},
225
226 /* Interrupt Registers */
227 {IXGBE_EICR, "EICR"},
228
229 /* RX Registers */
230 {IXGBE_SRRCTL(0), "SRRCTL"},
231 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
232 {IXGBE_RDLEN(0), "RDLEN"},
233 {IXGBE_RDH(0), "RDH"},
234 {IXGBE_RDT(0), "RDT"},
235 {IXGBE_RXDCTL(0), "RXDCTL"},
236 {IXGBE_RDBAL(0), "RDBAL"},
237 {IXGBE_RDBAH(0), "RDBAH"},
238
239 /* TX Registers */
240 {IXGBE_TDBAL(0), "TDBAL"},
241 {IXGBE_TDBAH(0), "TDBAH"},
242 {IXGBE_TDLEN(0), "TDLEN"},
243 {IXGBE_TDH(0), "TDH"},
244 {IXGBE_TDT(0), "TDT"},
245 {IXGBE_TXDCTL(0), "TXDCTL"},
246
247 /* List Terminator */
248 {}
249};
250
251
252/*
253 * ixgbe_regdump - register printout routine
254 */
255static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
256{
257 int i = 0, j = 0;
258 char rname[16];
259 u32 regs[64];
260
261 switch (reginfo->ofs) {
262 case IXGBE_SRRCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
265 break;
266 case IXGBE_DCA_RXCTRL(0):
267 for (i = 0; i < 64; i++)
268 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
269 break;
270 case IXGBE_RDLEN(0):
271 for (i = 0; i < 64; i++)
272 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
273 break;
274 case IXGBE_RDH(0):
275 for (i = 0; i < 64; i++)
276 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
277 break;
278 case IXGBE_RDT(0):
279 for (i = 0; i < 64; i++)
280 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
281 break;
282 case IXGBE_RXDCTL(0):
283 for (i = 0; i < 64; i++)
284 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
285 break;
286 case IXGBE_RDBAL(0):
287 for (i = 0; i < 64; i++)
288 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
289 break;
290 case IXGBE_RDBAH(0):
291 for (i = 0; i < 64; i++)
292 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
293 break;
294 case IXGBE_TDBAL(0):
295 for (i = 0; i < 64; i++)
296 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
297 break;
298 case IXGBE_TDBAH(0):
299 for (i = 0; i < 64; i++)
300 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
301 break;
302 case IXGBE_TDLEN(0):
303 for (i = 0; i < 64; i++)
304 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
305 break;
306 case IXGBE_TDH(0):
307 for (i = 0; i < 64; i++)
308 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
309 break;
310 case IXGBE_TDT(0):
311 for (i = 0; i < 64; i++)
312 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
313 break;
314 case IXGBE_TXDCTL(0):
315 for (i = 0; i < 64; i++)
316 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
317 break;
318 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000319 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000320 IXGBE_READ_REG(hw, reginfo->ofs));
321 return;
322 }
323
324 for (i = 0; i < 8; i++) {
325 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000326 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000327 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000328 pr_cont(" %08x", regs[i*8+j]);
329 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 }
331
332}
333
334/*
335 * ixgbe_dump - Print registers, tx-rings and rx-rings
336 */
337static void ixgbe_dump(struct ixgbe_adapter *adapter)
338{
339 struct net_device *netdev = adapter->netdev;
340 struct ixgbe_hw *hw = &adapter->hw;
341 struct ixgbe_reg_info *reginfo;
342 int n = 0;
343 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000344 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000345 union ixgbe_adv_tx_desc *tx_desc;
346 struct my_u0 { u64 a; u64 b; } *u0;
347 struct ixgbe_ring *rx_ring;
348 union ixgbe_adv_rx_desc *rx_desc;
349 struct ixgbe_rx_buffer *rx_buffer_info;
350 u32 staterr;
351 int i = 0;
352
353 if (!netif_msg_hw(adapter))
354 return;
355
356 /* Print netdevice Info */
357 if (netdev) {
358 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000359 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000360 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("%-15s %016lX %016lX %016lX\n",
362 netdev->name,
363 netdev->state,
364 netdev->trans_start,
365 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000366 }
367
368 /* Print Registers */
369 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000370 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000371 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
372 reginfo->name; reginfo++) {
373 ixgbe_regdump(hw, reginfo);
374 }
375
376 /* Print TX Ring Summary */
377 if (!netdev || !netif_running(netdev))
378 goto exit;
379
380 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000381 pr_info(" %s %s %s %s\n",
382 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
383 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 for (n = 0; n < adapter->num_tx_queues; n++) {
385 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000386 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000387 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000389 (u64)dma_unmap_addr(tx_buffer, dma),
390 dma_unmap_len(tx_buffer, len),
391 tx_buffer->next_to_watch,
392 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000393 }
394
395 /* Print TX Rings */
396 if (!netif_msg_tx_done(adapter))
397 goto rx_ring_summary;
398
399 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
400
401 /* Transmit Descriptor Formats
402 *
Josh Hay39ac8682012-09-26 05:59:36 +0000403 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000404 * +--------------------------------------------------------------+
405 * 0 | Buffer Address [63:0] |
406 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000407 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000408 * +--------------------------------------------------------------+
409 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000410 *
411 * 82598 Advanced Transmit Descriptor (Write-Back Format)
412 * +--------------------------------------------------------------+
413 * 0 | RSV [63:0] |
414 * +--------------------------------------------------------------+
415 * 8 | RSV | STA | NXTSEQ |
416 * +--------------------------------------------------------------+
417 * 63 36 35 32 31 0
418 *
419 * 82599+ Advanced Transmit Descriptor
420 * +--------------------------------------------------------------+
421 * 0 | Buffer Address [63:0] |
422 * +--------------------------------------------------------------+
423 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
424 * +--------------------------------------------------------------+
425 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
426 *
427 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
428 * +--------------------------------------------------------------+
429 * 0 | RSV [63:0] |
430 * +--------------------------------------------------------------+
431 * 8 | RSV | STA | RSV |
432 * +--------------------------------------------------------------+
433 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000434 */
435
436 for (n = 0; n < adapter->num_tx_queues; n++) {
437 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("------------------------------------\n");
439 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
440 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000441 pr_info("%s%s %s %s %s %s\n",
442 "T [desc] [address 63:0 ] ",
443 "[PlPOIdStDDt Ln] [bi->dma ] ",
444 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445
446 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000447 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000448 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000449 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000450 if (dma_unmap_len(tx_buffer, len) > 0) {
451 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
452 i,
453 le64_to_cpu(u0->a),
454 le64_to_cpu(u0->b),
455 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000456 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000457 tx_buffer->next_to_watch,
458 (u64)tx_buffer->time_stamp,
459 tx_buffer->skb);
460 if (i == tx_ring->next_to_use &&
461 i == tx_ring->next_to_clean)
462 pr_cont(" NTC/U\n");
463 else if (i == tx_ring->next_to_use)
464 pr_cont(" NTU\n");
465 else if (i == tx_ring->next_to_clean)
466 pr_cont(" NTC\n");
467 else
468 pr_cont("\n");
469
470 if (netif_msg_pktdata(adapter) &&
471 tx_buffer->skb)
472 print_hex_dump(KERN_INFO, "",
473 DUMP_PREFIX_ADDRESS, 16, 1,
474 tx_buffer->skb->data,
475 dma_unmap_len(tx_buffer, len),
476 true);
477 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000478 }
479 }
480
481 /* Print RX Rings Summary */
482rx_ring_summary:
483 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000484 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000485 for (n = 0; n < adapter->num_rx_queues; n++) {
486 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_info("%5d %5X %5X\n",
488 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000489 }
490
491 /* Print RX Rings */
492 if (!netif_msg_rx_status(adapter))
493 goto exit;
494
495 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
496
Josh Hay39ac8682012-09-26 05:59:36 +0000497 /* Receive Descriptor Formats
498 *
499 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000500 * 63 1 0
501 * +-----------------------------------------------------+
502 * 0 | Packet Buffer Address [63:1] |A0/NSE|
503 * +----------------------------------------------+------+
504 * 8 | Header Buffer Address [63:1] | DD |
505 * +-----------------------------------------------------+
506 *
507 *
Josh Hay39ac8682012-09-26 05:59:36 +0000508 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000509 *
510 * 63 48 47 32 31 30 21 20 16 15 4 3 0
511 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000512 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
513 * | Packet | IP | | | | Type | Type |
514 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000515 * +------------------------------------------------------+
516 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
517 * +------------------------------------------------------+
518 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000519 *
520 * 82599+ Advanced Receive Descriptor (Read) Format
521 * 63 1 0
522 * +-----------------------------------------------------+
523 * 0 | Packet Buffer Address [63:1] |A0/NSE|
524 * +----------------------------------------------+------+
525 * 8 | Header Buffer Address [63:1] | DD |
526 * +-----------------------------------------------------+
527 *
528 *
529 * 82599+ Advanced Receive Descriptor (Write-Back) Format
530 *
531 * 63 48 47 32 31 30 21 20 17 16 4 3 0
532 * +------------------------------------------------------+
533 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
534 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
535 * |/ Flow Dir Flt ID | | | | | |
536 * +------------------------------------------------------+
537 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
538 * +------------------------------------------------------+
539 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540 */
Josh Hay39ac8682012-09-26 05:59:36 +0000541
Taku Izumidcd79ae2010-04-27 14:39:53 +0000542 for (n = 0; n < adapter->num_rx_queues; n++) {
543 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000544 pr_info("------------------------------------\n");
545 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
546 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000547 pr_info("%s%s%s",
548 "R [desc] [ PktBuf A0] ",
549 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000550 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000551 pr_info("%s%s%s",
552 "RWB[desc] [PcsmIpSHl PtRs] ",
553 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000554 "<-- Adv Rx Write-Back format\n");
555
556 for (i = 0; i < rx_ring->count; i++) {
557 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000558 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000559 u0 = (struct my_u0 *)rx_desc;
560 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
561 if (staterr & IXGBE_RXD_STAT_DD) {
562 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000563 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000564 "%016llX ---------------- %p", i,
565 le64_to_cpu(u0->a),
566 le64_to_cpu(u0->b),
567 rx_buffer_info->skb);
568 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000569 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000570 "%016llX %016llX %p", i,
571 le64_to_cpu(u0->a),
572 le64_to_cpu(u0->b),
573 (u64)rx_buffer_info->dma,
574 rx_buffer_info->skb);
575
Emil Tantilov9c50c032012-07-26 01:21:24 +0000576 if (netif_msg_pktdata(adapter) &&
577 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000578 print_hex_dump(KERN_INFO, "",
579 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000580 page_address(rx_buffer_info->page) +
581 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000582 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000583 }
584 }
585
586 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000587 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000588 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000589 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000590 else
Joe Perchesc7689572010-09-07 21:35:17 +0000591 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592
593 }
594 }
595
596exit:
597 return;
598}
599
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800600static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
601{
602 u32 ctrl_ext;
603
604 /* Let firmware take over control of h/w */
605 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
606 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000607 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800608}
609
610static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
611{
612 u32 ctrl_ext;
613
614 /* Let firmware know the driver has taken over */
615 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
616 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000617 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800618}
Auke Kok9a799d72007-09-15 14:07:45 -0700619
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000620/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000621 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
622 * @adapter: pointer to adapter struct
623 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
624 * @queue: queue to map the corresponding interrupt to
625 * @msix_vector: the vector to map to the corresponding queue
626 *
627 */
628static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000629 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700630{
631 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000632 struct ixgbe_hw *hw = &adapter->hw;
633 switch (hw->mac.type) {
634 case ixgbe_mac_82598EB:
635 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
636 if (direction == -1)
637 direction = 0;
638 index = (((direction * 64) + queue) >> 2) & 0x1F;
639 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
640 ivar &= ~(0xFF << (8 * (queue & 0x3)));
641 ivar |= (msix_vector << (8 * (queue & 0x3)));
642 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
643 break;
644 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800645 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000646 if (direction == -1) {
647 /* other causes */
648 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
649 index = ((queue & 1) * 8);
650 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
651 ivar &= ~(0xFF << index);
652 ivar |= (msix_vector << index);
653 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
654 break;
655 } else {
656 /* tx or rx causes */
657 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
658 index = ((16 * (queue & 1)) + (8 * direction));
659 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
660 ivar &= ~(0xFF << index);
661 ivar |= (msix_vector << index);
662 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
663 break;
664 }
665 default:
666 break;
667 }
Auke Kok9a799d72007-09-15 14:07:45 -0700668}
669
Alexander Duyckfe49f042009-06-04 16:00:09 +0000670static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000671 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000672{
673 u32 mask;
674
Alexander Duyckbd508172010-11-16 19:27:03 -0800675 switch (adapter->hw.mac.type) {
676 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000677 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
678 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800679 break;
680 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800681 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000682 mask = (qmask & 0xFFFFFFFF);
683 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
684 mask = (qmask >> 32);
685 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800686 break;
687 default:
688 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000689 }
690}
691
Alexander Duyck729739b2012-02-08 07:51:06 +0000692void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
693 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000694{
Alexander Duyck729739b2012-02-08 07:51:06 +0000695 if (tx_buffer->skb) {
696 dev_kfree_skb_any(tx_buffer->skb);
697 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000698 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000699 dma_unmap_addr(tx_buffer, dma),
700 dma_unmap_len(tx_buffer, len),
701 DMA_TO_DEVICE);
702 } else if (dma_unmap_len(tx_buffer, len)) {
703 dma_unmap_page(ring->dev,
704 dma_unmap_addr(tx_buffer, dma),
705 dma_unmap_len(tx_buffer, len),
706 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000707 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000708 tx_buffer->next_to_watch = NULL;
709 tx_buffer->skb = NULL;
710 dma_unmap_len_set(tx_buffer, len, 0);
711 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700712}
713
Alexander Duyck943561d2012-05-09 22:14:44 -0700714static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
715{
716 struct ixgbe_hw *hw = &adapter->hw;
717 struct ixgbe_hw_stats *hwstats = &adapter->stats;
718 int i;
719 u32 data;
720
721 if ((hw->fc.current_mode != ixgbe_fc_full) &&
722 (hw->fc.current_mode != ixgbe_fc_rx_pause))
723 return;
724
725 switch (hw->mac.type) {
726 case ixgbe_mac_82598EB:
727 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
728 break;
729 default:
730 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
731 }
732 hwstats->lxoffrxc += data;
733
734 /* refill credits (no tx hang) if we received xoff */
735 if (!data)
736 return;
737
738 for (i = 0; i < adapter->num_tx_queues; i++)
739 clear_bit(__IXGBE_HANG_CHECK_ARMED,
740 &adapter->tx_ring[i]->state);
741}
742
John Fastabendc84d3242010-11-16 19:27:12 -0800743static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700744{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700745 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800746 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800747 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000748 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800749 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700750 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700751
Alexander Duyck943561d2012-05-09 22:14:44 -0700752 if (adapter->ixgbe_ieee_pfc)
753 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800754
Alexander Duyck943561d2012-05-09 22:14:44 -0700755 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
756 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800757 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700758 }
John Fastabendc84d3242010-11-16 19:27:12 -0800759
760 /* update stats for each tc, only valid with PFC enabled */
761 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000762 u32 pxoffrxc;
763
John Fastabendc84d3242010-11-16 19:27:12 -0800764 switch (hw->mac.type) {
765 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000766 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800767 break;
768 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000769 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800770 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000771 hwstats->pxoffrxc[i] += pxoffrxc;
772 /* Get the TC for given UP */
773 tc = netdev_get_prio_tc_map(adapter->netdev, i);
774 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700775 }
776
John Fastabendc84d3242010-11-16 19:27:12 -0800777 /* disarm tx queues that have received xoff frames */
778 for (i = 0; i < adapter->num_tx_queues; i++) {
779 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800780
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000781 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800782 if (xoff[tc])
783 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
784 }
785}
786
787static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
788{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000789 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800790}
791
792static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
793{
794 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
795 struct ixgbe_hw *hw = &adapter->hw;
796
797 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
798 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
799
800 if (head != tail)
801 return (head < tail) ?
802 tail - head : (tail + ring->count - head);
803
804 return 0;
805}
806
807static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
808{
809 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
810 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
811 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
812 bool ret = false;
813
814 clear_check_for_tx_hang(tx_ring);
815
816 /*
817 * Check for a hung queue, but be thorough. This verifies
818 * that a transmit has been completed since the previous
819 * check AND there is at least one packet pending. The
820 * ARMED bit is set to indicate a potential hang. The
821 * bit is cleared if a pause frame is received to remove
822 * false hang detection due to PFC or 802.3x frames. By
823 * requiring this to fail twice we avoid races with
824 * pfc clearing the ARMED bit and conditions where we
825 * run the check_tx_hang logic with a transmit completion
826 * pending but without time to complete it yet.
827 */
828 if ((tx_done_old == tx_done) && tx_pending) {
829 /* make sure it is true for two checks in a row */
830 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
831 &tx_ring->state);
832 } else {
833 /* update completed stats and continue */
834 tx_ring->tx_stats.tx_done_old = tx_done;
835 /* reset the countdown */
836 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
837 }
838
839 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700840}
841
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000842/**
843 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
844 * @adapter: driver private struct
845 **/
846static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
847{
848
849 /* Do the reset outside of interrupt context */
850 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
851 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Jacob Keller12ff3f32012-12-01 07:57:17 +0000852 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000853 ixgbe_service_event_schedule(adapter);
854 }
855}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700856
Auke Kok9a799d72007-09-15 14:07:45 -0700857/**
858 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000859 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700860 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700861 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000862static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000863 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700864{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000865 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000866 struct ixgbe_tx_buffer *tx_buffer;
867 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700868 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000869 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000870 unsigned int i = tx_ring->next_to_clean;
871
872 if (test_bit(__IXGBE_DOWN, &adapter->state))
873 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700874
Alexander Duyckd3d00232011-07-15 02:31:25 +0000875 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000876 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000877 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800878
Alexander Duyck729739b2012-02-08 07:51:06 +0000879 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000880 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700881
Alexander Duyckd3d00232011-07-15 02:31:25 +0000882 /* if next_to_watch is not set then there is no work pending */
883 if (!eop_desc)
884 break;
885
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000886 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +0000887 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000888
Alexander Duyckd3d00232011-07-15 02:31:25 +0000889 /* if DD is not set pending work has not been completed */
890 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
891 break;
892
Alexander Duyckd3d00232011-07-15 02:31:25 +0000893 /* clear next_to_watch to prevent false hangs */
894 tx_buffer->next_to_watch = NULL;
895
Alexander Duyck091a6242012-02-08 07:51:01 +0000896 /* update the statistics for this packet */
897 total_bytes += tx_buffer->bytecount;
898 total_packets += tx_buffer->gso_segs;
899
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000900 /* free the skb */
901 dev_kfree_skb_any(tx_buffer->skb);
902
Alexander Duyck729739b2012-02-08 07:51:06 +0000903 /* unmap skb header data */
904 dma_unmap_single(tx_ring->dev,
905 dma_unmap_addr(tx_buffer, dma),
906 dma_unmap_len(tx_buffer, len),
907 DMA_TO_DEVICE);
908
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000909 /* clear tx_buffer data */
910 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000911 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000912
Alexander Duyck729739b2012-02-08 07:51:06 +0000913 /* unmap remaining buffers */
914 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000915 tx_buffer++;
916 tx_desc++;
917 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000918 if (unlikely(!i)) {
919 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000920 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000921 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000922 }
923
Alexander Duyck729739b2012-02-08 07:51:06 +0000924 /* unmap any remaining paged data */
925 if (dma_unmap_len(tx_buffer, len)) {
926 dma_unmap_page(tx_ring->dev,
927 dma_unmap_addr(tx_buffer, dma),
928 dma_unmap_len(tx_buffer, len),
929 DMA_TO_DEVICE);
930 dma_unmap_len_set(tx_buffer, len, 0);
931 }
932 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800933
Alexander Duyck729739b2012-02-08 07:51:06 +0000934 /* move us one more past the eop_desc for start of next pkt */
935 tx_buffer++;
936 tx_desc++;
937 i++;
938 if (unlikely(!i)) {
939 i -= tx_ring->count;
940 tx_buffer = tx_ring->tx_buffer_info;
941 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
942 }
943
944 /* issue prefetch for next Tx descriptor */
945 prefetch(tx_desc);
946
947 /* update budget accounting */
948 budget--;
949 } while (likely(budget));
950
951 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700952 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000953 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800954 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000955 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000956 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000957 q_vector->tx.total_bytes += total_bytes;
958 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800959
John Fastabendc84d3242010-11-16 19:27:12 -0800960 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800961 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800962 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800963 e_err(drv, "Detected Tx Unit Hang\n"
964 " Tx Queue <%d>\n"
965 " TDH, TDT <%x>, <%x>\n"
966 " next_to_use <%x>\n"
967 " next_to_clean <%x>\n"
968 "tx_buffer_info[next_to_clean]\n"
969 " time_stamp <%lx>\n"
970 " jiffies <%lx>\n",
971 tx_ring->queue_index,
972 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
973 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000974 tx_ring->next_to_use, i,
975 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800976
977 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
978
979 e_info(probe,
980 "tx hang %d detected on queue %d, resetting adapter\n",
981 adapter->tx_timeout_count + 1, tx_ring->queue_index);
982
983 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000984 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800985
986 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000987 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800988 }
Auke Kok9a799d72007-09-15 14:07:45 -0700989
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000990 netdev_tx_completed_queue(txring_txq(tx_ring),
991 total_packets, total_bytes);
992
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800993#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000994 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000995 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800996 /* Make sure that anybody stopping the queue after this
997 * sees the new next_to_clean.
998 */
999 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001000 if (__netif_subqueue_stopped(tx_ring->netdev,
1001 tx_ring->queue_index)
1002 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1003 netif_wake_subqueue(tx_ring->netdev,
1004 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001005 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001006 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001007 }
Auke Kok9a799d72007-09-15 14:07:45 -07001008
Alexander Duyck59224552011-08-31 00:01:06 +00001009 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001010}
1011
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001012#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001013static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001014 struct ixgbe_ring *tx_ring,
1015 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001016{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001017 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001018 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1019 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001020
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001021 switch (hw->mac.type) {
1022 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001023 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001024 break;
1025 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001026 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001027 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1028 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1029 break;
1030 default:
1031 /* for unknown hardware do not write register */
1032 return;
1033 }
1034
1035 /*
1036 * We can enable relaxed ordering for reads, but not writes when
1037 * DCA is enabled. This is due to a known issue in some chipsets
1038 * which will cause the DCA tag to be cleared.
1039 */
1040 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1041 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1042 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1043
1044 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1045}
1046
1047static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1048 struct ixgbe_ring *rx_ring,
1049 int cpu)
1050{
1051 struct ixgbe_hw *hw = &adapter->hw;
1052 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1053 u8 reg_idx = rx_ring->reg_idx;
1054
1055
1056 switch (hw->mac.type) {
1057 case ixgbe_mac_82599EB:
1058 case ixgbe_mac_X540:
1059 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001060 break;
1061 default:
1062 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001063 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001064
1065 /*
1066 * We can enable relaxed ordering for reads, but not writes when
1067 * DCA is enabled. This is due to a known issue in some chipsets
1068 * which will cause the DCA tag to be cleared.
1069 */
1070 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001071 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1072
1073 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001074}
1075
1076static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1077{
1078 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001079 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001080 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001081
1082 if (q_vector->cpu == cpu)
1083 goto out_no_update;
1084
Alexander Duycka5579282012-02-08 07:50:04 +00001085 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001086 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001087
Alexander Duycka5579282012-02-08 07:50:04 +00001088 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001089 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001090
1091 q_vector->cpu = cpu;
1092out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001093 put_cpu();
1094}
1095
1096static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1097{
1098 int i;
1099
1100 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1101 return;
1102
Alexander Duycke35ec122009-05-21 13:07:12 +00001103 /* always use CB2 mode, difference is masked in the CB driver */
1104 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1105
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001106 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001107 adapter->q_vector[i]->cpu = -1;
1108 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001109 }
1110}
1111
1112static int __ixgbe_notify_dca(struct device *dev, void *data)
1113{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001114 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001115 unsigned long event = *(unsigned long *)data;
1116
Don Skidmore2a72c312011-07-20 02:27:05 +00001117 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001118 return 0;
1119
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001120 switch (event) {
1121 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001122 /* if we're already enabled, don't do it again */
1123 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1124 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001125 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001126 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001127 ixgbe_setup_dca(adapter);
1128 break;
1129 }
1130 /* Fall Through since DCA is disabled. */
1131 case DCA_PROVIDER_REMOVE:
1132 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1133 dca_remove_requester(dev);
1134 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1135 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1136 }
1137 break;
1138 }
1139
Denis V. Lunev652f0932008-03-27 14:39:17 +03001140 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001141}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001142
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001143#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001144static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1145 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001146 struct sk_buff *skb)
1147{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001148 if (ring->netdev->features & NETIF_F_RXHASH)
1149 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001150}
1151
Alexander Duyckf8003262012-03-03 02:35:52 +00001152#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001153/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001154 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001155 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001156 * @rx_desc: advanced rx descriptor
1157 *
1158 * Returns : true if it is FCoE pkt
1159 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001160static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001161 union ixgbe_adv_rx_desc *rx_desc)
1162{
1163 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1164
Alexander Duyck57efd442012-06-25 21:54:46 +00001165 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001166 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1167 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1168 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1169}
1170
Alexander Duyckf8003262012-03-03 02:35:52 +00001171#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001172/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001173 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001174 * @ring: structure containing ring specific data
1175 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001176 * @skb: skb currently being received and modified
1177 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001178static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001179 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001180 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001181{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001182 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001183
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001184 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001185 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001186 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001187
1188 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001189 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1190 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001191 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001192 return;
1193 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001194
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001195 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001196 return;
1197
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001198 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001199 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001200
1201 /*
1202 * 82599 errata, UDP frames with a 0 checksum can be marked as
1203 * checksum errors.
1204 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001205 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1206 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001207 return;
1208
Alexander Duyck8a0da212012-01-31 02:59:49 +00001209 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001210 return;
1211 }
1212
Auke Kok9a799d72007-09-15 14:07:45 -07001213 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001214 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001215}
1216
Alexander Duyck84ea2592010-11-16 19:26:49 -08001217static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001218{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001219 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001220
1221 /* update next to alloc since we have filled the ring */
1222 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001223 /*
1224 * Force memory writes to complete before letting h/w
1225 * know there are new descriptors to fetch. (Only
1226 * applicable for weak-ordered memory model archs,
1227 * such as IA-64).
1228 */
1229 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001230 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001231}
1232
Alexander Duyckf990b792012-01-31 02:59:34 +00001233static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1234 struct ixgbe_rx_buffer *bi)
1235{
1236 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001237 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001238
Alexander Duyckf8003262012-03-03 02:35:52 +00001239 /* since we are recycling buffers we should seldom need to alloc */
1240 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001241 return true;
1242
Alexander Duyckf8003262012-03-03 02:35:52 +00001243 /* alloc new page for storage */
1244 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001245 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1246 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001247 if (unlikely(!page)) {
1248 rx_ring->rx_stats.alloc_rx_page_failed++;
1249 return false;
1250 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001251 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001252 }
1253
Alexander Duyckf8003262012-03-03 02:35:52 +00001254 /* map page for use */
1255 dma = dma_map_page(rx_ring->dev, page, 0,
1256 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001257
Alexander Duyckf8003262012-03-03 02:35:52 +00001258 /*
1259 * if mapping failed free memory back to system since
1260 * there isn't much point in holding memory we can't use
1261 */
1262 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001263 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001264 bi->page = NULL;
1265
Alexander Duyckf990b792012-01-31 02:59:34 +00001266 rx_ring->rx_stats.alloc_rx_page_failed++;
1267 return false;
1268 }
1269
Alexander Duyckf8003262012-03-03 02:35:52 +00001270 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001271 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001272
Alexander Duyckf990b792012-01-31 02:59:34 +00001273 return true;
1274}
1275
Auke Kok9a799d72007-09-15 14:07:45 -07001276/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001277 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001278 * @rx_ring: ring to place buffers on
1279 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001280 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001281void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001282{
Auke Kok9a799d72007-09-15 14:07:45 -07001283 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001284 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001285 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001286
Alexander Duyckf8003262012-03-03 02:35:52 +00001287 /* nothing to do */
1288 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001289 return;
1290
Alexander Duycke4f74022012-01-31 02:59:44 +00001291 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001292 bi = &rx_ring->rx_buffer_info[i];
1293 i -= rx_ring->count;
1294
Alexander Duyckf8003262012-03-03 02:35:52 +00001295 do {
1296 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001297 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001298
Alexander Duyckf8003262012-03-03 02:35:52 +00001299 /*
1300 * Refresh the desc even if buffer_addrs didn't change
1301 * because each write-back erases this info.
1302 */
1303 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001304
Alexander Duyckf990b792012-01-31 02:59:34 +00001305 rx_desc++;
1306 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001307 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001308 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001309 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001310 bi = rx_ring->rx_buffer_info;
1311 i -= rx_ring->count;
1312 }
1313
1314 /* clear the hdr_addr for the next_to_use descriptor */
1315 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001316
1317 cleaned_count--;
1318 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001319
Alexander Duyckf990b792012-01-31 02:59:34 +00001320 i += rx_ring->count;
1321
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001322 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001323 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001324}
1325
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001326/**
1327 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1328 * @data: pointer to the start of the headers
1329 * @max_len: total length of section to find headers in
1330 *
1331 * This function is meant to determine the length of headers that will
1332 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1333 * motivation of doing this is to only perform one pull for IPv4 TCP
1334 * packets so that we can do basic things like calculating the gso_size
1335 * based on the average data per packet.
1336 **/
1337static unsigned int ixgbe_get_headlen(unsigned char *data,
1338 unsigned int max_len)
1339{
1340 union {
1341 unsigned char *network;
1342 /* l2 headers */
1343 struct ethhdr *eth;
1344 struct vlan_hdr *vlan;
1345 /* l3 headers */
1346 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001347 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001348 } hdr;
1349 __be16 protocol;
1350 u8 nexthdr = 0; /* default to not TCP */
1351 u8 hlen;
1352
1353 /* this should never happen, but better safe than sorry */
1354 if (max_len < ETH_HLEN)
1355 return max_len;
1356
1357 /* initialize network frame pointer */
1358 hdr.network = data;
1359
1360 /* set first protocol and move network header forward */
1361 protocol = hdr.eth->h_proto;
1362 hdr.network += ETH_HLEN;
1363
1364 /* handle any vlan tag if present */
1365 if (protocol == __constant_htons(ETH_P_8021Q)) {
1366 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1367 return max_len;
1368
1369 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1370 hdr.network += VLAN_HLEN;
1371 }
1372
1373 /* handle L3 protocols */
1374 if (protocol == __constant_htons(ETH_P_IP)) {
1375 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1376 return max_len;
1377
1378 /* access ihl as a u8 to avoid unaligned access on ia64 */
1379 hlen = (hdr.network[0] & 0x0F) << 2;
1380
1381 /* verify hlen meets minimum size requirements */
1382 if (hlen < sizeof(struct iphdr))
1383 return hdr.network - data;
1384
Alexander Duycked83da12012-11-13 01:13:33 +00001385 /* record next protocol if header is present */
Alexander Duyck20967f42013-02-01 08:56:41 +00001386 if (!(hdr.ipv4->frag_off & htons(IP_OFFSET)))
Alexander Duycked83da12012-11-13 01:13:33 +00001387 nexthdr = hdr.ipv4->protocol;
Alexander Duycka048b402012-05-24 08:26:29 +00001388 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1389 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1390 return max_len;
1391
1392 /* record next protocol */
1393 nexthdr = hdr.ipv6->nexthdr;
Alexander Duycked83da12012-11-13 01:13:33 +00001394 hlen = sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001395#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001396 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1397 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1398 return max_len;
Alexander Duycked83da12012-11-13 01:13:33 +00001399 hlen = FCOE_HEADER_LEN;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001400#endif
1401 } else {
1402 return hdr.network - data;
1403 }
1404
Alexander Duycked83da12012-11-13 01:13:33 +00001405 /* relocate pointer to start of L4 header */
1406 hdr.network += hlen;
1407
Alexander Duycka048b402012-05-24 08:26:29 +00001408 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001409 if (nexthdr == IPPROTO_TCP) {
1410 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1411 return max_len;
1412
1413 /* access doff as a u8 to avoid unaligned access on ia64 */
1414 hlen = (hdr.network[12] & 0xF0) >> 2;
1415
1416 /* verify hlen meets minimum size requirements */
1417 if (hlen < sizeof(struct tcphdr))
1418 return hdr.network - data;
1419
1420 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001421 } else if (nexthdr == IPPROTO_UDP) {
1422 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1423 return max_len;
1424
1425 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001426 }
1427
1428 /*
1429 * If everything has gone correctly hdr.network should be the
1430 * data section of the packet and will be the end of the header.
1431 * If not then it probably represents the end of the last recognized
1432 * header.
1433 */
1434 if ((hdr.network - data) < max_len)
1435 return hdr.network - data;
1436 else
1437 return max_len;
1438}
1439
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001440static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1441 struct sk_buff *skb)
1442{
Alexander Duyckf8003262012-03-03 02:35:52 +00001443 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001444
1445 /* set gso_size to avoid messing up TCP MSS */
1446 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1447 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001448 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001449}
1450
1451static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1452 struct sk_buff *skb)
1453{
1454 /* if append_cnt is 0 then frame is not RSC */
1455 if (!IXGBE_CB(skb)->append_cnt)
1456 return;
1457
1458 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1459 rx_ring->rx_stats.rsc_flush++;
1460
1461 ixgbe_set_rsc_gso_size(rx_ring, skb);
1462
1463 /* gso_size is computed using append_cnt so always clear it last */
1464 IXGBE_CB(skb)->append_cnt = 0;
1465}
1466
Alexander Duyck8a0da212012-01-31 02:59:49 +00001467/**
1468 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1469 * @rx_ring: rx descriptor ring packet is being transacted on
1470 * @rx_desc: pointer to the EOP Rx descriptor
1471 * @skb: pointer to current skb being populated
1472 *
1473 * This function checks the ring, descriptor, and packet information in
1474 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1475 * other fields within the skb.
1476 **/
1477static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1478 union ixgbe_adv_rx_desc *rx_desc,
1479 struct sk_buff *skb)
1480{
John Fastabend43e95f12012-05-15 06:12:17 +00001481 struct net_device *dev = rx_ring->netdev;
1482
Alexander Duyck8a0da212012-01-31 02:59:49 +00001483 ixgbe_update_rsc_stats(rx_ring, skb);
1484
1485 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1486
1487 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1488
Jacob Keller6cb562d2012-12-05 07:24:41 +00001489 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001490
Patrick McHardyf6469682013-04-19 02:04:27 +00001491 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001492 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001493 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001494 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001495 }
1496
1497 skb_record_rx_queue(skb, rx_ring->queue_index);
1498
John Fastabend43e95f12012-05-15 06:12:17 +00001499 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001500}
1501
1502static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1503 struct sk_buff *skb)
1504{
1505 struct ixgbe_adapter *adapter = q_vector->adapter;
1506
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001507 if (ixgbe_qv_ll_polling(q_vector))
1508 netif_receive_skb(skb);
1509 else if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
Alexander Duyck8a0da212012-01-31 02:59:49 +00001510 napi_gro_receive(&q_vector->napi, skb);
1511 else
1512 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001513}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001514
Alexander Duyckf8003262012-03-03 02:35:52 +00001515/**
1516 * ixgbe_is_non_eop - process handling of non-EOP buffers
1517 * @rx_ring: Rx ring being processed
1518 * @rx_desc: Rx descriptor for current buffer
1519 * @skb: Current socket buffer containing buffer in progress
1520 *
1521 * This function updates next to clean. If the buffer is an EOP buffer
1522 * this function exits returning false, otherwise it will place the
1523 * sk_buff in the next buffer to be chained and return true indicating
1524 * that this is in fact a non-EOP buffer.
1525 **/
1526static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1527 union ixgbe_adv_rx_desc *rx_desc,
1528 struct sk_buff *skb)
1529{
1530 u32 ntc = rx_ring->next_to_clean + 1;
1531
1532 /* fetch, update, and store next to clean */
1533 ntc = (ntc < rx_ring->count) ? ntc : 0;
1534 rx_ring->next_to_clean = ntc;
1535
1536 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1537
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001538 /* update RSC append count if present */
1539 if (ring_is_rsc_enabled(rx_ring)) {
1540 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1541 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1542
1543 if (unlikely(rsc_enabled)) {
1544 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1545
1546 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1547 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1548
1549 /* update ntc based on RSC value */
1550 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1551 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1552 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1553 }
1554 }
1555
1556 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001557 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1558 return false;
1559
Alexander Duyckf8003262012-03-03 02:35:52 +00001560 /* place skb in next buffer to be received */
1561 rx_ring->rx_buffer_info[ntc].skb = skb;
1562 rx_ring->rx_stats.non_eop_descs++;
1563
1564 return true;
1565}
1566
1567/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001568 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1569 * @rx_ring: rx descriptor ring packet is being transacted on
1570 * @skb: pointer to current skb being adjusted
1571 *
1572 * This function is an ixgbe specific version of __pskb_pull_tail. The
1573 * main difference between this version and the original function is that
1574 * this function can make several assumptions about the state of things
1575 * that allow for significant optimizations versus the standard function.
1576 * As a result we can do things like drop a frag and maintain an accurate
1577 * truesize for the skb.
1578 */
1579static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1580 struct sk_buff *skb)
1581{
1582 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1583 unsigned char *va;
1584 unsigned int pull_len;
1585
1586 /*
1587 * it is valid to use page_address instead of kmap since we are
1588 * working with pages allocated out of the lomem pool per
1589 * alloc_page(GFP_ATOMIC)
1590 */
1591 va = skb_frag_address(frag);
1592
1593 /*
1594 * we need the header to contain the greater of either ETH_HLEN or
1595 * 60 bytes if the skb->len is less than 60 for skb_pad.
1596 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001597 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001598
1599 /* align pull length to size of long to optimize memcpy performance */
1600 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1601
1602 /* update all of the pointers */
1603 skb_frag_size_sub(frag, pull_len);
1604 frag->page_offset += pull_len;
1605 skb->data_len -= pull_len;
1606 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001607}
1608
1609/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001610 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1611 * @rx_ring: rx descriptor ring packet is being transacted on
1612 * @skb: pointer to current skb being updated
1613 *
1614 * This function provides a basic DMA sync up for the first fragment of an
1615 * skb. The reason for doing this is that the first fragment cannot be
1616 * unmapped until we have reached the end of packet descriptor for a buffer
1617 * chain.
1618 */
1619static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1620 struct sk_buff *skb)
1621{
1622 /* if the page was released unmap it, else just sync our portion */
1623 if (unlikely(IXGBE_CB(skb)->page_released)) {
1624 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1625 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1626 IXGBE_CB(skb)->page_released = false;
1627 } else {
1628 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1629
1630 dma_sync_single_range_for_cpu(rx_ring->dev,
1631 IXGBE_CB(skb)->dma,
1632 frag->page_offset,
1633 ixgbe_rx_bufsz(rx_ring),
1634 DMA_FROM_DEVICE);
1635 }
1636 IXGBE_CB(skb)->dma = 0;
1637}
1638
1639/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001640 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1641 * @rx_ring: rx descriptor ring packet is being transacted on
1642 * @rx_desc: pointer to the EOP Rx descriptor
1643 * @skb: pointer to current skb being fixed
1644 *
1645 * Check for corrupted packet headers caused by senders on the local L2
1646 * embedded NIC switch not setting up their Tx Descriptors right. These
1647 * should be very rare.
1648 *
1649 * Also address the case where we are pulling data in on pages only
1650 * and as such no data is present in the skb header.
1651 *
1652 * In addition if skb is not at least 60 bytes we need to pad it so that
1653 * it is large enough to qualify as a valid Ethernet frame.
1654 *
1655 * Returns true if an error was encountered and skb was freed.
1656 **/
1657static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1658 union ixgbe_adv_rx_desc *rx_desc,
1659 struct sk_buff *skb)
1660{
Alexander Duyckf8003262012-03-03 02:35:52 +00001661 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001662
1663 /* verify that the packet does not have any known errors */
1664 if (unlikely(ixgbe_test_staterr(rx_desc,
1665 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1666 !(netdev->features & NETIF_F_RXALL))) {
1667 dev_kfree_skb_any(skb);
1668 return true;
1669 }
1670
Alexander Duyck19861ce2012-07-20 08:08:33 +00001671 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001672 if (skb_is_nonlinear(skb))
1673 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001674
Alexander Duyck57efd442012-06-25 21:54:46 +00001675#ifdef IXGBE_FCOE
1676 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1677 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1678 return false;
1679
1680#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001681 /* if skb_pad returns an error the skb was freed */
1682 if (unlikely(skb->len < 60)) {
1683 int pad_len = 60 - skb->len;
1684
1685 if (skb_pad(skb, pad_len))
1686 return true;
1687 __skb_put(skb, pad_len);
1688 }
1689
1690 return false;
1691}
1692
1693/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001694 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1695 * @rx_ring: rx descriptor ring to store buffers on
1696 * @old_buff: donor buffer to have page reused
1697 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001698 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001699 **/
1700static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1701 struct ixgbe_rx_buffer *old_buff)
1702{
1703 struct ixgbe_rx_buffer *new_buff;
1704 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001705
1706 new_buff = &rx_ring->rx_buffer_info[nta];
1707
1708 /* update, and store next to alloc */
1709 nta++;
1710 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1711
1712 /* transfer page from old buffer to new buffer */
1713 new_buff->page = old_buff->page;
1714 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001715 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001716
1717 /* sync the buffer for use by the device */
1718 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001719 new_buff->page_offset,
1720 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001721 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001722}
1723
1724/**
1725 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1726 * @rx_ring: rx descriptor ring to transact packets on
1727 * @rx_buffer: buffer containing page to add
1728 * @rx_desc: descriptor containing length of buffer written by hardware
1729 * @skb: sk_buff to place the data into
1730 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001731 * This function will add the data contained in rx_buffer->page to the skb.
1732 * This is done either through a direct copy if the data in the buffer is
1733 * less than the skb header size, otherwise it will just attach the page as
1734 * a frag to the skb.
1735 *
1736 * The function will then update the page offset if necessary and return
1737 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001738 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001739static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001740 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001741 union ixgbe_adv_rx_desc *rx_desc,
1742 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001743{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001744 struct page *page = rx_buffer->page;
1745 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001746#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001747 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001748#else
1749 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1750 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1751 ixgbe_rx_bufsz(rx_ring);
1752#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001753
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001754 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1755 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1756
1757 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1758
1759 /* we can reuse buffer as-is, just make sure it is local */
1760 if (likely(page_to_nid(page) == numa_node_id()))
1761 return true;
1762
1763 /* this page cannot be reused so discard it */
1764 put_page(page);
1765 return false;
1766 }
1767
Alexander Duyck0549ae22012-07-20 08:08:18 +00001768 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1769 rx_buffer->page_offset, size, truesize);
1770
Alexander Duyck09816fb2012-07-20 08:08:23 +00001771 /* avoid re-using remote pages */
1772 if (unlikely(page_to_nid(page) != numa_node_id()))
1773 return false;
1774
1775#if (PAGE_SIZE < 8192)
1776 /* if we are only owner of page we can reuse it */
1777 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001778 return false;
1779
1780 /* flip page offset to other buffer */
1781 rx_buffer->page_offset ^= truesize;
1782
Alexander Duyck09816fb2012-07-20 08:08:23 +00001783 /*
1784 * since we are the only owner of the page and we need to
1785 * increment it, just set the value to 2 in order to avoid
1786 * an unecessary locked operation
1787 */
1788 atomic_set(&page->_count, 2);
1789#else
1790 /* move offset up to the next cache line */
1791 rx_buffer->page_offset += truesize;
1792
1793 if (rx_buffer->page_offset > last_offset)
1794 return false;
1795
Alexander Duyck0549ae22012-07-20 08:08:18 +00001796 /* bump ref count on page before it is given to the stack */
1797 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001798#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001799
1800 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001801}
1802
Alexander Duyck18806c92012-07-20 08:08:44 +00001803static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1804 union ixgbe_adv_rx_desc *rx_desc)
1805{
1806 struct ixgbe_rx_buffer *rx_buffer;
1807 struct sk_buff *skb;
1808 struct page *page;
1809
1810 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1811 page = rx_buffer->page;
1812 prefetchw(page);
1813
1814 skb = rx_buffer->skb;
1815
1816 if (likely(!skb)) {
1817 void *page_addr = page_address(page) +
1818 rx_buffer->page_offset;
1819
1820 /* prefetch first cache line of first page */
1821 prefetch(page_addr);
1822#if L1_CACHE_BYTES < 128
1823 prefetch(page_addr + L1_CACHE_BYTES);
1824#endif
1825
1826 /* allocate a skb to store the frags */
1827 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1828 IXGBE_RX_HDR_SIZE);
1829 if (unlikely(!skb)) {
1830 rx_ring->rx_stats.alloc_rx_buff_failed++;
1831 return NULL;
1832 }
1833
1834 /*
1835 * we will be copying header into skb->data in
1836 * pskb_may_pull so it is in our interest to prefetch
1837 * it now to avoid a possible cache miss
1838 */
1839 prefetchw(skb->data);
1840
1841 /*
1842 * Delay unmapping of the first packet. It carries the
1843 * header information, HW may still access the header
1844 * after the writeback. Only unmap it when EOP is
1845 * reached
1846 */
1847 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1848 goto dma_sync;
1849
1850 IXGBE_CB(skb)->dma = rx_buffer->dma;
1851 } else {
1852 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1853 ixgbe_dma_sync_frag(rx_ring, skb);
1854
1855dma_sync:
1856 /* we are reusing so sync this buffer for CPU use */
1857 dma_sync_single_range_for_cpu(rx_ring->dev,
1858 rx_buffer->dma,
1859 rx_buffer->page_offset,
1860 ixgbe_rx_bufsz(rx_ring),
1861 DMA_FROM_DEVICE);
1862 }
1863
1864 /* pull page into skb */
1865 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1866 /* hand second half of page back to the ring */
1867 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1868 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1869 /* the page has been released from the ring */
1870 IXGBE_CB(skb)->page_released = true;
1871 } else {
1872 /* we are not reusing the buffer so unmap it */
1873 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1874 ixgbe_rx_pg_size(rx_ring),
1875 DMA_FROM_DEVICE);
1876 }
1877
1878 /* clear contents of buffer_info */
1879 rx_buffer->skb = NULL;
1880 rx_buffer->dma = 0;
1881 rx_buffer->page = NULL;
1882
1883 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001884}
1885
1886/**
1887 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1888 * @q_vector: structure containing interrupt and ring information
1889 * @rx_ring: rx descriptor ring to transact packets on
1890 * @budget: Total limit on number of packets to process
1891 *
1892 * This function provides a "bounce buffer" approach to Rx interrupt
1893 * processing. The advantage to this is that on systems that have
1894 * expensive overhead for IOMMU access this provides a means of avoiding
1895 * it by maintaining the mapping of the page to the syste.
1896 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001897 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00001898 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001899static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001900 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001901 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001902{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001903 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001904#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001905 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001906 int ddp_bytes;
1907 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001908#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001909 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001910
Alexander Duyckf8003262012-03-03 02:35:52 +00001911 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001912 union ixgbe_adv_rx_desc *rx_desc;
1913 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001914
Alexander Duyckf8003262012-03-03 02:35:52 +00001915 /* return some buffers to hardware, one at a time is too slow */
1916 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1917 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1918 cleaned_count = 0;
1919 }
Auke Kok9a799d72007-09-15 14:07:45 -07001920
Alexander Duyck18806c92012-07-20 08:08:44 +00001921 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001922
Alexander Duyckf8003262012-03-03 02:35:52 +00001923 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1924 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001925
Alexander Duyckf8003262012-03-03 02:35:52 +00001926 /*
1927 * This memory barrier is needed to keep us from reading
1928 * any other fields out of the rx_desc until we know the
1929 * RXD_STAT_DD bit is set
1930 */
1931 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001932
Alexander Duyck18806c92012-07-20 08:08:44 +00001933 /* retrieve a buffer from the ring */
1934 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001935
Alexander Duyck18806c92012-07-20 08:08:44 +00001936 /* exit if we failed to retrieve a buffer */
1937 if (!skb)
1938 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001939
Auke Kok9a799d72007-09-15 14:07:45 -07001940 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001941
Alexander Duyckf8003262012-03-03 02:35:52 +00001942 /* place incomplete frames back on ring for completion */
1943 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1944 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001945
Alexander Duyckf8003262012-03-03 02:35:52 +00001946 /* verify the packet layout is correct */
1947 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1948 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001949
1950 /* probably a little skewed due to removing CRC */
1951 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001952
Alexander Duyck8a0da212012-01-31 02:59:49 +00001953 /* populate checksum, timestamp, VLAN, and protocol */
1954 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1955
Yi Zou332d4a72009-05-13 13:11:53 +00001956#ifdef IXGBE_FCOE
1957 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001958 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001959 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001960 /* include DDPed FCoE data */
1961 if (ddp_bytes > 0) {
1962 if (!mss) {
1963 mss = rx_ring->netdev->mtu -
1964 sizeof(struct fcoe_hdr) -
1965 sizeof(struct fc_frame_header) -
1966 sizeof(struct fcoe_crc_eof);
1967 if (mss > 512)
1968 mss &= ~511;
1969 }
1970 total_rx_bytes += ddp_bytes;
1971 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1972 mss);
1973 }
David S. Miller823dcd22011-08-20 10:39:12 -07001974 if (!ddp_bytes) {
1975 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001976 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001977 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001978 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001979
Yi Zou332d4a72009-05-13 13:11:53 +00001980#endif /* IXGBE_FCOE */
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001981 skb_mark_ll(skb, &q_vector->napi);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001982 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001983
Alexander Duyckf8003262012-03-03 02:35:52 +00001984 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001985 total_rx_packets++;
1986 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001987
Alexander Duyckc267fc12010-11-16 19:27:00 -08001988 u64_stats_update_begin(&rx_ring->syncp);
1989 rx_ring->stats.packets += total_rx_packets;
1990 rx_ring->stats.bytes += total_rx_bytes;
1991 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001992 q_vector->rx.total_packets += total_rx_packets;
1993 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001994
Alexander Duyckf8003262012-03-03 02:35:52 +00001995 if (cleaned_count)
1996 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1997
Eliezer Tamir5a85e732013-06-10 11:40:20 +03001998 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07001999}
2000
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002001#ifdef CONFIG_NET_LL_RX_POLL
2002/* must be called with local_bh_disable()d */
2003static int ixgbe_low_latency_recv(struct napi_struct *napi)
2004{
2005 struct ixgbe_q_vector *q_vector =
2006 container_of(napi, struct ixgbe_q_vector, napi);
2007 struct ixgbe_adapter *adapter = q_vector->adapter;
2008 struct ixgbe_ring *ring;
2009 int found = 0;
2010
2011 if (test_bit(__IXGBE_DOWN, &adapter->state))
2012 return LL_FLUSH_FAILED;
2013
2014 if (!ixgbe_qv_lock_poll(q_vector))
2015 return LL_FLUSH_BUSY;
2016
2017 ixgbe_for_each_ring(ring, q_vector->rx) {
2018 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
2019 if (found)
2020 break;
2021 }
2022
2023 ixgbe_qv_unlock_poll(q_vector);
2024
2025 return found;
2026}
2027#endif /* CONFIG_NET_LL_RX_POLL */
2028
Auke Kok9a799d72007-09-15 14:07:45 -07002029/**
2030 * ixgbe_configure_msix - Configure MSI-X hardware
2031 * @adapter: board private structure
2032 *
2033 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2034 * interrupts.
2035 **/
2036static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2037{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002038 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002039 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002040 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002041
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002042 /* Populate MSIX to EITR Select */
2043 if (adapter->num_vfs > 32) {
2044 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2045 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2046 }
2047
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002048 /*
2049 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002050 * corresponding register.
2051 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002052 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002053 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002054 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002055
Alexander Duycka5579282012-02-08 07:50:04 +00002056 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002057 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002058
Alexander Duycka5579282012-02-08 07:50:04 +00002059 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002060 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002061
Alexander Duyckfe49f042009-06-04 16:00:09 +00002062 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002063 }
2064
Alexander Duyckbd508172010-11-16 19:27:03 -08002065 switch (adapter->hw.mac.type) {
2066 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002067 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002068 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002069 break;
2070 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002071 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002072 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002073 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002074 default:
2075 break;
2076 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002077 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002078
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002079 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002080 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002081 mask &= ~(IXGBE_EIMS_OTHER |
2082 IXGBE_EIMS_MAILBOX |
2083 IXGBE_EIMS_LSC);
2084
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002085 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002086}
2087
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002088enum latency_range {
2089 lowest_latency = 0,
2090 low_latency = 1,
2091 bulk_latency = 2,
2092 latency_invalid = 255
2093};
2094
2095/**
2096 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002097 * @q_vector: structure containing interrupt and ring information
2098 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002099 *
2100 * Stores a new ITR value based on packets and byte
2101 * counts during the last interrupt. The advantage of per interrupt
2102 * computation is faster updates and more accurate ITR for the current
2103 * traffic pattern. Constants in this function were computed
2104 * based on theoretical maximum wire speed and thresholds were set based
2105 * on testing data as well as attempting to minimize response time
2106 * while increasing bulk throughput.
2107 * this functionality is controlled by the InterruptThrottleRate module
2108 * parameter (see ixgbe_param.c)
2109 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002110static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2111 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002112{
Alexander Duyckbd198052011-06-11 01:45:08 +00002113 int bytes = ring_container->total_bytes;
2114 int packets = ring_container->total_packets;
2115 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002116 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002117 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002118
2119 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002120 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002121
2122 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002123 * 0-10MB/s lowest (100000 ints/s)
2124 * 10-20MB/s low (20000 ints/s)
2125 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002126 */
2127 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002128 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002129 if (timepassed_us == 0)
2130 return;
2131
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002132 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2133
2134 switch (itr_setting) {
2135 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002136 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002137 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002138 break;
2139 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002140 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002141 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002142 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002143 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002144 break;
2145 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002146 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002147 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002148 break;
2149 }
2150
Alexander Duyckbd198052011-06-11 01:45:08 +00002151 /* clear work counters since we have the values we need */
2152 ring_container->total_bytes = 0;
2153 ring_container->total_packets = 0;
2154
2155 /* write updated itr to ring container */
2156 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002157}
2158
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002159/**
2160 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002161 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002162 *
2163 * This function is made to be called by ethtool and by the driver
2164 * when it needs to update EITR registers at runtime. Hardware
2165 * specific quirks/differences are taken care of here.
2166 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002167void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002168{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002169 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002170 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002171 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002172 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002173
Alexander Duyckbd508172010-11-16 19:27:03 -08002174 switch (adapter->hw.mac.type) {
2175 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002176 /* must write high and low 16 bits to reset counter */
2177 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002178 break;
2179 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002180 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002181 /*
2182 * set the WDIS bit to not clear the timer bits and cause an
2183 * immediate assertion of the interrupt
2184 */
2185 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002186 break;
2187 default:
2188 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002189 }
2190 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2191}
2192
Alexander Duyckbd198052011-06-11 01:45:08 +00002193static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002194{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002195 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002196 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002197
Alexander Duyckbd198052011-06-11 01:45:08 +00002198 ixgbe_update_itr(q_vector, &q_vector->tx);
2199 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002200
Alexander Duyck08c88332011-06-11 01:45:03 +00002201 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002202
2203 switch (current_itr) {
2204 /* counts and packets in update_itr are dependent on these numbers */
2205 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002206 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002207 break;
2208 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002209 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002210 break;
2211 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002212 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002213 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002214 default:
2215 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002216 }
2217
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002218 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002219 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002220 new_itr = (10 * new_itr * q_vector->itr) /
2221 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002222
Alexander Duyckbd198052011-06-11 01:45:08 +00002223 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002224 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002225
2226 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002227 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002228}
2229
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002230/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002231 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002232 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002233 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002234static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002235{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002236 struct ixgbe_hw *hw = &adapter->hw;
2237 u32 eicr = adapter->interrupt_event;
2238
Alexander Duyckf0f97782011-04-22 04:08:09 +00002239 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002240 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002241
Alexander Duyckf0f97782011-04-22 04:08:09 +00002242 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2243 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2244 return;
2245
2246 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2247
Joe Perches7ca647b2010-09-07 21:35:40 +00002248 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002249 case IXGBE_DEV_ID_82599_T3_LOM:
2250 /*
2251 * Since the warning interrupt is for both ports
2252 * we don't have to check if:
2253 * - This interrupt wasn't for our port.
2254 * - We may have missed the interrupt so always have to
2255 * check if we got a LSC
2256 */
2257 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2258 !(eicr & IXGBE_EICR_LSC))
2259 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002260
Alexander Duyckf0f97782011-04-22 04:08:09 +00002261 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002262 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002263 bool link_up = false;
2264
Josh Hay3d292262012-12-15 03:28:19 +00002265 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002266
Alexander Duyckf0f97782011-04-22 04:08:09 +00002267 if (link_up)
2268 return;
2269 }
2270
2271 /* Check if this is not due to overtemp */
2272 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2273 return;
2274
2275 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002276 default:
2277 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2278 return;
2279 break;
2280 }
2281 e_crit(drv,
2282 "Network adapter has been stopped because it has over heated. "
2283 "Restart the computer. If the problem persists, "
2284 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002285
2286 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002287}
2288
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002289static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2290{
2291 struct ixgbe_hw *hw = &adapter->hw;
2292
2293 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2294 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002295 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002296 /* write to clear the interrupt */
2297 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2298 }
2299}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002300
Jacob Keller4f51bf72011-08-20 04:49:45 +00002301static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2302{
2303 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2304 return;
2305
2306 switch (adapter->hw.mac.type) {
2307 case ixgbe_mac_82599EB:
2308 /*
2309 * Need to check link state so complete overtemp check
2310 * on service task
2311 */
2312 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2313 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2314 adapter->interrupt_event = eicr;
2315 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2316 ixgbe_service_event_schedule(adapter);
2317 return;
2318 }
2319 return;
2320 case ixgbe_mac_X540:
2321 if (!(eicr & IXGBE_EICR_TS))
2322 return;
2323 break;
2324 default:
2325 return;
2326 }
2327
2328 e_crit(drv,
2329 "Network adapter has been stopped because it has over heated. "
2330 "Restart the computer. If the problem persists, "
2331 "power off the system and replace the adapter\n");
2332}
2333
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002334static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2335{
2336 struct ixgbe_hw *hw = &adapter->hw;
2337
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002338 if (eicr & IXGBE_EICR_GPI_SDP2) {
2339 /* Clear the interrupt */
2340 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002341 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2342 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2343 ixgbe_service_event_schedule(adapter);
2344 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002345 }
2346
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002347 if (eicr & IXGBE_EICR_GPI_SDP1) {
2348 /* Clear the interrupt */
2349 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002350 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2351 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2352 ixgbe_service_event_schedule(adapter);
2353 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002354 }
2355}
2356
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002357static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2358{
2359 struct ixgbe_hw *hw = &adapter->hw;
2360
2361 adapter->lsc_int++;
2362 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2363 adapter->link_check_timeout = jiffies;
2364 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2365 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002366 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002367 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002368 }
2369}
2370
Alexander Duyckfe49f042009-06-04 16:00:09 +00002371static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2372 u64 qmask)
2373{
2374 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002375 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002376
Alexander Duyckbd508172010-11-16 19:27:03 -08002377 switch (hw->mac.type) {
2378 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002379 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002380 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2381 break;
2382 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002383 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002384 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002385 if (mask)
2386 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002387 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002388 if (mask)
2389 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2390 break;
2391 default:
2392 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002393 }
2394 /* skip the flush */
2395}
2396
2397static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002398 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002399{
2400 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002401 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002402
Alexander Duyckbd508172010-11-16 19:27:03 -08002403 switch (hw->mac.type) {
2404 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002405 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002406 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2407 break;
2408 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002409 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002410 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002411 if (mask)
2412 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002413 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002414 if (mask)
2415 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2416 break;
2417 default:
2418 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002419 }
2420 /* skip the flush */
2421}
2422
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002423/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002424 * ixgbe_irq_enable - Enable default interrupt generation settings
2425 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002426 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002427static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2428 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002429{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002430 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002431
Alexander Duyck2c4af692011-07-15 07:29:55 +00002432 /* don't reenable LSC while waiting for link */
2433 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2434 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435
Alexander Duyck2c4af692011-07-15 07:29:55 +00002436 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002437 switch (adapter->hw.mac.type) {
2438 case ixgbe_mac_82599EB:
2439 mask |= IXGBE_EIMS_GPI_SDP0;
2440 break;
2441 case ixgbe_mac_X540:
2442 mask |= IXGBE_EIMS_TS;
2443 break;
2444 default:
2445 break;
2446 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002447 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2448 mask |= IXGBE_EIMS_GPI_SDP1;
2449 switch (adapter->hw.mac.type) {
2450 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002451 mask |= IXGBE_EIMS_GPI_SDP1;
2452 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002453 case ixgbe_mac_X540:
2454 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002455 mask |= IXGBE_EIMS_MAILBOX;
2456 break;
2457 default:
2458 break;
2459 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002460
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002461 if (adapter->hw.mac.type == ixgbe_mac_X540)
2462 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002463
Alexander Duyck2c4af692011-07-15 07:29:55 +00002464 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2465 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2466 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002467
Alexander Duyck2c4af692011-07-15 07:29:55 +00002468 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2469 if (queues)
2470 ixgbe_irq_enable_queues(adapter, ~0);
2471 if (flush)
2472 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002473}
2474
Alexander Duyck2c4af692011-07-15 07:29:55 +00002475static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002476{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002477 struct ixgbe_adapter *adapter = data;
2478 struct ixgbe_hw *hw = &adapter->hw;
2479 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002480
Alexander Duyck2c4af692011-07-15 07:29:55 +00002481 /*
2482 * Workaround for Silicon errata. Use clear-by-write instead
2483 * of clear-by-read. Reading with EICS will return the
2484 * interrupt causes without clearing, which later be done
2485 * with the write to EICR.
2486 */
2487 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002488
2489 /* The lower 16bits of the EICR register are for the queue interrupts
2490 * which should be masked here in order to not accidently clear them if
2491 * the bits are high when ixgbe_msix_other is called. There is a race
2492 * condition otherwise which results in possible performance loss
2493 * especially if the ixgbe_msix_other interrupt is triggering
2494 * consistently (as it would when PPS is turned on for the X540 device)
2495 */
2496 eicr &= 0xFFFF0000;
2497
Alexander Duyck2c4af692011-07-15 07:29:55 +00002498 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002499
Alexander Duyck2c4af692011-07-15 07:29:55 +00002500 if (eicr & IXGBE_EICR_LSC)
2501 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002502
Alexander Duyck2c4af692011-07-15 07:29:55 +00002503 if (eicr & IXGBE_EICR_MAILBOX)
2504 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002505
Alexander Duyck2c4af692011-07-15 07:29:55 +00002506 switch (hw->mac.type) {
2507 case ixgbe_mac_82599EB:
2508 case ixgbe_mac_X540:
2509 if (eicr & IXGBE_EICR_ECC)
2510 e_info(link, "Received unrecoverable ECC Err, please "
2511 "reboot\n");
2512 /* Handle Flow Director Full threshold interrupt */
2513 if (eicr & IXGBE_EICR_FLOW_DIR) {
2514 int reinit_count = 0;
2515 int i;
2516 for (i = 0; i < adapter->num_tx_queues; i++) {
2517 struct ixgbe_ring *ring = adapter->tx_ring[i];
2518 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2519 &ring->state))
2520 reinit_count++;
2521 }
2522 if (reinit_count) {
2523 /* no more flow director interrupts until after init */
2524 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2525 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2526 ixgbe_service_event_schedule(adapter);
2527 }
2528 }
2529 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002530 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002531 break;
2532 default:
2533 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002534 }
2535
Alexander Duyck2c4af692011-07-15 07:29:55 +00002536 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002537
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002538 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2539 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002540
Alexander Duyck2c4af692011-07-15 07:29:55 +00002541 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002542 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002543 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002544
Alexander Duyck2c4af692011-07-15 07:29:55 +00002545 return IRQ_HANDLED;
2546}
2547
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002548static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002549{
2550 struct ixgbe_q_vector *q_vector = data;
2551
Auke Kok9a799d72007-09-15 14:07:45 -07002552 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002553
2554 if (q_vector->rx.ring || q_vector->tx.ring)
2555 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002556
2557 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002558}
2559
Auke Kok9a799d72007-09-15 14:07:45 -07002560/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002561 * ixgbe_poll - NAPI Rx polling callback
2562 * @napi: structure for representing this polling device
2563 * @budget: how many packets driver is allowed to clean
2564 *
2565 * This function is used for legacy and MSI, NAPI mode
2566 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002567int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002568{
2569 struct ixgbe_q_vector *q_vector =
2570 container_of(napi, struct ixgbe_q_vector, napi);
2571 struct ixgbe_adapter *adapter = q_vector->adapter;
2572 struct ixgbe_ring *ring;
2573 int per_ring_budget;
2574 bool clean_complete = true;
2575
2576#ifdef CONFIG_IXGBE_DCA
2577 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2578 ixgbe_update_dca(q_vector);
2579#endif
2580
2581 ixgbe_for_each_ring(ring, q_vector->tx)
2582 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2583
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002584 if (!ixgbe_qv_lock_napi(q_vector))
2585 return budget;
2586
Alexander Duyckeb01b972012-02-08 07:51:27 +00002587 /* attempt to distribute budget to each queue fairly, but don't allow
2588 * the budget to go below 1 because we'll exit polling */
2589 if (q_vector->rx.count > 1)
2590 per_ring_budget = max(budget/q_vector->rx.count, 1);
2591 else
2592 per_ring_budget = budget;
2593
2594 ixgbe_for_each_ring(ring, q_vector->rx)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002595 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2596 per_ring_budget) < per_ring_budget);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002597
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002598 ixgbe_qv_unlock_napi(q_vector);
Alexander Duyckeb01b972012-02-08 07:51:27 +00002599 /* If all work not completed, return budget and keep polling */
2600 if (!clean_complete)
2601 return budget;
2602
2603 /* all work done, exit the polling mode */
2604 napi_complete(napi);
2605 if (adapter->rx_itr_setting & 1)
2606 ixgbe_set_itr(q_vector);
2607 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2608 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2609
2610 return 0;
2611}
2612
2613/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002614 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2615 * @adapter: board private structure
2616 *
2617 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2618 * interrupts from the kernel.
2619 **/
2620static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2621{
2622 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002623 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002624 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002625
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002626 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002627 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002628 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002629
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002630 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002631 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002632 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002633 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002634 } else if (q_vector->rx.ring) {
2635 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2636 "%s-%s-%d", netdev->name, "rx", ri++);
2637 } else if (q_vector->tx.ring) {
2638 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2639 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002640 } else {
2641 /* skip this unused q_vector */
2642 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002643 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002644 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2645 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002646 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002647 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002648 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002649 goto free_queue_irqs;
2650 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002651 /* If Flow Director is enabled, set interrupt affinity */
2652 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2653 /* assign the mask for this irq */
2654 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002655 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002656 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002657 }
2658
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002659 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002660 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002661 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002662 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002663 goto free_queue_irqs;
2664 }
2665
2666 return 0;
2667
2668free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002669 while (vector) {
2670 vector--;
2671 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2672 NULL);
2673 free_irq(adapter->msix_entries[vector].vector,
2674 adapter->q_vector[vector]);
2675 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002676 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2677 pci_disable_msix(adapter->pdev);
2678 kfree(adapter->msix_entries);
2679 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002680 return err;
2681}
2682
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002683/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002684 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002685 * @irq: interrupt number
2686 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002687 **/
2688static irqreturn_t ixgbe_intr(int irq, void *data)
2689{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002690 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002691 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002692 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002693 u32 eicr;
2694
Don Skidmore54037502009-02-21 15:42:56 -08002695 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002696 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002697 * before the read of EICR.
2698 */
2699 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2700
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002701 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002702 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002703 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002704 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002705 /*
2706 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002707 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002708 * have disabled interrupts due to EIAM
2709 * finish the workaround of silicon errata on 82598. Unmask
2710 * the interrupt that we masked before the EICR read.
2711 */
2712 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2713 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002714 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002715 }
Auke Kok9a799d72007-09-15 14:07:45 -07002716
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002717 if (eicr & IXGBE_EICR_LSC)
2718 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002719
Alexander Duyckbd508172010-11-16 19:27:03 -08002720 switch (hw->mac.type) {
2721 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002722 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002723 /* Fall through */
2724 case ixgbe_mac_X540:
2725 if (eicr & IXGBE_EICR_ECC)
2726 e_info(link, "Received unrecoverable ECC err, please "
2727 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002728 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002729 break;
2730 default:
2731 break;
2732 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002733
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002734 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002735 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2736 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002737
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002738 /* would disable interrupts here but EIAM disabled it */
2739 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002740
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002741 /*
2742 * re-enable link(maybe) and non-queue interrupts, no flush.
2743 * ixgbe_poll will re-enable the queue interrupts
2744 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002745 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2746 ixgbe_irq_enable(adapter, false, false);
2747
Auke Kok9a799d72007-09-15 14:07:45 -07002748 return IRQ_HANDLED;
2749}
2750
2751/**
2752 * ixgbe_request_irq - initialize interrupts
2753 * @adapter: board private structure
2754 *
2755 * Attempts to configure interrupts using the best available
2756 * capabilities of the hardware and kernel.
2757 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002758static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002759{
2760 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002761 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002762
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002763 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002764 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002765 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002766 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002767 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002768 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002769 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002770 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002771
Alexander Duyckde88eee2012-02-08 07:49:59 +00002772 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002773 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002774
Auke Kok9a799d72007-09-15 14:07:45 -07002775 return err;
2776}
2777
2778static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2779{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002780 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002781
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002782 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002783 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002784 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002785 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002786
2787 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2788 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2789 struct msix_entry *entry = &adapter->msix_entries[vector];
2790
2791 /* free only the irqs that were actually requested */
2792 if (!q_vector->rx.ring && !q_vector->tx.ring)
2793 continue;
2794
2795 /* clear the affinity_mask in the IRQ descriptor */
2796 irq_set_affinity_hint(entry->vector, NULL);
2797
2798 free_irq(entry->vector, q_vector);
2799 }
2800
2801 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002802}
2803
2804/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002805 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2806 * @adapter: board private structure
2807 **/
2808static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2809{
Alexander Duyckbd508172010-11-16 19:27:03 -08002810 switch (adapter->hw.mac.type) {
2811 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002812 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002813 break;
2814 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002815 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002816 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2817 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002818 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002819 break;
2820 default:
2821 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002822 }
2823 IXGBE_WRITE_FLUSH(&adapter->hw);
2824 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002825 int vector;
2826
2827 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2828 synchronize_irq(adapter->msix_entries[vector].vector);
2829
2830 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002831 } else {
2832 synchronize_irq(adapter->pdev->irq);
2833 }
2834}
2835
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002836/**
Auke Kok9a799d72007-09-15 14:07:45 -07002837 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2838 *
2839 **/
2840static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2841{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002842 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002843
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002844 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002845
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002846 ixgbe_set_ivar(adapter, 0, 0, 0);
2847 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002848
Emil Tantilov396e7992010-07-01 20:05:12 +00002849 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002850}
2851
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002852/**
2853 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2854 * @adapter: board private structure
2855 * @ring: structure containing ring specific data
2856 *
2857 * Configure the Tx descriptor ring after a reset.
2858 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002859void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2860 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002861{
2862 struct ixgbe_hw *hw = &adapter->hw;
2863 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002864 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002865 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002866 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002867
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002868 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002869 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002870 IXGBE_WRITE_FLUSH(hw);
2871
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002872 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002873 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002874 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2875 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2876 ring->count * sizeof(union ixgbe_adv_tx_desc));
2877 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2878 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002879 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002880
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002881 /*
2882 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00002883 * higher than 1 when:
2884 * - ITR is 0 as it could cause false TX hangs
2885 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002886 *
2887 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2888 * to or less than the number of on chip descriptors, which is
2889 * currently 40.
2890 */
Emil Tantilov67da0972013-01-25 06:19:20 +00002891#if IS_ENABLED(CONFIG_BQL)
2892 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
2893#else
Alexander Duycke954b372012-02-08 07:49:38 +00002894 if (!ring->q_vector || (ring->q_vector->itr < 8))
Emil Tantilov67da0972013-01-25 06:19:20 +00002895#endif
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002896 txdctl |= (1 << 16); /* WTHRESH = 1 */
2897 else
2898 txdctl |= (8 << 16); /* WTHRESH = 8 */
2899
Alexander Duycke954b372012-02-08 07:49:38 +00002900 /*
2901 * Setting PTHRESH to 32 both improves performance
2902 * and avoids a TX hang with DFP enabled
2903 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002904 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2905 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002906
2907 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002908 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002909 ring->atr_sample_rate = adapter->atr_sample_rate;
2910 ring->atr_count = 0;
2911 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2912 } else {
2913 ring->atr_sample_rate = 0;
2914 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002915
Alexander Duyckfd786b72013-01-12 06:33:31 +00002916 /* initialize XPS */
2917 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
2918 struct ixgbe_q_vector *q_vector = ring->q_vector;
2919
2920 if (q_vector)
2921 netif_set_xps_queue(adapter->netdev,
2922 &q_vector->affinity_mask,
2923 ring->queue_index);
2924 }
2925
John Fastabendc84d3242010-11-16 19:27:12 -08002926 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2927
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002928 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002929 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2930
2931 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2932 if (hw->mac.type == ixgbe_mac_82598EB &&
2933 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2934 return;
2935
2936 /* poll to verify queue is enabled */
2937 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002938 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002939 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2940 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2941 if (!wait_loop)
2942 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002943}
2944
Alexander Duyck120ff942010-08-19 13:34:50 +00002945static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2946{
2947 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002948 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002949 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002950
2951 if (hw->mac.type == ixgbe_mac_82598EB)
2952 return;
2953
2954 /* disable the arbiter while setting MTQC */
2955 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2956 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2957 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2958
2959 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002960 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2961 mtqc = IXGBE_MTQC_VT_ENA;
2962 if (tcs > 4)
2963 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2964 else if (tcs > 1)
2965 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2966 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2967 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002968 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002969 mtqc |= IXGBE_MTQC_64VF;
2970 } else {
2971 if (tcs > 4)
2972 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2973 else if (tcs > 1)
2974 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2975 else
2976 mtqc = IXGBE_MTQC_64Q_1PB;
2977 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002978
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002979 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002980
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002981 /* Enable Security TX Buffer IFG for multiple pb */
2982 if (tcs) {
2983 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2984 sectx |= IXGBE_SECTX_DCB;
2985 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002986 }
2987
2988 /* re-enable the arbiter */
2989 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2990 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2991}
2992
Auke Kok9a799d72007-09-15 14:07:45 -07002993/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002994 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002995 * @adapter: board private structure
2996 *
2997 * Configure the Tx unit of the MAC after a reset.
2998 **/
2999static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3000{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003001 struct ixgbe_hw *hw = &adapter->hw;
3002 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003003 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003004
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003005 ixgbe_setup_mtqc(adapter);
3006
3007 if (hw->mac.type != ixgbe_mac_82598EB) {
3008 /* DMATXCTL.EN must be before Tx queues are enabled */
3009 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3010 dmatxctl |= IXGBE_DMATXCTL_TE;
3011 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3012 }
3013
Auke Kok9a799d72007-09-15 14:07:45 -07003014 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003015 for (i = 0; i < adapter->num_tx_queues; i++)
3016 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003017}
3018
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003019static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3020 struct ixgbe_ring *ring)
3021{
3022 struct ixgbe_hw *hw = &adapter->hw;
3023 u8 reg_idx = ring->reg_idx;
3024 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3025
3026 srrctl |= IXGBE_SRRCTL_DROP_EN;
3027
3028 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3029}
3030
3031static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3032 struct ixgbe_ring *ring)
3033{
3034 struct ixgbe_hw *hw = &adapter->hw;
3035 u8 reg_idx = ring->reg_idx;
3036 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3037
3038 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3039
3040 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3041}
3042
3043#ifdef CONFIG_IXGBE_DCB
3044void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3045#else
3046static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3047#endif
3048{
3049 int i;
3050 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3051
3052 if (adapter->ixgbe_ieee_pfc)
3053 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3054
3055 /*
3056 * We should set the drop enable bit if:
3057 * SR-IOV is enabled
3058 * or
3059 * Number of Rx queues > 1 and flow control is disabled
3060 *
3061 * This allows us to avoid head of line blocking for security
3062 * and performance reasons.
3063 */
3064 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3065 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3066 for (i = 0; i < adapter->num_rx_queues; i++)
3067 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3068 } else {
3069 for (i = 0; i < adapter->num_rx_queues; i++)
3070 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3071 }
3072}
3073
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003074#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003075
Yi Zoua6616b42009-08-06 13:05:23 +00003076static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003077 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003078{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003079 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003080 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003081 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003082
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003083 if (hw->mac.type == ixgbe_mac_82598EB) {
3084 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3085
3086 /*
3087 * if VMDq is not active we must program one srrctl register
3088 * per RSS queue since we have enabled RDRXCTL.MVMEN
3089 */
3090 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003091 }
3092
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003093 /* configure header buffer length, needed for RSC */
3094 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003095
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003096 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00003097 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003098
3099 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003100 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003101
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003102 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003103}
3104
Alexander Duyck05abb122010-08-19 13:35:41 +00003105static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003106{
Alexander Duyck05abb122010-08-19 13:35:41 +00003107 struct ixgbe_hw *hw = &adapter->hw;
3108 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003109 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3110 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003111 u32 mrqc = 0, reta = 0;
3112 u32 rxcsum;
3113 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003114 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003115
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003116 /*
3117 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3118 * make full use of any rings they may have. We will use the
3119 * PSRTYPE register to control how many rings we use within the PF.
3120 */
3121 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3122 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003123
Alexander Duyck05abb122010-08-19 13:35:41 +00003124 /* Fill out hash function seeds */
3125 for (i = 0; i < 10; i++)
3126 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003127
Alexander Duyck05abb122010-08-19 13:35:41 +00003128 /* Fill out redirection table */
3129 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003130 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003131 j = 0;
3132 /* reta = 4-byte sliding window of
3133 * 0x00..(indices-1)(indices-1)00..etc. */
3134 reta = (reta << 8) | (j * 0x11);
3135 if ((i & 3) == 3)
3136 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3137 }
3138
3139 /* Disable indicating checksum in descriptor, enables RSS hash */
3140 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3141 rxcsum |= IXGBE_RXCSUM_PCSD;
3142 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3143
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003144 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003145 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003146 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003147 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003148 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003149
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003150 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3151 if (tcs > 4)
3152 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3153 else if (tcs > 1)
3154 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3155 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3156 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3157 else
3158 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3159 } else {
3160 if (tcs > 4)
3161 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3162 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003163 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3164 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003165 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003166 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003167 }
3168
Alexander Duyck05abb122010-08-19 13:35:41 +00003169 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003170 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3171 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3172 IXGBE_MRQC_RSS_FIELD_IPV6 |
3173 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003174
Alexander Duyckef6afc02012-02-08 07:51:53 +00003175 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3176 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3177 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3178 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3179
Alexander Duyck05abb122010-08-19 13:35:41 +00003180 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003181}
3182
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003183/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003184 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3185 * @adapter: address of board private structure
3186 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003187 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003188static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003189 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003190{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003191 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003192 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003193 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003194
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003195 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003196 return;
3197
Alexander Duyck73670962010-08-19 13:38:34 +00003198 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003199 rscctrl |= IXGBE_RSCCTL_RSCEN;
3200 /*
3201 * we must limit the number of descriptors so that the
3202 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003203 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003204 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003205 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003206 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003207}
3208
Alexander Duyck9e10e042010-08-19 13:40:06 +00003209#define IXGBE_MAX_RX_DESC_POLL 10
3210static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3211 struct ixgbe_ring *ring)
3212{
3213 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003214 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3215 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003216 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003217
3218 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3219 if (hw->mac.type == ixgbe_mac_82598EB &&
3220 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3221 return;
3222
3223 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003224 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003225 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3226 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3227
3228 if (!wait_loop) {
3229 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3230 "the polling period\n", reg_idx);
3231 }
3232}
3233
Yi Zou2d39d572011-01-06 14:29:56 +00003234void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3235 struct ixgbe_ring *ring)
3236{
3237 struct ixgbe_hw *hw = &adapter->hw;
3238 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3239 u32 rxdctl;
3240 u8 reg_idx = ring->reg_idx;
3241
3242 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3243 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3244
3245 /* write value back with RXDCTL.ENABLE bit cleared */
3246 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3247
3248 if (hw->mac.type == ixgbe_mac_82598EB &&
3249 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3250 return;
3251
3252 /* the hardware may take up to 100us to really disable the rx queue */
3253 do {
3254 udelay(10);
3255 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3256 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3257
3258 if (!wait_loop) {
3259 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3260 "the polling period\n", reg_idx);
3261 }
3262}
3263
Alexander Duyck84418e32010-08-19 13:40:54 +00003264void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3265 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003266{
3267 struct ixgbe_hw *hw = &adapter->hw;
3268 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003269 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003270 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003271
Alexander Duyck9e10e042010-08-19 13:40:06 +00003272 /* disable queue to avoid issues while updating state */
3273 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003274 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003275
Alexander Duyckacd37172010-08-19 13:36:05 +00003276 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3277 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3278 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3279 ring->count * sizeof(union ixgbe_adv_rx_desc));
3280 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3281 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003282 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003283
3284 ixgbe_configure_srrctl(adapter, ring);
3285 ixgbe_configure_rscctl(adapter, ring);
3286
3287 if (hw->mac.type == ixgbe_mac_82598EB) {
3288 /*
3289 * enable cache line friendly hardware writes:
3290 * PTHRESH=32 descriptors (half the internal cache),
3291 * this also removes ugly rx_no_buffer_count increment
3292 * HTHRESH=4 descriptors (to minimize latency on fetch)
3293 * WTHRESH=8 burst writeback up to two cache lines
3294 */
3295 rxdctl &= ~0x3FFFFF;
3296 rxdctl |= 0x080420;
3297 }
3298
3299 /* enable receive descriptor ring */
3300 rxdctl |= IXGBE_RXDCTL_ENABLE;
3301 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3302
3303 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003304 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003305}
3306
Alexander Duyck48654522010-08-19 13:36:27 +00003307static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3308{
3309 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003310 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003311 int p;
3312
3313 /* PSRTYPE must be initialized in non 82598 adapters */
3314 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003315 IXGBE_PSRTYPE_UDPHDR |
3316 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003317 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003318 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003319
3320 if (hw->mac.type == ixgbe_mac_82598EB)
3321 return;
3322
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003323 if (rss_i > 3)
3324 psrtype |= 2 << 29;
3325 else if (rss_i > 1)
3326 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003327
3328 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003329 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003330 psrtype);
3331}
3332
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003333static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3334{
3335 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003336 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003337 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003338 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003339
3340 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3341 return;
3342
3343 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003344 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3345 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003346 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003347 vmdctl |= IXGBE_VT_CTL_REPLEN;
3348 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003349
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003350 vf_shift = VMDQ_P(0) % 32;
3351 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003352
3353 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003354 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3355 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3356 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3357 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003358 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3359 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003360
3361 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003362 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003363
3364 /*
3365 * Set up VF register offsets for selected VT Mode,
3366 * i.e. 32 or 64 VFs for SR-IOV
3367 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003368 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3369 case IXGBE_82599_VMDQ_8Q_MASK:
3370 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3371 break;
3372 case IXGBE_82599_VMDQ_4Q_MASK:
3373 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3374 break;
3375 default:
3376 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3377 break;
3378 }
3379
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003380 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3381
Alexander Duyck435b19f2012-05-18 06:34:08 +00003382
Greg Rosea985b6c32010-11-18 03:02:52 +00003383 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003384 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003385 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003386 /* For VFs that have spoof checking turned off */
3387 for (i = 0; i < adapter->num_vfs; i++) {
3388 if (!adapter->vfinfo[i].spoofchk_enabled)
3389 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3390 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003391}
3392
Alexander Duyck477de6e2010-08-19 13:38:11 +00003393static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003394{
Auke Kok9a799d72007-09-15 14:07:45 -07003395 struct ixgbe_hw *hw = &adapter->hw;
3396 struct net_device *netdev = adapter->netdev;
3397 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003398 struct ixgbe_ring *rx_ring;
3399 int i;
3400 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003401
Alexander Duyck477de6e2010-08-19 13:38:11 +00003402#ifdef IXGBE_FCOE
3403 /* adjust max frame to be able to do baby jumbo for FCoE */
3404 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3405 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3406 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3407
3408#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003409
3410 /* adjust max frame to be at least the size of a standard frame */
3411 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3412 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3413
Alexander Duyck477de6e2010-08-19 13:38:11 +00003414 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3415 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3416 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3417 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3418
3419 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003420 }
3421
Auke Kok9a799d72007-09-15 14:07:45 -07003422 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003423 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3424 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003425 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3426
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003427 /*
3428 * Setup the HW Rx Head and Tail Descriptor Pointers and
3429 * the Base and Length of the Rx Descriptor Ring
3430 */
Auke Kok9a799d72007-09-15 14:07:45 -07003431 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003432 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003433 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3434 set_ring_rsc_enabled(rx_ring);
3435 else
3436 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003437 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003438}
3439
Alexander Duyck73670962010-08-19 13:38:34 +00003440static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3441{
3442 struct ixgbe_hw *hw = &adapter->hw;
3443 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3444
3445 switch (hw->mac.type) {
3446 case ixgbe_mac_82598EB:
3447 /*
3448 * For VMDq support of different descriptor types or
3449 * buffer sizes through the use of multiple SRRCTL
3450 * registers, RDRXCTL.MVMEN must be set to 1
3451 *
3452 * also, the manual doesn't mention it clearly but DCA hints
3453 * will only use queue 0's tags unless this bit is set. Side
3454 * effects of setting this bit are only that SRRCTL must be
3455 * fully programmed [0..15]
3456 */
3457 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3458 break;
3459 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003460 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003461 /* Disable RSC for ACK packets */
3462 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3463 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3464 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3465 /* hardware requires some bits to be set by default */
3466 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3467 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3468 break;
3469 default:
3470 /* We should do nothing since we don't know this hardware */
3471 return;
3472 }
3473
3474 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3475}
3476
Alexander Duyck477de6e2010-08-19 13:38:11 +00003477/**
3478 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3479 * @adapter: board private structure
3480 *
3481 * Configure the Rx unit of the MAC after a reset.
3482 **/
3483static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3484{
3485 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003486 int i;
3487 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003488
3489 /* disable receives while setting up the descriptors */
3490 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3491 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3492
3493 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003494 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003495
Alexander Duyck9e10e042010-08-19 13:40:06 +00003496 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003497 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003498
Alexander Duyck477de6e2010-08-19 13:38:11 +00003499 /* set_rx_buffer_len must be called before ring initialization */
3500 ixgbe_set_rx_buffer_len(adapter);
3501
3502 /*
3503 * Setup the HW Rx Head and Tail Descriptor Pointers and
3504 * the Base and Length of the Rx Descriptor Ring
3505 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003506 for (i = 0; i < adapter->num_rx_queues; i++)
3507 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003508
Alexander Duyck9e10e042010-08-19 13:40:06 +00003509 /* disable drop enable for 82598 parts */
3510 if (hw->mac.type == ixgbe_mac_82598EB)
3511 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3512
3513 /* enable all receives */
3514 rxctrl |= IXGBE_RXCTRL_RXEN;
3515 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003516}
3517
Patrick McHardy80d5c362013-04-19 02:04:28 +00003518static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3519 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003520{
3521 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003522 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003523
3524 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003525 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003526 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003527
3528 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003529}
3530
Patrick McHardy80d5c362013-04-19 02:04:28 +00003531static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3532 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003533{
3534 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003535 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003536
Auke Kok9a799d72007-09-15 14:07:45 -07003537 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003538 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003539 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003540
3541 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003542}
3543
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003544/**
3545 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3546 * @adapter: driver data
3547 */
3548static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3549{
3550 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003551 u32 vlnctrl;
3552
3553 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3554 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3555 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3556}
3557
3558/**
3559 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3560 * @adapter: driver data
3561 */
3562static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3563{
3564 struct ixgbe_hw *hw = &adapter->hw;
3565 u32 vlnctrl;
3566
3567 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3568 vlnctrl |= IXGBE_VLNCTRL_VFE;
3569 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3570 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3571}
3572
3573/**
3574 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3575 * @adapter: driver data
3576 */
3577static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3578{
3579 struct ixgbe_hw *hw = &adapter->hw;
3580 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003581 int i, j;
3582
3583 switch (hw->mac.type) {
3584 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003585 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3586 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003587 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3588 break;
3589 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003590 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003591 for (i = 0; i < adapter->num_rx_queues; i++) {
3592 j = adapter->rx_ring[i]->reg_idx;
3593 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3594 vlnctrl &= ~IXGBE_RXDCTL_VME;
3595 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3596 }
3597 break;
3598 default:
3599 break;
3600 }
3601}
3602
3603/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003604 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003605 * @adapter: driver data
3606 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003607static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003608{
3609 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003610 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003611 int i, j;
3612
3613 switch (hw->mac.type) {
3614 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003615 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3616 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003617 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3618 break;
3619 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003620 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003621 for (i = 0; i < adapter->num_rx_queues; i++) {
3622 j = adapter->rx_ring[i]->reg_idx;
3623 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3624 vlnctrl |= IXGBE_RXDCTL_VME;
3625 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3626 }
3627 break;
3628 default:
3629 break;
3630 }
3631}
3632
Auke Kok9a799d72007-09-15 14:07:45 -07003633static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3634{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003635 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003636
Patrick McHardy80d5c362013-04-19 02:04:28 +00003637 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003638
3639 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00003640 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003641}
3642
3643/**
Alexander Duyck28500622010-06-15 09:25:48 +00003644 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3645 * @netdev: network interface device structure
3646 *
3647 * Writes unicast address list to the RAR table.
3648 * Returns: -ENOMEM on failure/insufficient address space
3649 * 0 on no addresses written
3650 * X on writing X addresses to the RAR table
3651 **/
3652static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3653{
3654 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3655 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003656 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003657 int count = 0;
3658
John Fastabend95447462012-05-31 12:42:26 +00003659 /* In SR-IOV mode significantly less RAR entries are available */
3660 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3661 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3662
Alexander Duyck28500622010-06-15 09:25:48 +00003663 /* return ENOMEM indicating insufficient memory for addresses */
3664 if (netdev_uc_count(netdev) > rar_entries)
3665 return -ENOMEM;
3666
John Fastabend95447462012-05-31 12:42:26 +00003667 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003668 struct netdev_hw_addr *ha;
3669 /* return error if we do not support writing to RAR table */
3670 if (!hw->mac.ops.set_rar)
3671 return -ENOMEM;
3672
3673 netdev_for_each_uc_addr(ha, netdev) {
3674 if (!rar_entries)
3675 break;
3676 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003677 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003678 count++;
3679 }
3680 }
3681 /* write the addresses in reverse order to avoid write combining */
3682 for (; rar_entries > 0 ; rar_entries--)
3683 hw->mac.ops.clear_rar(hw, rar_entries);
3684
3685 return count;
3686}
3687
3688/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003689 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003690 * @netdev: network interface device structure
3691 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003692 * The set_rx_method entry point is called whenever the unicast/multicast
3693 * address list or the network interface flags are updated. This routine is
3694 * responsible for configuring the hardware for proper unicast, multicast and
3695 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003696 **/
Greg Rose7f870472010-01-09 02:25:29 +00003697void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003698{
3699 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3700 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003701 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3702 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003703
3704 /* Check for Promiscuous and All Multicast modes */
3705
3706 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3707
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003708 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003709 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003710 fctrl |= IXGBE_FCTRL_BAM;
3711 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3712 fctrl |= IXGBE_FCTRL_PMCF;
3713
Alexander Duyck28500622010-06-15 09:25:48 +00003714 /* clear the bits we are changing the status of */
3715 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3716
Auke Kok9a799d72007-09-15 14:07:45 -07003717 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003718 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003719 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003720 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003721 /* don't hardware filter vlans in promisc mode */
3722 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003723 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003724 if (netdev->flags & IFF_ALLMULTI) {
3725 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003726 vmolr |= IXGBE_VMOLR_MPE;
3727 } else {
3728 /*
3729 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003730 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003731 * that we can at least receive multicast traffic
3732 */
3733 hw->mac.ops.update_mc_addr_list(hw, netdev);
3734 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003735 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003736 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003737 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003738 }
3739
3740 /*
3741 * Write addresses to available RAR registers, if there is not
3742 * sufficient space to store all the addresses then enable
3743 * unicast promiscuous mode
3744 */
3745 count = ixgbe_write_uc_addr_list(netdev);
3746 if (count < 0) {
3747 fctrl |= IXGBE_FCTRL_UPE;
3748 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003749 }
3750
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003751 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003752 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003753
3754 if (hw->mac.type != ixgbe_mac_82598EB) {
3755 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003756 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3757 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003758 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003759 }
3760
Ben Greear3f2d1c02012-03-08 08:28:41 +00003761 /* This is useful for sniffing bad packets. */
3762 if (adapter->netdev->features & NETIF_F_RXALL) {
3763 /* UPE and MPE will be handled by normal PROMISC logic
3764 * in e1000e_set_rx_mode */
3765 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3766 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3767 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3768
3769 fctrl &= ~(IXGBE_FCTRL_DPF);
3770 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3771 }
3772
Auke Kok9a799d72007-09-15 14:07:45 -07003773 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003774
Patrick McHardyf6469682013-04-19 02:04:27 +00003775 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00003776 ixgbe_vlan_strip_enable(adapter);
3777 else
3778 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003779}
3780
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003781static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3782{
3783 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003784
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003785 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
3786 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003787 napi_enable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003788 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003789}
3790
3791static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3792{
3793 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003794
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003795 local_bh_disable(); /* for ixgbe_qv_lock_napi() */
3796 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003797 napi_disable(&adapter->q_vector[q_idx]->napi);
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003798 while (!ixgbe_qv_lock_napi(adapter->q_vector[q_idx])) {
3799 pr_info("QV %d locked\n", q_idx);
3800 mdelay(1);
3801 }
3802 }
3803 local_bh_enable();
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003804}
3805
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003806#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003807/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003808 * ixgbe_configure_dcb - Configure DCB hardware
3809 * @adapter: ixgbe adapter struct
3810 *
3811 * This is called by the driver on open to configure the DCB hardware.
3812 * This is also called by the gennetlink interface when reconfiguring
3813 * the DCB state.
3814 */
3815static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3816{
3817 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003818 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003819
Alexander Duyck67ebd792010-08-19 13:34:04 +00003820 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3821 if (hw->mac.type == ixgbe_mac_82598EB)
3822 netif_set_gso_max_size(adapter->netdev, 65536);
3823 return;
3824 }
3825
3826 if (hw->mac.type == ixgbe_mac_82598EB)
3827 netif_set_gso_max_size(adapter->netdev, 32768);
3828
John Fastabendb1208182011-10-15 05:00:10 +00003829#ifdef IXGBE_FCOE
3830 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3831 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3832#endif
3833
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003834 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003835 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003836 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3837 DCB_TX_CONFIG);
3838 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3839 DCB_RX_CONFIG);
3840 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003841 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3842 ixgbe_dcb_hw_ets(&adapter->hw,
3843 adapter->ixgbe_ieee_ets,
3844 max_frame);
3845 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3846 adapter->ixgbe_ieee_pfc->pfc_en,
3847 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003848 }
John Fastabend8187cd42011-02-23 05:58:08 +00003849
3850 /* Enable RSS Hash per TC */
3851 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003852 u32 msb = 0;
3853 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003854
Alexander Duyckd411a932012-06-30 00:14:01 +00003855 while (rss_i) {
3856 msb++;
3857 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003858 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003859
Alexander Duyck4ae63732012-06-22 06:46:33 +00003860 /* write msb to all 8 TCs in one write */
3861 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003862 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003863}
John Fastabend9da712d2011-08-23 03:14:22 +00003864#endif
3865
3866/* Additional bittime to account for IXGBE framing */
3867#define IXGBE_ETH_FRAMING 20
3868
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003869/**
John Fastabend9da712d2011-08-23 03:14:22 +00003870 * ixgbe_hpbthresh - calculate high water mark for flow control
3871 *
3872 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003873 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003874 */
3875static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3876{
3877 struct ixgbe_hw *hw = &adapter->hw;
3878 struct net_device *dev = adapter->netdev;
3879 int link, tc, kb, marker;
3880 u32 dv_id, rx_pba;
3881
3882 /* Calculate max LAN frame size */
3883 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3884
3885#ifdef IXGBE_FCOE
3886 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003887 if ((dev->features & NETIF_F_FCOE_MTU) &&
3888 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3889 (pb == ixgbe_fcoe_get_tc(adapter)))
3890 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003891
3892#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003893 /* Calculate delay value for device */
3894 switch (hw->mac.type) {
3895 case ixgbe_mac_X540:
3896 dv_id = IXGBE_DV_X540(link, tc);
3897 break;
3898 default:
3899 dv_id = IXGBE_DV(link, tc);
3900 break;
3901 }
3902
3903 /* Loopback switch introduces additional latency */
3904 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3905 dv_id += IXGBE_B2BT(tc);
3906
3907 /* Delay value is calculated in bit times convert to KB */
3908 kb = IXGBE_BT2KB(dv_id);
3909 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3910
3911 marker = rx_pba - kb;
3912
3913 /* It is possible that the packet buffer is not large enough
3914 * to provide required headroom. In this case throw an error
3915 * to user and a do the best we can.
3916 */
3917 if (marker < 0) {
3918 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3919 "headroom to support flow control."
3920 "Decrease MTU or number of traffic classes\n", pb);
3921 marker = tc + 1;
3922 }
3923
3924 return marker;
3925}
3926
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003927/**
John Fastabend9da712d2011-08-23 03:14:22 +00003928 * ixgbe_lpbthresh - calculate low water mark for for flow control
3929 *
3930 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003931 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003932 */
3933static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3934{
3935 struct ixgbe_hw *hw = &adapter->hw;
3936 struct net_device *dev = adapter->netdev;
3937 int tc;
3938 u32 dv_id;
3939
3940 /* Calculate max LAN frame size */
3941 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3942
3943 /* Calculate delay value for device */
3944 switch (hw->mac.type) {
3945 case ixgbe_mac_X540:
3946 dv_id = IXGBE_LOW_DV_X540(tc);
3947 break;
3948 default:
3949 dv_id = IXGBE_LOW_DV(tc);
3950 break;
3951 }
3952
3953 /* Delay value is calculated in bit times convert to KB */
3954 return IXGBE_BT2KB(dv_id);
3955}
3956
3957/*
3958 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3959 */
3960static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3961{
3962 struct ixgbe_hw *hw = &adapter->hw;
3963 int num_tc = netdev_get_num_tc(adapter->netdev);
3964 int i;
3965
3966 if (!num_tc)
3967 num_tc = 1;
3968
3969 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3970
3971 for (i = 0; i < num_tc; i++) {
3972 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3973
3974 /* Low water marks must not be larger than high water marks */
3975 if (hw->fc.low_water > hw->fc.high_water[i])
3976 hw->fc.low_water = 0;
3977 }
3978}
John Fastabend80605c652011-05-02 12:34:10 +00003979
3980static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3981{
John Fastabend80605c652011-05-02 12:34:10 +00003982 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003983 int hdrm;
3984 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003985
3986 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3987 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003988 hdrm = 32 << adapter->fdir_pballoc;
3989 else
3990 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003991
Alexander Duyckf7e10272011-07-21 00:40:35 +00003992 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003993 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003994}
3995
Alexander Duycke4911d52011-05-11 07:18:52 +00003996static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3997{
3998 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08003999 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004000 struct ixgbe_fdir_filter *filter;
4001
4002 spin_lock(&adapter->fdir_perfect_lock);
4003
4004 if (!hlist_empty(&adapter->fdir_filter_list))
4005 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4006
Sasha Levinb67bfe02013-02-27 17:06:00 -08004007 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004008 &adapter->fdir_filter_list, fdir_node) {
4009 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00004010 &filter->filter,
4011 filter->sw_idx,
4012 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4013 IXGBE_FDIR_DROP_QUEUE :
4014 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00004015 }
4016
4017 spin_unlock(&adapter->fdir_perfect_lock);
4018}
4019
Auke Kok9a799d72007-09-15 14:07:45 -07004020static void ixgbe_configure(struct ixgbe_adapter *adapter)
4021{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004022 struct ixgbe_hw *hw = &adapter->hw;
4023
John Fastabend80605c652011-05-02 12:34:10 +00004024 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004025#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00004026 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004027#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00004028 /*
4029 * We must restore virtualization before VLANs or else
4030 * the VLVF registers will not be populated
4031 */
4032 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004033
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004034 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004035 ixgbe_restore_vlan(adapter);
4036
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004037 switch (hw->mac.type) {
4038 case ixgbe_mac_82599EB:
4039 case ixgbe_mac_X540:
4040 hw->mac.ops.disable_rx_buff(hw);
4041 break;
4042 default:
4043 break;
4044 }
4045
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004046 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004047 ixgbe_init_fdir_signature_82599(&adapter->hw,
4048 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00004049 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4050 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4051 adapter->fdir_pballoc);
4052 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004053 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00004054
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00004055 switch (hw->mac.type) {
4056 case ixgbe_mac_82599EB:
4057 case ixgbe_mac_X540:
4058 hw->mac.ops.enable_rx_buff(hw);
4059 break;
4060 default:
4061 break;
4062 }
4063
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004064#ifdef IXGBE_FCOE
4065 /* configure FCoE L2 filters, redirection table, and Rx control */
4066 ixgbe_configure_fcoe(adapter);
4067
4068#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004069 ixgbe_configure_tx(adapter);
4070 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004071}
4072
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004073static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
4074{
4075 switch (hw->phy.type) {
4076 case ixgbe_phy_sfp_avago:
4077 case ixgbe_phy_sfp_ftl:
4078 case ixgbe_phy_sfp_intel:
4079 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00004080 case ixgbe_phy_sfp_passive_tyco:
4081 case ixgbe_phy_sfp_passive_unknown:
4082 case ixgbe_phy_sfp_active_unknown:
4083 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004084 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00004085 case ixgbe_phy_nl:
4086 if (hw->mac.type == ixgbe_mac_82598EB)
4087 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004088 default:
4089 return false;
4090 }
4091}
4092
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004093/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004094 * ixgbe_sfp_link_config - set up SFP+ link
4095 * @adapter: pointer to private adapter struct
4096 **/
4097static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4098{
Alexander Duyck70864002011-04-27 09:13:56 +00004099 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004100 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00004101 * is that an SFP was inserted/removed after the reset
4102 * but before SFP detection was enabled. As such the best
4103 * solution is to just start searching as soon as we start
4104 */
4105 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4106 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004107
Alexander Duyck70864002011-04-27 09:13:56 +00004108 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004109}
4110
4111/**
4112 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004113 * @hw: pointer to private hardware struct
4114 *
4115 * Returns 0 on success, negative on failure
4116 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004117static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004118{
Josh Hay3d292262012-12-15 03:28:19 +00004119 u32 speed;
4120 bool autoneg, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004121 u32 ret = IXGBE_ERR_LINK_SETUP;
4122
4123 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004124 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004125
4126 if (ret)
4127 goto link_cfg_out;
4128
Josh Hay3d292262012-12-15 03:28:19 +00004129 speed = hw->phy.autoneg_advertised;
4130 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4131 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4132 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004133 if (ret)
4134 goto link_cfg_out;
4135
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004136 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004137 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004138link_cfg_out:
4139 return ret;
4140}
4141
Alexander Duycka34bcff2010-08-19 13:39:20 +00004142static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004143{
Auke Kok9a799d72007-09-15 14:07:45 -07004144 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004145 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004146
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004147 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004148 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4149 IXGBE_GPIE_OCD;
4150 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004151 /*
4152 * use EIAM to auto-mask when MSI-X interrupt is asserted
4153 * this saves a register write for every interrupt
4154 */
4155 switch (hw->mac.type) {
4156 case ixgbe_mac_82598EB:
4157 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4158 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004159 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004160 case ixgbe_mac_X540:
4161 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004162 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4163 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4164 break;
4165 }
4166 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004167 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4168 * specifically only auto mask tx and rx interrupts */
4169 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004170 }
4171
Alexander Duycka34bcff2010-08-19 13:39:20 +00004172 /* XXX: to interrupt immediately for EICS writes, enable this */
4173 /* gpie |= IXGBE_GPIE_EIMEN; */
4174
4175 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4176 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004177
4178 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4179 case IXGBE_82599_VMDQ_8Q_MASK:
4180 gpie |= IXGBE_GPIE_VTMODE_16;
4181 break;
4182 case IXGBE_82599_VMDQ_4Q_MASK:
4183 gpie |= IXGBE_GPIE_VTMODE_32;
4184 break;
4185 default:
4186 gpie |= IXGBE_GPIE_VTMODE_64;
4187 break;
4188 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004189 }
4190
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004191 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004192 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4193 switch (adapter->hw.mac.type) {
4194 case ixgbe_mac_82599EB:
4195 gpie |= IXGBE_SDP0_GPIEN;
4196 break;
4197 case ixgbe_mac_X540:
4198 gpie |= IXGBE_EIMS_TS;
4199 break;
4200 default:
4201 break;
4202 }
4203 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004204
Alexander Duycka34bcff2010-08-19 13:39:20 +00004205 /* Enable fan failure interrupt */
4206 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004207 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004208
Don Skidmore2698b202011-04-13 07:01:52 +00004209 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004210 gpie |= IXGBE_SDP1_GPIEN;
4211 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004212 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004213
4214 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4215}
4216
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004217static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004218{
4219 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004220 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004221 u32 ctrl_ext;
4222
4223 ixgbe_get_hw_control(adapter);
4224 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004225
Auke Kok9a799d72007-09-15 14:07:45 -07004226 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4227 ixgbe_configure_msix(adapter);
4228 else
4229 ixgbe_configure_msi_and_legacy(adapter);
4230
Emil Tantilovec74a472012-09-20 03:33:56 +00004231 /* enable the optics for 82599 SFP+ fiber */
4232 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004233 hw->mac.ops.enable_tx_laser(hw);
4234
Auke Kok9a799d72007-09-15 14:07:45 -07004235 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004236 ixgbe_napi_enable_all(adapter);
4237
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004238 if (ixgbe_is_sfp(hw)) {
4239 ixgbe_sfp_link_config(adapter);
4240 } else {
4241 err = ixgbe_non_sfp_link_config(hw);
4242 if (err)
4243 e_err(probe, "link_config FAILED %d\n", err);
4244 }
4245
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004246 /* clear any pending interrupts, may auto mask */
4247 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004248 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004249
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004250 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004251 * If this adapter has a fan, check to see if we had a failure
4252 * before we enabled the interrupt.
4253 */
4254 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4255 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4256 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004257 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004258 }
4259
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004260 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004261 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004262
Auke Kok9a799d72007-09-15 14:07:45 -07004263 /* bring the link up in the watchdog, this could race with our first
4264 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004265 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4266 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004267 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004268
4269 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4270 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4271 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4272 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004273}
4274
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004275void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4276{
4277 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004278 /* put off any impending NetWatchDogTimeout */
4279 adapter->netdev->trans_start = jiffies;
4280
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004281 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004282 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004283 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004284 /*
4285 * If SR-IOV enabled then wait a bit before bringing the adapter
4286 * back up to give the VFs time to respond to the reset. The
4287 * two second wait is based upon the watchdog timer cycle in
4288 * the VF driver.
4289 */
4290 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4291 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004292 ixgbe_up(adapter);
4293 clear_bit(__IXGBE_RESETTING, &adapter->state);
4294}
4295
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004296void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004297{
4298 /* hardware has been reset, we need to reload some things */
4299 ixgbe_configure(adapter);
4300
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004301 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004302}
4303
4304void ixgbe_reset(struct ixgbe_adapter *adapter)
4305{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004306 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004307 int err;
4308
Alexander Duyck70864002011-04-27 09:13:56 +00004309 /* lock SFP init bit to prevent race conditions with the watchdog */
4310 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4311 usleep_range(1000, 2000);
4312
4313 /* clear all SFP and link config related flags while holding SFP_INIT */
4314 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4315 IXGBE_FLAG2_SFP_NEEDS_RESET);
4316 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4317
Don Skidmore8ca783a2009-05-26 20:40:47 -07004318 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004319 switch (err) {
4320 case 0:
4321 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004322 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004323 break;
4324 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004325 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004326 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004327 case IXGBE_ERR_EEPROM_VERSION:
4328 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004329 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004330 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004331 "your hardware. If you are experiencing problems "
4332 "please contact your Intel or hardware "
4333 "representative who provided you with this "
4334 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004335 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004336 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004337 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004338 }
Auke Kok9a799d72007-09-15 14:07:45 -07004339
Alexander Duyck70864002011-04-27 09:13:56 +00004340 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4341
Auke Kok9a799d72007-09-15 14:07:45 -07004342 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004343 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004344
4345 /* update SAN MAC vmdq pool selection */
4346 if (hw->mac.san_mac_rar_index)
4347 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004348
Jacob Keller1a71ab22012-08-25 03:54:19 +00004349 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4350 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004351}
4352
Auke Kok9a799d72007-09-15 14:07:45 -07004353/**
4354 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004355 * @rx_ring: ring to free buffers from
4356 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004357static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004358{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004359 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004360 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004361 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004362
Alexander Duyck84418e32010-08-19 13:40:54 +00004363 /* ring already cleared, nothing to do */
4364 if (!rx_ring->rx_buffer_info)
4365 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004366
Alexander Duyck84418e32010-08-19 13:40:54 +00004367 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004368 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004369 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004370
Alexander Duyckf8003262012-03-03 02:35:52 +00004371 rx_buffer = &rx_ring->rx_buffer_info[i];
4372 if (rx_buffer->skb) {
4373 struct sk_buff *skb = rx_buffer->skb;
4374 if (IXGBE_CB(skb)->page_released) {
4375 dma_unmap_page(dev,
4376 IXGBE_CB(skb)->dma,
4377 ixgbe_rx_bufsz(rx_ring),
4378 DMA_FROM_DEVICE);
4379 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004380 }
4381 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004382 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004383 rx_buffer->skb = NULL;
4384 if (rx_buffer->dma)
4385 dma_unmap_page(dev, rx_buffer->dma,
4386 ixgbe_rx_pg_size(rx_ring),
4387 DMA_FROM_DEVICE);
4388 rx_buffer->dma = 0;
4389 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004390 __free_pages(rx_buffer->page,
4391 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004392 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004393 }
4394
4395 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4396 memset(rx_ring->rx_buffer_info, 0, size);
4397
4398 /* Zero out the descriptor ring */
4399 memset(rx_ring->desc, 0, rx_ring->size);
4400
Alexander Duyckf8003262012-03-03 02:35:52 +00004401 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004402 rx_ring->next_to_clean = 0;
4403 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004404}
4405
4406/**
4407 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004408 * @tx_ring: ring to be cleaned
4409 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004410static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004411{
4412 struct ixgbe_tx_buffer *tx_buffer_info;
4413 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004414 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004415
Alexander Duyck84418e32010-08-19 13:40:54 +00004416 /* ring already cleared, nothing to do */
4417 if (!tx_ring->tx_buffer_info)
4418 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004419
Alexander Duyck84418e32010-08-19 13:40:54 +00004420 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004421 for (i = 0; i < tx_ring->count; i++) {
4422 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004423 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004424 }
4425
John Fastabenddad8a3b2012-04-23 12:22:39 +00004426 netdev_tx_reset_queue(txring_txq(tx_ring));
4427
Auke Kok9a799d72007-09-15 14:07:45 -07004428 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4429 memset(tx_ring->tx_buffer_info, 0, size);
4430
4431 /* Zero out the descriptor ring */
4432 memset(tx_ring->desc, 0, tx_ring->size);
4433
4434 tx_ring->next_to_use = 0;
4435 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004436}
4437
4438/**
Auke Kok9a799d72007-09-15 14:07:45 -07004439 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4440 * @adapter: board private structure
4441 **/
4442static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4443{
4444 int i;
4445
4446 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004447 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004448}
4449
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004450/**
4451 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4452 * @adapter: board private structure
4453 **/
4454static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4455{
4456 int i;
4457
4458 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004459 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004460}
4461
Alexander Duycke4911d52011-05-11 07:18:52 +00004462static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4463{
Sasha Levinb67bfe02013-02-27 17:06:00 -08004464 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00004465 struct ixgbe_fdir_filter *filter;
4466
4467 spin_lock(&adapter->fdir_perfect_lock);
4468
Sasha Levinb67bfe02013-02-27 17:06:00 -08004469 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00004470 &adapter->fdir_filter_list, fdir_node) {
4471 hlist_del(&filter->fdir_node);
4472 kfree(filter);
4473 }
4474 adapter->fdir_filter_count = 0;
4475
4476 spin_unlock(&adapter->fdir_perfect_lock);
4477}
4478
Auke Kok9a799d72007-09-15 14:07:45 -07004479void ixgbe_down(struct ixgbe_adapter *adapter)
4480{
4481 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004482 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004483 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004484 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004485
4486 /* signal that we are down to the interrupt handler */
4487 set_bit(__IXGBE_DOWN, &adapter->state);
4488
4489 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004490 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4491 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004492
Yi Zou2d39d572011-01-06 14:29:56 +00004493 /* disable all enabled rx queues */
4494 for (i = 0; i < adapter->num_rx_queues; i++)
4495 /* this call also flushes the previous write */
4496 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4497
Don Skidmore032b4322011-03-18 09:32:53 +00004498 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004499
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004500 netif_tx_stop_all_queues(netdev);
4501
Alexander Duyck70864002011-04-27 09:13:56 +00004502 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004503 netif_carrier_off(netdev);
4504 netif_tx_disable(netdev);
4505
4506 ixgbe_irq_disable(adapter);
4507
4508 ixgbe_napi_disable_all(adapter);
4509
Alexander Duyckd034acf2011-04-27 09:25:34 +00004510 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4511 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004512 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4513
4514 del_timer_sync(&adapter->service_timer);
4515
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004516 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004517 /* Clear EITR Select mapping */
4518 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4519
4520 /* Mark all the VFs as inactive */
4521 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004522 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004523
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004524 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004525 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004526
Auke Kok9a799d72007-09-15 14:07:45 -07004527 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004528 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004529 }
4530
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004531 /* disable transmits in the hardware now that interrupts are off */
4532 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004533 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004534 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004535 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004536
4537 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004538 switch (hw->mac.type) {
4539 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004540 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004541 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004542 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4543 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004544 break;
4545 default:
4546 break;
4547 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004548
Paul Larson6f4a0e42008-06-24 17:00:56 -07004549 if (!pci_channel_offline(adapter->pdev))
4550 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004551
Emil Tantilovec74a472012-09-20 03:33:56 +00004552 /* power down the optics for 82599 SFP+ fiber */
4553 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004554 hw->mac.ops.disable_tx_laser(hw);
4555
Auke Kok9a799d72007-09-15 14:07:45 -07004556 ixgbe_clean_all_tx_rings(adapter);
4557 ixgbe_clean_all_rx_rings(adapter);
4558
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004559#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004560 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004561 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004562#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004563}
4564
Auke Kok9a799d72007-09-15 14:07:45 -07004565/**
Auke Kok9a799d72007-09-15 14:07:45 -07004566 * ixgbe_tx_timeout - Respond to a Tx Hang
4567 * @netdev: network interface device structure
4568 **/
4569static void ixgbe_tx_timeout(struct net_device *netdev)
4570{
4571 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4572
4573 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004574 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004575}
4576
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004577/**
Auke Kok9a799d72007-09-15 14:07:45 -07004578 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4579 * @adapter: board private structure to initialize
4580 *
4581 * ixgbe_sw_init initializes the Adapter private data structure.
4582 * Fields are initialized based on PCI device information and
4583 * OS network device settings (MTU size).
4584 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004585static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004586{
4587 struct ixgbe_hw *hw = &adapter->hw;
4588 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004589 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004590 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004591#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004592 int j;
4593 struct tc_configuration *tc;
4594#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004595
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004596 /* PCI config space info */
4597
4598 hw->vendor_id = pdev->vendor;
4599 hw->device_id = pdev->device;
4600 hw->revision_id = pdev->revision;
4601 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4602 hw->subsystem_device_id = pdev->subsystem_device;
4603
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004604 /* Set common capability flags and settings */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004605 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004606 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004607 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4608 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004609 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
4610 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004611 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
4612 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004613 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4614#ifdef CONFIG_IXGBE_DCA
4615 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
4616#endif
4617#ifdef IXGBE_FCOE
4618 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4619 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4620#ifdef CONFIG_IXGBE_DCB
4621 /* Default traffic class to use for FCoE */
4622 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4623#endif /* CONFIG_IXGBE_DCB */
4624#endif /* IXGBE_FCOE */
4625
4626 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08004627 switch (hw->mac.type) {
4628 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004629 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
4630 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
4631
Don Skidmorebf069c92009-05-07 10:39:54 +00004632 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4633 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004634
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004635 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004636 adapter->ring_feature[RING_F_FDIR].limit = 0;
4637 adapter->atr_sample_rate = 0;
4638 adapter->fdir_pballoc = 0;
4639#ifdef IXGBE_FCOE
4640 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
4641 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4642#ifdef CONFIG_IXGBE_DCB
4643 adapter->fcoe.up = 0;
4644#endif /* IXGBE_DCB */
4645#endif /* IXGBE_FCOE */
4646 break;
4647 case ixgbe_mac_82599EB:
4648 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4649 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08004650 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004651 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004652 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
4653 if (fwsm & IXGBE_FWSM_TS_ENABLED)
4654 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08004655 break;
4656 default:
4657 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004658 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004659
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004660#ifdef IXGBE_FCOE
4661 /* FCoE support exists, always init the FCoE lock */
4662 spin_lock_init(&adapter->fcoe.lock);
4663
4664#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004665 /* n-tuple support exists, always init our spinlock */
4666 spin_lock_init(&adapter->fdir_perfect_lock);
4667
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004668#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004669 switch (hw->mac.type) {
4670 case ixgbe_mac_X540:
4671 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4672 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4673 break;
4674 default:
4675 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4676 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4677 break;
4678 }
4679
Alexander Duyck2f90b862008-11-20 20:52:10 -08004680 /* Configure DCB traffic classes */
4681 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4682 tc = &adapter->dcb_cfg.tc_config[j];
4683 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4684 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4685 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4686 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4687 tc->dcb_pfc = pfc_disabled;
4688 }
John Fastabend4de2a022011-09-27 03:52:01 +00004689
4690 /* Initialize default user to priority mapping, UPx->TC0 */
4691 tc = &adapter->dcb_cfg.tc_config[0];
4692 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4693 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4694
Alexander Duyck2f90b862008-11-20 20:52:10 -08004695 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4696 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004697 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004698 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004699 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004700 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4701 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004702
4703#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004704
4705 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004706 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004707 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004708 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004709 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4710 hw->fc.send_xon = true;
Jacob Kellerdb2adc22012-10-24 07:26:02 +00004711 hw->fc.disable_fc_autoneg =
4712 (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
Auke Kok9a799d72007-09-15 14:07:45 -07004713
Alexander Duyck99d74482012-05-09 08:09:25 +00004714#ifdef CONFIG_PCI_IOV
4715 /* assign number of SR-IOV VFs */
4716 if (hw->mac.type != ixgbe_mac_82598EB)
4717 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4718
4719#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004720 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004721 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004722 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004723
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004724 /* set default ring sizes */
4725 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4726 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4727
Alexander Duyckbd198052011-06-11 01:45:08 +00004728 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004729 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004730
Auke Kok9a799d72007-09-15 14:07:45 -07004731 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004732 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004733 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004734 return -EIO;
4735 }
4736
Auke Kok9a799d72007-09-15 14:07:45 -07004737 set_bit(__IXGBE_DOWN, &adapter->state);
4738
4739 return 0;
4740}
4741
4742/**
4743 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004744 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004745 *
4746 * Return 0 on success, negative on failure
4747 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004748int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004749{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004750 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004751 int orig_node = dev_to_node(dev);
4752 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004753 int size;
4754
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004755 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004756
4757 if (tx_ring->q_vector)
4758 numa_node = tx_ring->q_vector->numa_node;
4759
4760 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004761 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004762 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004763 if (!tx_ring->tx_buffer_info)
4764 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004765
4766 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004767 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004768 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004769
Alexander Duyckde88eee2012-02-08 07:49:59 +00004770 set_dev_node(dev, numa_node);
4771 tx_ring->desc = dma_alloc_coherent(dev,
4772 tx_ring->size,
4773 &tx_ring->dma,
4774 GFP_KERNEL);
4775 set_dev_node(dev, orig_node);
4776 if (!tx_ring->desc)
4777 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4778 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004779 if (!tx_ring->desc)
4780 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004781
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004782 tx_ring->next_to_use = 0;
4783 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004784 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004785
4786err:
4787 vfree(tx_ring->tx_buffer_info);
4788 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004789 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004790 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004791}
4792
4793/**
Alexander Duyck69888672008-09-11 20:05:39 -07004794 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4795 * @adapter: board private structure
4796 *
4797 * If this function returns with an error, then it's possible one or
4798 * more of the rings is populated (while the rest are not). It is the
4799 * callers duty to clean those orphaned rings.
4800 *
4801 * Return 0 on success, negative on failure
4802 **/
4803static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4804{
4805 int i, err = 0;
4806
4807 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004808 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004809 if (!err)
4810 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004811
Emil Tantilov396e7992010-07-01 20:05:12 +00004812 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004813 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004814 }
4815
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004816 return 0;
4817err_setup_tx:
4818 /* rewind the index freeing the rings as we go */
4819 while (i--)
4820 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004821 return err;
4822}
4823
4824/**
Auke Kok9a799d72007-09-15 14:07:45 -07004825 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004826 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004827 *
4828 * Returns 0 on success, negative on failure
4829 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004830int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004831{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004832 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004833 int orig_node = dev_to_node(dev);
4834 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004835 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004836
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004837 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004838
4839 if (rx_ring->q_vector)
4840 numa_node = rx_ring->q_vector->numa_node;
4841
4842 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004843 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004844 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004845 if (!rx_ring->rx_buffer_info)
4846 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004847
Auke Kok9a799d72007-09-15 14:07:45 -07004848 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004849 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4850 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004851
Alexander Duyckde88eee2012-02-08 07:49:59 +00004852 set_dev_node(dev, numa_node);
4853 rx_ring->desc = dma_alloc_coherent(dev,
4854 rx_ring->size,
4855 &rx_ring->dma,
4856 GFP_KERNEL);
4857 set_dev_node(dev, orig_node);
4858 if (!rx_ring->desc)
4859 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4860 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004861 if (!rx_ring->desc)
4862 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004863
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004864 rx_ring->next_to_clean = 0;
4865 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004866
4867 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004868err:
4869 vfree(rx_ring->rx_buffer_info);
4870 rx_ring->rx_buffer_info = NULL;
4871 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004872 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004873}
4874
4875/**
Alexander Duyck69888672008-09-11 20:05:39 -07004876 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4877 * @adapter: board private structure
4878 *
4879 * If this function returns with an error, then it's possible one or
4880 * more of the rings is populated (while the rest are not). It is the
4881 * callers duty to clean those orphaned rings.
4882 *
4883 * Return 0 on success, negative on failure
4884 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004885static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4886{
4887 int i, err = 0;
4888
4889 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004890 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004891 if (!err)
4892 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004893
Emil Tantilov396e7992010-07-01 20:05:12 +00004894 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004895 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004896 }
4897
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004898#ifdef IXGBE_FCOE
4899 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4900 if (!err)
4901#endif
4902 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004903err_setup_rx:
4904 /* rewind the index freeing the rings as we go */
4905 while (i--)
4906 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004907 return err;
4908}
4909
4910/**
Auke Kok9a799d72007-09-15 14:07:45 -07004911 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004912 * @tx_ring: Tx descriptor ring for a specific queue
4913 *
4914 * Free all transmit software resources
4915 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004916void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004917{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004918 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004919
4920 vfree(tx_ring->tx_buffer_info);
4921 tx_ring->tx_buffer_info = NULL;
4922
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004923 /* if not set, then don't free */
4924 if (!tx_ring->desc)
4925 return;
4926
4927 dma_free_coherent(tx_ring->dev, tx_ring->size,
4928 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004929
4930 tx_ring->desc = NULL;
4931}
4932
4933/**
4934 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4935 * @adapter: board private structure
4936 *
4937 * Free all transmit software resources
4938 **/
4939static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4940{
4941 int i;
4942
4943 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004944 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004945 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004946}
4947
4948/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004949 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004950 * @rx_ring: ring to clean the resources from
4951 *
4952 * Free all receive software resources
4953 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004954void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004955{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004956 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004957
4958 vfree(rx_ring->rx_buffer_info);
4959 rx_ring->rx_buffer_info = NULL;
4960
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004961 /* if not set, then don't free */
4962 if (!rx_ring->desc)
4963 return;
4964
4965 dma_free_coherent(rx_ring->dev, rx_ring->size,
4966 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004967
4968 rx_ring->desc = NULL;
4969}
4970
4971/**
4972 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4973 * @adapter: board private structure
4974 *
4975 * Free all receive software resources
4976 **/
4977static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4978{
4979 int i;
4980
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004981#ifdef IXGBE_FCOE
4982 ixgbe_free_fcoe_ddp_resources(adapter);
4983
4984#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004985 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004986 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004987 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004988}
4989
4990/**
Auke Kok9a799d72007-09-15 14:07:45 -07004991 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4992 * @netdev: network interface device structure
4993 * @new_mtu: new value for maximum frame size
4994 *
4995 * Returns 0 on success, negative on failure
4996 **/
4997static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4998{
4999 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5000 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5001
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005002 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005003 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5004 return -EINVAL;
5005
5006 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00005007 * For 82599EB we cannot allow legacy VFs to enable their receive
5008 * paths when MTU greater than 1500 is configured. So display a
5009 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00005010 */
5011 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5012 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00005013 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00005014 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005015
Emil Tantilov396e7992010-07-01 20:05:12 +00005016 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005017
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005018 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005019 netdev->mtu = new_mtu;
5020
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005021 if (netif_running(netdev))
5022 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005023
5024 return 0;
5025}
5026
5027/**
5028 * ixgbe_open - Called when a network interface is made active
5029 * @netdev: network interface device structure
5030 *
5031 * Returns 0 on success, negative value on failure
5032 *
5033 * The open entry point is called when a network interface is made
5034 * active by the system (IFF_UP). At this point all resources needed
5035 * for transmit and receive operations are allocated, the interrupt
5036 * handler is registered with the OS, the watchdog timer is started,
5037 * and the stack is notified that the interface is ready.
5038 **/
5039static int ixgbe_open(struct net_device *netdev)
5040{
5041 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5042 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005043
Auke Kok4bebfaa2008-02-11 09:26:01 -08005044 /* disallow open during test */
5045 if (test_bit(__IXGBE_TESTING, &adapter->state))
5046 return -EBUSY;
5047
Jesse Brandeburg54386462009-04-17 20:44:27 +00005048 netif_carrier_off(netdev);
5049
Auke Kok9a799d72007-09-15 14:07:45 -07005050 /* allocate transmit descriptors */
5051 err = ixgbe_setup_all_tx_resources(adapter);
5052 if (err)
5053 goto err_setup_tx;
5054
Auke Kok9a799d72007-09-15 14:07:45 -07005055 /* allocate receive descriptors */
5056 err = ixgbe_setup_all_rx_resources(adapter);
5057 if (err)
5058 goto err_setup_rx;
5059
5060 ixgbe_configure(adapter);
5061
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005062 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005063 if (err)
5064 goto err_req_irq;
5065
Alexander Duyckac802f52012-07-12 05:52:53 +00005066 /* Notify the stack of the actual queue counts. */
5067 err = netif_set_real_num_tx_queues(netdev,
5068 adapter->num_rx_pools > 1 ? 1 :
5069 adapter->num_tx_queues);
5070 if (err)
5071 goto err_set_queues;
5072
5073
5074 err = netif_set_real_num_rx_queues(netdev,
5075 adapter->num_rx_pools > 1 ? 1 :
5076 adapter->num_rx_queues);
5077 if (err)
5078 goto err_set_queues;
5079
Jacob Keller1a71ab22012-08-25 03:54:19 +00005080 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005081
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005082 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005083
5084 return 0;
5085
Alexander Duyckac802f52012-07-12 05:52:53 +00005086err_set_queues:
5087 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005088err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005089 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005090err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005091 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00005092err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07005093 ixgbe_reset(adapter);
5094
5095 return err;
5096}
5097
5098/**
5099 * ixgbe_close - Disables a network interface
5100 * @netdev: network interface device structure
5101 *
5102 * Returns 0, this is not allowed to fail
5103 *
5104 * The close entry point is called when an interface is de-activated
5105 * by the OS. The hardware is still under the drivers control, but
5106 * needs to be disabled. A global MAC reset is issued to stop the
5107 * hardware, and all transmit and receive resources are freed.
5108 **/
5109static int ixgbe_close(struct net_device *netdev)
5110{
5111 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005112
Jacob Keller1a71ab22012-08-25 03:54:19 +00005113 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005114
Auke Kok9a799d72007-09-15 14:07:45 -07005115 ixgbe_down(adapter);
5116 ixgbe_free_irq(adapter);
5117
Alexander Duycke4911d52011-05-11 07:18:52 +00005118 ixgbe_fdir_filter_exit(adapter);
5119
Auke Kok9a799d72007-09-15 14:07:45 -07005120 ixgbe_free_all_tx_resources(adapter);
5121 ixgbe_free_all_rx_resources(adapter);
5122
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005123 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005124
5125 return 0;
5126}
5127
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005128#ifdef CONFIG_PM
5129static int ixgbe_resume(struct pci_dev *pdev)
5130{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005131 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5132 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005133 u32 err;
5134
5135 pci_set_power_state(pdev, PCI_D0);
5136 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005137 /*
5138 * pci_restore_state clears dev->state_saved so call
5139 * pci_save_state to restore it.
5140 */
5141 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005142
5143 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005144 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005145 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005146 return err;
5147 }
5148 pci_set_master(pdev);
5149
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005150 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005151
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005152 ixgbe_reset(adapter);
5153
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005154 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5155
Alexander Duyckac802f52012-07-12 05:52:53 +00005156 rtnl_lock();
5157 err = ixgbe_init_interrupt_scheme(adapter);
5158 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005159 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005160
5161 rtnl_unlock();
5162
5163 if (err)
5164 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005165
5166 netif_device_attach(netdev);
5167
5168 return 0;
5169}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005170#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005171
5172static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005173{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005174 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5175 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005176 struct ixgbe_hw *hw = &adapter->hw;
5177 u32 ctrl, fctrl;
5178 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005179#ifdef CONFIG_PM
5180 int retval = 0;
5181#endif
5182
5183 netif_device_detach(netdev);
5184
akepner499ab5c2013-03-13 14:54:58 +00005185 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005186 if (netif_running(netdev)) {
5187 ixgbe_down(adapter);
5188 ixgbe_free_irq(adapter);
5189 ixgbe_free_all_tx_resources(adapter);
5190 ixgbe_free_all_rx_resources(adapter);
5191 }
akepner499ab5c2013-03-13 14:54:58 +00005192 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005193
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005194 ixgbe_clear_interrupt_scheme(adapter);
5195
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005196#ifdef CONFIG_PM
5197 retval = pci_save_state(pdev);
5198 if (retval)
5199 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005200
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005201#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005202 if (wufc) {
5203 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005204
Emil Tantilovec74a472012-09-20 03:33:56 +00005205 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5206 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005207 hw->mac.ops.enable_tx_laser(hw);
5208
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005209 /* turn on all-multi mode if wake on multicast is enabled */
5210 if (wufc & IXGBE_WUFC_MC) {
5211 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5212 fctrl |= IXGBE_FCTRL_MPE;
5213 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5214 }
5215
5216 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5217 ctrl |= IXGBE_CTRL_GIO_DIS;
5218 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5219
5220 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5221 } else {
5222 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5223 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5224 }
5225
Alexander Duyckbd508172010-11-16 19:27:03 -08005226 switch (hw->mac.type) {
5227 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005228 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005229 break;
5230 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005231 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005232 pci_wake_from_d3(pdev, !!wufc);
5233 break;
5234 default:
5235 break;
5236 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005237
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005238 *enable_wake = !!wufc;
5239
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005240 ixgbe_release_hw_control(adapter);
5241
5242 pci_disable_device(pdev);
5243
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005244 return 0;
5245}
5246
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005247#ifdef CONFIG_PM
5248static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5249{
5250 int retval;
5251 bool wake;
5252
5253 retval = __ixgbe_shutdown(pdev, &wake);
5254 if (retval)
5255 return retval;
5256
5257 if (wake) {
5258 pci_prepare_to_sleep(pdev);
5259 } else {
5260 pci_wake_from_d3(pdev, false);
5261 pci_set_power_state(pdev, PCI_D3hot);
5262 }
5263
5264 return 0;
5265}
5266#endif /* CONFIG_PM */
5267
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005268static void ixgbe_shutdown(struct pci_dev *pdev)
5269{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005270 bool wake;
5271
5272 __ixgbe_shutdown(pdev, &wake);
5273
5274 if (system_state == SYSTEM_POWER_OFF) {
5275 pci_wake_from_d3(pdev, wake);
5276 pci_set_power_state(pdev, PCI_D3hot);
5277 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005278}
5279
5280/**
Auke Kok9a799d72007-09-15 14:07:45 -07005281 * ixgbe_update_stats - Update the board statistics counters.
5282 * @adapter: board private structure
5283 **/
5284void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5285{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005286 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005287 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005288 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005289 u64 total_mpc = 0;
5290 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005291 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5292 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005293 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005294
Don Skidmored08935c2010-06-11 13:20:29 +00005295 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5296 test_bit(__IXGBE_RESETTING, &adapter->state))
5297 return;
5298
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005299 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005300 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005301 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005302 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005303 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5304 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005305 }
5306 adapter->rsc_total_count = rsc_count;
5307 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005308 }
5309
Alexander Duyck5b7da512010-11-16 19:26:50 -08005310 for (i = 0; i < adapter->num_rx_queues; i++) {
5311 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5312 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5313 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5314 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005315 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005316 bytes += rx_ring->stats.bytes;
5317 packets += rx_ring->stats.packets;
5318 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005319 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005320 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5321 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005322 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005323 netdev->stats.rx_bytes = bytes;
5324 netdev->stats.rx_packets = packets;
5325
5326 bytes = 0;
5327 packets = 0;
5328 /* gather some stats to the adapter struct that are per queue */
5329 for (i = 0; i < adapter->num_tx_queues; i++) {
5330 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5331 restart_queue += tx_ring->tx_stats.restart_queue;
5332 tx_busy += tx_ring->tx_stats.tx_busy;
5333 bytes += tx_ring->stats.bytes;
5334 packets += tx_ring->stats.packets;
5335 }
5336 adapter->restart_queue = restart_queue;
5337 adapter->tx_busy = tx_busy;
5338 netdev->stats.tx_bytes = bytes;
5339 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005340
Joe Perches7ca647b2010-09-07 21:35:40 +00005341 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005342
5343 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005344 for (i = 0; i < 8; i++) {
5345 /* for packet buffers not used, the register should read 0 */
5346 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5347 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005348 hwstats->mpc[i] += mpc;
5349 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005350 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5351 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005352 switch (hw->mac.type) {
5353 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005354 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5355 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5356 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005357 hwstats->pxonrxc[i] +=
5358 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005359 break;
5360 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005361 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005362 hwstats->pxonrxc[i] +=
5363 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005364 break;
5365 default:
5366 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005367 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005368 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005369
5370 /*16 register reads */
5371 for (i = 0; i < 16; i++) {
5372 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5373 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5374 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5375 (hw->mac.type == ixgbe_mac_X540)) {
5376 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5377 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5378 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5379 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5380 }
5381 }
5382
Joe Perches7ca647b2010-09-07 21:35:40 +00005383 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005384 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005385 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005386
John Fastabendc84d3242010-11-16 19:27:12 -08005387 ixgbe_update_xoff_received(adapter);
5388
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005389 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005390 switch (hw->mac.type) {
5391 case ixgbe_mac_82598EB:
5392 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005393 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5394 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5395 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5396 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005397 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005398 /* OS2BMC stats are X540 only*/
5399 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5400 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5401 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5402 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5403 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005404 for (i = 0; i < 16; i++)
5405 adapter->hw_rx_no_dma_resources +=
5406 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005407 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005408 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005409 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005410 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005411 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005412 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005413 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005414 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5415 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005416#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005417 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5418 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5419 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5420 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5421 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5422 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005423 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005424 if (adapter->fcoe.ddp_pool) {
5425 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5426 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5427 unsigned int cpu;
5428 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005429 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005430 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5431 noddp += ddp_pool->noddp;
5432 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005433 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005434 hwstats->fcoe_noddp = noddp;
5435 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005436 }
Yi Zou6d455222009-05-13 13:12:16 +00005437#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005438 break;
5439 default:
5440 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005441 }
Auke Kok9a799d72007-09-15 14:07:45 -07005442 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005443 hwstats->bprc += bprc;
5444 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005445 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005446 hwstats->mprc -= bprc;
5447 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5448 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5449 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5450 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5451 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5452 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5453 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5454 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005455 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005456 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005457 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005458 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005459 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5460 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005461 /*
5462 * 82598 errata - tx of flow control packets is included in tx counters
5463 */
5464 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005465 hwstats->gptc -= xon_off_tot;
5466 hwstats->mptc -= xon_off_tot;
5467 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5468 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5469 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5470 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5471 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5472 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5473 hwstats->ptc64 -= xon_off_tot;
5474 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5475 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5476 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5477 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5478 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5479 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005480
5481 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005482 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005483
5484 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005485 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005486 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005487 netdev->stats.rx_length_errors = hwstats->rlec;
5488 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005489 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005490}
5491
5492/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005493 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005494 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005495 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005496static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005497{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005498 struct ixgbe_hw *hw = &adapter->hw;
5499 int i;
5500
Alexander Duyckd034acf2011-04-27 09:25:34 +00005501 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5502 return;
5503
5504 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5505
5506 /* if interface is down do nothing */
5507 if (test_bit(__IXGBE_DOWN, &adapter->state))
5508 return;
5509
5510 /* do nothing if we are not using signature filters */
5511 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5512 return;
5513
5514 adapter->fdir_overflow++;
5515
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005516 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5517 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005518 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005519 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005520 /* re-enable flow director interrupts */
5521 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005522 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005523 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005524 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005525 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005526}
5527
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005528/**
5529 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005530 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005531 *
5532 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005533 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005534 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005535 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005536 */
5537static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5538{
Auke Kok9a799d72007-09-15 14:07:45 -07005539 struct ixgbe_hw *hw = &adapter->hw;
5540 u64 eics = 0;
5541 int i;
5542
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005543 /* If we're down or resetting, just bail */
5544 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5545 test_bit(__IXGBE_RESETTING, &adapter->state))
5546 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005547
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005548 /* Force detection of hung controller */
5549 if (netif_carrier_ok(adapter->netdev)) {
5550 for (i = 0; i < adapter->num_tx_queues; i++)
5551 set_check_for_tx_hang(adapter->tx_ring[i]);
5552 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005553
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005554 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005555 /*
5556 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005557 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005558 * would set *both* EIMS and EICS for any bit in EIAM
5559 */
5560 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5561 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005562 } else {
5563 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005564 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005565 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005566 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005567 eics |= ((u64)1 << i);
5568 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005569 }
5570
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005571 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005572 ixgbe_irq_rearm_queues(adapter, eics);
5573
Alexander Duyckfe49f042009-06-04 16:00:09 +00005574}
5575
5576/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005577 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005578 * @adapter: pointer to the device adapter structure
5579 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005580 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005581static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005582{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005583 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005584 u32 link_speed = adapter->link_speed;
5585 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005586 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005587
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005588 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5589 return;
5590
5591 if (hw->mac.ops.check_link) {
5592 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005593 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005594 /* always assume link is up, if no check link function */
5595 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5596 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005597 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005598
5599 if (adapter->ixgbe_ieee_pfc)
5600 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5601
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005602 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005603 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005604 ixgbe_set_rx_drop_en(adapter);
5605 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005606
5607 if (link_up ||
5608 time_after(jiffies, (adapter->link_check_timeout +
5609 IXGBE_TRY_LINK_TIMEOUT))) {
5610 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5611 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5612 IXGBE_WRITE_FLUSH(hw);
5613 }
5614
5615 adapter->link_up = link_up;
5616 adapter->link_speed = link_speed;
5617}
5618
Alexander Duyck107d3012012-10-02 00:17:03 +00005619static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5620{
5621#ifdef CONFIG_IXGBE_DCB
5622 struct net_device *netdev = adapter->netdev;
5623 struct dcb_app app = {
5624 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5625 .protocol = 0,
5626 };
5627 u8 up = 0;
5628
5629 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5630 up = dcb_ieee_getapp_mask(netdev, &app);
5631
5632 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5633#endif
5634}
5635
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005636/**
5637 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5638 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005639 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005640 **/
5641static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5642{
5643 struct net_device *netdev = adapter->netdev;
5644 struct ixgbe_hw *hw = &adapter->hw;
5645 u32 link_speed = adapter->link_speed;
5646 bool flow_rx, flow_tx;
5647
5648 /* only continue if link was previously down */
5649 if (netif_carrier_ok(netdev))
5650 return;
5651
5652 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5653
5654 switch (hw->mac.type) {
5655 case ixgbe_mac_82598EB: {
5656 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5657 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5658 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5659 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5660 }
5661 break;
5662 case ixgbe_mac_X540:
5663 case ixgbe_mac_82599EB: {
5664 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5665 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5666 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5667 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5668 }
5669 break;
5670 default:
5671 flow_tx = false;
5672 flow_rx = false;
5673 break;
5674 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005675
Jacob Keller6cb562d2012-12-05 07:24:41 +00005676 adapter->last_rx_ptp_check = jiffies;
5677
Jacob Keller1a71ab22012-08-25 03:54:19 +00005678 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5679 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005680
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005681 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5682 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5683 "10 Gbps" :
5684 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5685 "1 Gbps" :
5686 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5687 "100 Mbps" :
5688 "unknown speed"))),
5689 ((flow_rx && flow_tx) ? "RX/TX" :
5690 (flow_rx ? "RX" :
5691 (flow_tx ? "TX" : "None"))));
5692
5693 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005694 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005695
Alexander Duyck107d3012012-10-02 00:17:03 +00005696 /* update the default user priority for VFs */
5697 ixgbe_update_default_up(adapter);
5698
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005699 /* ping all the active vfs to let them know link has changed */
5700 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005701}
5702
5703/**
5704 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5705 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005706 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005707 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005708static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005709{
5710 struct net_device *netdev = adapter->netdev;
5711 struct ixgbe_hw *hw = &adapter->hw;
5712
5713 adapter->link_up = false;
5714 adapter->link_speed = 0;
5715
5716 /* only continue if link was up previously */
5717 if (!netif_carrier_ok(netdev))
5718 return;
5719
5720 /* poll for SFP+ cable when link is down */
5721 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5722 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5723
Jacob Keller1a71ab22012-08-25 03:54:19 +00005724 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5725 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005726
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005727 e_info(drv, "NIC Link is Down\n");
5728 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005729
5730 /* ping all the active vfs to let them know link has changed */
5731 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005732}
5733
5734/**
5735 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005736 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005737 **/
5738static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5739{
5740 int i;
5741 int some_tx_pending = 0;
5742
5743 if (!netif_carrier_ok(adapter->netdev)) {
5744 for (i = 0; i < adapter->num_tx_queues; i++) {
5745 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5746 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5747 some_tx_pending = 1;
5748 break;
5749 }
5750 }
5751
5752 if (some_tx_pending) {
5753 /* We've lost link, so the controller stops DMA,
5754 * but we've got queued Tx work that's never going
5755 * to get done, so reset controller to flush Tx.
5756 * (Do the reset outside of interrupt context).
5757 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00005758 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005759 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005760 }
5761 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005762}
5763
Greg Rosea985b6c32010-11-18 03:02:52 +00005764static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5765{
5766 u32 ssvpc;
5767
Greg Rose0584d992012-08-08 00:00:58 +00005768 /* Do not perform spoof check for 82598 or if not in IOV mode */
5769 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5770 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005771 return;
5772
5773 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5774
5775 /*
5776 * ssvpc register is cleared on read, if zero then no
5777 * spoofed packets in the last interval.
5778 */
5779 if (!ssvpc)
5780 return;
5781
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005782 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005783}
5784
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005785/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005786 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005787 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005788 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005789static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005790{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005791 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005792 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5793 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005794 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005795
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005796 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005797
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005798 if (adapter->link_up)
5799 ixgbe_watchdog_link_is_up(adapter);
5800 else
5801 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005802
Greg Rosea985b6c32010-11-18 03:02:52 +00005803 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005804 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005805
5806 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005807}
5808
Alexander Duyck70864002011-04-27 09:13:56 +00005809/**
5810 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005811 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005812 **/
5813static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5814{
5815 struct ixgbe_hw *hw = &adapter->hw;
5816 s32 err;
5817
5818 /* not searching for SFP so there is nothing to do here */
5819 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5820 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5821 return;
5822
Aurélien Guillaume71858ac2013-01-17 06:55:24 +00005823 /* concurent i2c reads are not supported */
5824 if (test_bit(__IXGBE_READ_I2C, &adapter->state))
5825 return;
5826
Alexander Duyck70864002011-04-27 09:13:56 +00005827 /* someone else is in init, wait until next service event */
5828 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5829 return;
5830
5831 err = hw->phy.ops.identify_sfp(hw);
5832 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5833 goto sfp_out;
5834
5835 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5836 /* If no cable is present, then we need to reset
5837 * the next time we find a good cable. */
5838 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5839 }
5840
5841 /* exit on error */
5842 if (err)
5843 goto sfp_out;
5844
5845 /* exit if reset not needed */
5846 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5847 goto sfp_out;
5848
5849 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5850
5851 /*
5852 * A module may be identified correctly, but the EEPROM may not have
5853 * support for that module. setup_sfp() will fail in that case, so
5854 * we should not allow that module to load.
5855 */
5856 if (hw->mac.type == ixgbe_mac_82598EB)
5857 err = hw->phy.ops.reset(hw);
5858 else
5859 err = hw->mac.ops.setup_sfp(hw);
5860
5861 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5862 goto sfp_out;
5863
5864 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5865 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5866
5867sfp_out:
5868 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5869
5870 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5871 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5872 e_dev_err("failed to initialize because an unsupported "
5873 "SFP+ module type was detected.\n");
5874 e_dev_err("Reload the driver after installing a "
5875 "supported module.\n");
5876 unregister_netdev(adapter->netdev);
5877 }
5878}
5879
5880/**
5881 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005882 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005883 **/
5884static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5885{
5886 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00005887 u32 speed;
5888 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00005889
5890 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5891 return;
5892
5893 /* someone else is in init, wait until next service event */
5894 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5895 return;
5896
5897 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5898
Josh Hay3d292262012-12-15 03:28:19 +00005899 speed = hw->phy.autoneg_advertised;
5900 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5901 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Alexander Duyck70864002011-04-27 09:13:56 +00005902 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005903 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00005904
5905 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5906 adapter->link_check_timeout = jiffies;
5907 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5908}
5909
Greg Rose83c61fa2011-09-07 05:59:35 +00005910#ifdef CONFIG_PCI_IOV
5911static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5912{
5913 int vf;
5914 struct ixgbe_hw *hw = &adapter->hw;
5915 struct net_device *netdev = adapter->netdev;
5916 u32 gpc;
5917 u32 ciaa, ciad;
5918
5919 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5920 if (gpc) /* If incrementing then no need for the check below */
5921 return;
5922 /*
5923 * Check to see if a bad DMA write target from an errant or
5924 * malicious VF has caused a PCIe error. If so then we can
5925 * issue a VFLR to the offending VF(s) and then resume without
5926 * requesting a full slot reset.
5927 */
5928
5929 for (vf = 0; vf < adapter->num_vfs; vf++) {
5930 ciaa = (vf << 16) | 0x80000000;
5931 /* 32 bit read so align, we really want status at offset 6 */
5932 ciaa |= PCI_COMMAND;
5933 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5934 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5935 ciaa &= 0x7FFFFFFF;
5936 /* disable debug mode asap after reading data */
5937 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5938 /* Get the upper 16 bits which will be the PCI status reg */
5939 ciad >>= 16;
5940 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5941 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5942 /* Issue VFLR */
5943 ciaa = (vf << 16) | 0x80000000;
5944 ciaa |= 0xA8;
5945 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5946 ciad = 0x00008000; /* VFLR */
5947 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5948 ciaa &= 0x7FFFFFFF;
5949 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5950 }
5951 }
5952}
5953
5954#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005955/**
5956 * ixgbe_service_timer - Timer Call-back
5957 * @data: pointer to adapter cast into an unsigned long
5958 **/
5959static void ixgbe_service_timer(unsigned long data)
5960{
5961 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5962 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005963 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005964
5965 /* poll faster when waiting for link */
5966 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5967 next_event_offset = HZ / 10;
5968 else
5969 next_event_offset = HZ * 2;
5970
Greg Rose83c61fa2011-09-07 05:59:35 +00005971#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005972 /*
5973 * don't bother with SR-IOV VF DMA hang check if there are
5974 * no VFs or the link is down
5975 */
5976 if (!adapter->num_vfs ||
5977 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5978 goto normal_timer_service;
5979
5980 /* If we have VFs allocated then we must check for DMA hangs */
5981 ixgbe_check_for_bad_vf(adapter);
5982 next_event_offset = HZ / 50;
5983 adapter->timer_event_accumulator++;
5984
5985 if (adapter->timer_event_accumulator >= 100)
5986 adapter->timer_event_accumulator = 0;
5987 else
5988 ready = false;
5989
5990normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005991#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005992 /* Reset the timer */
5993 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5994
Greg Rose83c61fa2011-09-07 05:59:35 +00005995 if (ready)
5996 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005997}
5998
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005999static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6000{
6001 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6002 return;
6003
6004 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6005
6006 /* If we're already down or resetting, just bail */
6007 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6008 test_bit(__IXGBE_RESETTING, &adapter->state))
6009 return;
6010
6011 ixgbe_dump(adapter);
6012 netdev_err(adapter->netdev, "Reset adapter\n");
6013 adapter->tx_timeout_count++;
6014
6015 ixgbe_reinit_locked(adapter);
6016}
6017
Alexander Duyck70864002011-04-27 09:13:56 +00006018/**
6019 * ixgbe_service_task - manages and runs subtasks
6020 * @work: pointer to work_struct containing our data
6021 **/
6022static void ixgbe_service_task(struct work_struct *work)
6023{
6024 struct ixgbe_adapter *adapter = container_of(work,
6025 struct ixgbe_adapter,
6026 service_task);
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006027 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006028 ixgbe_sfp_detection_subtask(adapter);
6029 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006030 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006031 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006032 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006033 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00006034
6035 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) {
6036 ixgbe_ptp_overflow_check(adapter);
6037 ixgbe_ptp_rx_hang(adapter);
6038 }
Alexander Duyck70864002011-04-27 09:13:56 +00006039
6040 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006041}
6042
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006043static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6044 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006045 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006046{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006047 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006048 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006049 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006050
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00006051 if (skb->ip_summed != CHECKSUM_PARTIAL)
6052 return 0;
6053
Alexander Duyck897ab152011-05-27 05:31:47 +00006054 if (!skb_is_gso(skb))
6055 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006056
Alexander Duyck897ab152011-05-27 05:31:47 +00006057 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006058 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00006059 if (err)
6060 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006061 }
6062
Alexander Duyck897ab152011-05-27 05:31:47 +00006063 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6064 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6065
Alexander Duyck244e27a2012-02-08 07:51:11 +00006066 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006067 struct iphdr *iph = ip_hdr(skb);
6068 iph->tot_len = 0;
6069 iph->check = 0;
6070 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6071 iph->daddr, 0,
6072 IPPROTO_TCP,
6073 0);
6074 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006075 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6076 IXGBE_TX_FLAGS_CSUM |
6077 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006078 } else if (skb_is_gso_v6(skb)) {
6079 ipv6_hdr(skb)->payload_len = 0;
6080 tcp_hdr(skb)->check =
6081 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6082 &ipv6_hdr(skb)->daddr,
6083 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006084 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6085 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006086 }
6087
Alexander Duyck091a6242012-02-08 07:51:01 +00006088 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006089 l4len = tcp_hdrlen(skb);
6090 *hdr_len = skb_transport_offset(skb) + l4len;
6091
Alexander Duyck091a6242012-02-08 07:51:01 +00006092 /* update gso size and bytecount with header size */
6093 first->gso_segs = skb_shinfo(skb)->gso_segs;
6094 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6095
Alexander Duyckc44f5f52012-10-30 06:01:45 +00006096 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00006097 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6098 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00006099
6100 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6101 vlan_macip_lens = skb_network_header_len(skb);
6102 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006103 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006104
6105 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006106 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006107
6108 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006109}
6110
Alexander Duyck244e27a2012-02-08 07:51:11 +00006111static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6112 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006113{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006114 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006115 u32 vlan_macip_lens = 0;
6116 u32 mss_l4len_idx = 0;
6117 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006118
Alexander Duyck897ab152011-05-27 05:31:47 +00006119 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006120 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6121 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6122 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006123 } else {
6124 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006125 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006126 case __constant_htons(ETH_P_IP):
6127 vlan_macip_lens |= skb_network_header_len(skb);
6128 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6129 l4_hdr = ip_hdr(skb)->protocol;
6130 break;
6131 case __constant_htons(ETH_P_IPV6):
6132 vlan_macip_lens |= skb_network_header_len(skb);
6133 l4_hdr = ipv6_hdr(skb)->nexthdr;
6134 break;
6135 default:
6136 if (unlikely(net_ratelimit())) {
6137 dev_warn(tx_ring->dev,
6138 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006139 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006140 }
6141 break;
6142 }
Auke Kok9a799d72007-09-15 14:07:45 -07006143
Alexander Duyck897ab152011-05-27 05:31:47 +00006144 switch (l4_hdr) {
6145 case IPPROTO_TCP:
6146 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6147 mss_l4len_idx = tcp_hdrlen(skb) <<
6148 IXGBE_ADVTXD_L4LEN_SHIFT;
6149 break;
6150 case IPPROTO_SCTP:
6151 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6152 mss_l4len_idx = sizeof(struct sctphdr) <<
6153 IXGBE_ADVTXD_L4LEN_SHIFT;
6154 break;
6155 case IPPROTO_UDP:
6156 mss_l4len_idx = sizeof(struct udphdr) <<
6157 IXGBE_ADVTXD_L4LEN_SHIFT;
6158 break;
6159 default:
6160 if (unlikely(net_ratelimit())) {
6161 dev_warn(tx_ring->dev,
6162 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006163 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006164 }
6165 break;
6166 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006167
6168 /* update TX checksum flag */
6169 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006170 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006171
Alexander Duyck244e27a2012-02-08 07:51:11 +00006172 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006173 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006174 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006175
6176 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6177 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006178}
6179
Alexander Duyck472148c2012-11-07 02:34:28 +00006180#define IXGBE_SET_FLAG(_input, _flag, _result) \
6181 ((_flag <= _result) ? \
6182 ((u32)(_input & _flag) * (_result / _flag)) : \
6183 ((u32)(_input & _flag) / (_flag / _result)))
6184
6185static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006186{
6187 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006188 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6189 IXGBE_ADVTXD_DCMD_DEXT |
6190 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006191
6192 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006193 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6194 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006195
Alexander Duyckd3d00232011-07-15 02:31:25 +00006196 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006197 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6198 IXGBE_ADVTXD_DCMD_TSE);
6199
6200 /* set timestamp bit if present */
6201 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6202 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006203
Alexander Duyck62748b72012-07-20 08:09:01 +00006204 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006205 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006206
Alexander Duyckd3d00232011-07-15 02:31:25 +00006207 return cmd_type;
6208}
6209
Alexander Duyck729739b2012-02-08 07:51:06 +00006210static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6211 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006212{
Alexander Duyck472148c2012-11-07 02:34:28 +00006213 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006214
6215 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006216 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6217 IXGBE_TX_FLAGS_CSUM,
6218 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006219
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006220 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006221 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6222 IXGBE_TX_FLAGS_IPV4,
6223 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006224
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006225 /*
6226 * Check Context must be set if Tx switch is enabled, which it
6227 * always is for case where virtual functions are running
6228 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006229 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6230 IXGBE_TX_FLAGS_CC,
6231 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006232
Alexander Duyck472148c2012-11-07 02:34:28 +00006233 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006234}
6235
6236#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6237 IXGBE_TXD_CMD_RS)
6238
6239static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006240 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006241 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006242{
Alexander Duyck729739b2012-02-08 07:51:06 +00006243 struct sk_buff *skb = first->skb;
6244 struct ixgbe_tx_buffer *tx_buffer;
6245 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00006246 struct skb_frag_struct *frag;
6247 dma_addr_t dma;
6248 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006249 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00006250 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006251 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006252
Alexander Duyck729739b2012-02-08 07:51:06 +00006253 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6254
Alexander Duyckec718252012-10-30 06:01:55 +00006255 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
6256
6257 size = skb_headlen(skb);
6258 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00006259
Alexander Duyckd3d00232011-07-15 02:31:25 +00006260#ifdef IXGBE_FCOE
6261 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006262 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006263 size -= sizeof(struct fcoe_crc_eof) - data_len;
6264 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006265 } else {
6266 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006267 }
Auke Kok9a799d72007-09-15 14:07:45 -07006268 }
6269
Alexander Duyckd3d00232011-07-15 02:31:25 +00006270#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006271 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006272
Alexander Duyckec718252012-10-30 06:01:55 +00006273 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006274
Alexander Duyckec718252012-10-30 06:01:55 +00006275 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
6276 if (dma_mapping_error(tx_ring->dev, dma))
6277 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006278
Alexander Duyckec718252012-10-30 06:01:55 +00006279 /* record length, and DMA address */
6280 dma_unmap_len_set(tx_buffer, len, size);
6281 dma_unmap_addr_set(tx_buffer, dma, dma);
6282
6283 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6284
Alexander Duyck729739b2012-02-08 07:51:06 +00006285 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006286 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00006287 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006288
Alexander Duyckd3d00232011-07-15 02:31:25 +00006289 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006290 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006291 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006292 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006293 i = 0;
6294 }
Alexander Duyckec718252012-10-30 06:01:55 +00006295 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006296
6297 dma += IXGBE_MAX_DATA_PER_TXD;
6298 size -= IXGBE_MAX_DATA_PER_TXD;
6299
6300 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006301 }
6302
Alexander Duyck729739b2012-02-08 07:51:06 +00006303 if (likely(!data_len))
6304 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006305
Alexander Duyck472148c2012-11-07 02:34:28 +00006306 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006307
Alexander Duyck729739b2012-02-08 07:51:06 +00006308 i++;
6309 tx_desc++;
6310 if (i == tx_ring->count) {
6311 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6312 i = 0;
6313 }
Alexander Duyckec718252012-10-30 06:01:55 +00006314 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006315
Alexander Duyckd3d00232011-07-15 02:31:25 +00006316#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006317 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006318#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006319 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006320#endif
6321 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006322
Alexander Duyck729739b2012-02-08 07:51:06 +00006323 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6324 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07006325
Alexander Duyck729739b2012-02-08 07:51:06 +00006326 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07006327 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006328
Alexander Duyck729739b2012-02-08 07:51:06 +00006329 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00006330 cmd_type |= size | IXGBE_TXD_CMD;
6331 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006332
Alexander Duyck091a6242012-02-08 07:51:01 +00006333 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006334
Alexander Duyckd3d00232011-07-15 02:31:25 +00006335 /* set the timestamp */
6336 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006337
6338 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006339 * Force memory writes to complete before letting h/w know there
6340 * are new descriptors to fetch. (Only applicable for weak-ordered
6341 * memory model archs, such as IA-64).
6342 *
6343 * We also need this memory barrier to make certain all of the
6344 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006345 */
6346 wmb();
6347
Alexander Duyckd3d00232011-07-15 02:31:25 +00006348 /* set next_to_watch value indicating a packet is present */
6349 first->next_to_watch = tx_desc;
6350
Alexander Duyck729739b2012-02-08 07:51:06 +00006351 i++;
6352 if (i == tx_ring->count)
6353 i = 0;
6354
6355 tx_ring->next_to_use = i;
6356
Alexander Duyckd3d00232011-07-15 02:31:25 +00006357 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006358 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006359
6360 return;
6361dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006362 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006363
6364 /* clear dma mappings for failed tx_buffer_info map */
6365 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006366 tx_buffer = &tx_ring->tx_buffer_info[i];
6367 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6368 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006369 break;
6370 if (i == 0)
6371 i = tx_ring->count;
6372 i--;
6373 }
6374
Alexander Duyckd3d00232011-07-15 02:31:25 +00006375 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006376}
6377
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006378static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006379 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006380{
Alexander Duyck69830522011-01-06 14:29:58 +00006381 struct ixgbe_q_vector *q_vector = ring->q_vector;
6382 union ixgbe_atr_hash_dword input = { .dword = 0 };
6383 union ixgbe_atr_hash_dword common = { .dword = 0 };
6384 union {
6385 unsigned char *network;
6386 struct iphdr *ipv4;
6387 struct ipv6hdr *ipv6;
6388 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006389 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006390 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006391
Alexander Duyck69830522011-01-06 14:29:58 +00006392 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6393 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006394 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006395
Alexander Duyck69830522011-01-06 14:29:58 +00006396 /* do nothing if sampling is disabled */
6397 if (!ring->atr_sample_rate)
6398 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006399
Alexander Duyck69830522011-01-06 14:29:58 +00006400 ring->atr_count++;
6401
6402 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006403 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006404
6405 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006406 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006407 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006408 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006409 hdr.ipv4->protocol != IPPROTO_TCP))
6410 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006411
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006412 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006413
Alexander Duyck66f32a82011-06-29 05:43:22 +00006414 /* skip this packet since it is invalid or the socket is closing */
6415 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006416 return;
6417
6418 /* sample on all syn packets or once every atr sample count */
6419 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6420 return;
6421
6422 /* reset sample count */
6423 ring->atr_count = 0;
6424
Alexander Duyck244e27a2012-02-08 07:51:11 +00006425 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006426
6427 /*
6428 * src and dst are inverted, think how the receiver sees them
6429 *
6430 * The input is broken into two sections, a non-compressed section
6431 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6432 * is XORed together and stored in the compressed dword.
6433 */
6434 input.formatted.vlan_id = vlan_id;
6435
6436 /*
6437 * since src port and flex bytes occupy the same word XOR them together
6438 * and write the value to source port portion of compressed dword
6439 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006440 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006441 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6442 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006443 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006444 common.port.dst ^= th->source;
6445
Alexander Duyck244e27a2012-02-08 07:51:11 +00006446 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006447 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6448 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6449 } else {
6450 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6451 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6452 hdr.ipv6->saddr.s6_addr32[1] ^
6453 hdr.ipv6->saddr.s6_addr32[2] ^
6454 hdr.ipv6->saddr.s6_addr32[3] ^
6455 hdr.ipv6->daddr.s6_addr32[0] ^
6456 hdr.ipv6->daddr.s6_addr32[1] ^
6457 hdr.ipv6->daddr.s6_addr32[2] ^
6458 hdr.ipv6->daddr.s6_addr32[3];
6459 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006460
6461 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006462 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6463 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006464}
6465
Alexander Duyck63544e92011-05-27 05:31:42 +00006466static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006467{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006468 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006469 /* Herbert's original patch had:
6470 * smp_mb__after_netif_stop_queue();
6471 * but since that doesn't exist yet, just open code it. */
6472 smp_mb();
6473
6474 /* We need to check again in a case another CPU has just
6475 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006476 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006477 return -EBUSY;
6478
6479 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006480 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006481 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006482 return 0;
6483}
6484
Alexander Duyck82d4e462011-06-11 01:44:58 +00006485static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006486{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006487 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006488 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006489 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006490}
6491
Alexander Duyck97488bd2013-01-12 06:33:37 +00006492#ifdef IXGBE_FCOE
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006493static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6494{
Alexander Duyck97488bd2013-01-12 06:33:37 +00006495 struct ixgbe_adapter *adapter;
6496 struct ixgbe_ring_feature *f;
6497 int txq;
Hao Zheng5e09a102010-11-11 13:47:59 +00006498
Alexander Duyck97488bd2013-01-12 06:33:37 +00006499 /*
6500 * only execute the code below if protocol is FCoE
6501 * or FIP and we have FCoE enabled on the adapter
6502 */
6503 switch (vlan_get_protocol(skb)) {
6504 case __constant_htons(ETH_P_FCOE):
6505 case __constant_htons(ETH_P_FIP):
6506 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00006507
Alexander Duyck97488bd2013-01-12 06:33:37 +00006508 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
6509 break;
6510 default:
6511 return __netdev_pick_tx(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006512 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006513
Alexander Duyck97488bd2013-01-12 06:33:37 +00006514 f = &adapter->ring_feature[RING_F_FCOE];
6515
6516 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6517 smp_processor_id();
6518
6519 while (txq >= f->indices)
6520 txq -= f->indices;
6521
6522 return txq + f->offset;
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006523}
6524
Alexander Duyck97488bd2013-01-12 06:33:37 +00006525#endif
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006526netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006527 struct ixgbe_adapter *adapter,
6528 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006529{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006530 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006531 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006532 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006533 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00006534 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006535 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006536 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006537
Alexander Duycka535c302011-05-27 05:31:52 +00006538 /*
6539 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006540 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006541 * + 2 desc gap to keep tail from touching head,
6542 * + 1 desc for context descriptor,
6543 * otherwise try next time
6544 */
Alexander Duycka535c302011-05-27 05:31:52 +00006545 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6546 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00006547
Alexander Duycka535c302011-05-27 05:31:52 +00006548 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6549 tx_ring->tx_stats.tx_busy++;
6550 return NETDEV_TX_BUSY;
6551 }
6552
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006553 /* record the location of the first descriptor for this packet */
6554 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6555 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006556 first->bytecount = skb->len;
6557 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006558
Alexander Duyck66f32a82011-06-29 05:43:22 +00006559 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006560 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006561 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6562 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6563 /* else if it is a SW VLAN check the next protocol and store the tag */
6564 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6565 struct vlan_hdr *vhdr, _vhdr;
6566 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6567 if (!vhdr)
6568 goto out_drop;
6569
6570 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006571 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6572 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006573 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006574 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006575
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006576 skb_tx_timestamp(skb);
6577
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006578 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6579 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6580 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00006581
6582 /* schedule check for Tx timestamp */
6583 adapter->ptp_tx_skb = skb_get(skb);
6584 adapter->ptp_tx_start = jiffies;
6585 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006586 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006587
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006588#ifdef CONFIG_PCI_IOV
6589 /*
6590 * Use the l2switch_enable flag - would be false if the DMA
6591 * Tx switch had been disabled.
6592 */
6593 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00006594 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006595
6596#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006597 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006598 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006599 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6600 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006601 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006602 tx_flags |= (skb->priority & 0x7) <<
6603 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006604 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6605 struct vlan_ethhdr *vhdr;
6606 if (skb_header_cloned(skb) &&
6607 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6608 goto out_drop;
6609 vhdr = (struct vlan_ethhdr *)skb->data;
6610 vhdr->h_vlan_TCI = htons(tx_flags >>
6611 IXGBE_TX_FLAGS_VLAN_SHIFT);
6612 } else {
6613 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6614 }
6615 }
Alexander Duycka535c302011-05-27 05:31:52 +00006616
Alexander Duyck244e27a2012-02-08 07:51:11 +00006617 /* record initial flags and protocol */
6618 first->tx_flags = tx_flags;
6619 first->protocol = protocol;
6620
Yi Zoueacd73f2009-05-13 13:11:06 +00006621#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006622 /* setup tx offload for FCoE */
6623 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006624 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006625 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006626 if (tso < 0)
6627 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006628
Alexander Duyck66f32a82011-06-29 05:43:22 +00006629 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006630 }
Auke Kok9a799d72007-09-15 14:07:45 -07006631
Auke Kok9a799d72007-09-15 14:07:45 -07006632#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006633 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006634 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006635 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006636 else if (!tso)
6637 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006638
6639 /* add the ATR filter if ATR is on */
6640 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006641 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006642
6643#ifdef IXGBE_FCOE
6644xmit_fcoe:
6645#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006646 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006647
6648 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006649
6650 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006651
6652out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006653 dev_kfree_skb_any(first->skb);
6654 first->skb = NULL;
6655
Alexander Duyck897ab152011-05-27 05:31:47 +00006656 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006657}
6658
Alexander Duycka50c29d2012-02-08 07:50:40 +00006659static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6660 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006661{
6662 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006663 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006664
Alexander Duycka50c29d2012-02-08 07:50:40 +00006665 /*
6666 * The minimum packet size for olinfo paylen is 17 so pad the skb
6667 * in order to meet this minimum size requirement.
6668 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006669 if (unlikely(skb->len < 17)) {
6670 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006671 return NETDEV_TX_OK;
6672 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006673 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006674 }
6675
Auke Kok9a799d72007-09-15 14:07:45 -07006676 tx_ring = adapter->tx_ring[skb->queue_mapping];
6677 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6678}
6679
6680/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006681 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006682 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006683 * @p: pointer to an address structure
6684 *
Auke Kok9a799d72007-09-15 14:07:45 -07006685 * Returns 0 on success, negative on failure
6686 **/
6687static int ixgbe_set_mac(struct net_device *netdev, void *p)
6688{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006689 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6690 struct ixgbe_hw *hw = &adapter->hw;
6691 struct sockaddr *addr = p;
6692
6693 if (!is_valid_ether_addr(addr->sa_data))
6694 return -EADDRNOTAVAIL;
6695
6696 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6697 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6698
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006699 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006700
6701 return 0;
6702}
6703
Ben Hutchings6b73e102009-04-29 08:08:58 +00006704static int
6705ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6706{
6707 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6708 struct ixgbe_hw *hw = &adapter->hw;
6709 u16 value;
6710 int rc;
6711
6712 if (prtad != hw->phy.mdio.prtad)
6713 return -EINVAL;
6714 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6715 if (!rc)
6716 rc = value;
6717 return rc;
6718}
6719
6720static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6721 u16 addr, u16 value)
6722{
6723 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6724 struct ixgbe_hw *hw = &adapter->hw;
6725
6726 if (prtad != hw->phy.mdio.prtad)
6727 return -EINVAL;
6728 return hw->phy.ops.write_reg(hw, addr, devad, value);
6729}
6730
6731static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6732{
6733 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6734
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006735 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006736 case SIOCSHWTSTAMP:
6737 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006738 default:
6739 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6740 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006741}
6742
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006743/**
6744 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006745 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006746 * @netdev: network interface device structure
6747 *
6748 * Returns non-zero on failure
6749 **/
6750static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6751{
6752 int err = 0;
6753 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006754 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006755
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006756 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006757 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006758 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006759 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006760
6761 /* update SAN MAC vmdq pool selection */
6762 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006763 }
6764 return err;
6765}
6766
6767/**
6768 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006769 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006770 * @netdev: network interface device structure
6771 *
6772 * Returns non-zero on failure
6773 **/
6774static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6775{
6776 int err = 0;
6777 struct ixgbe_adapter *adapter = netdev_priv(dev);
6778 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6779
6780 if (is_valid_ether_addr(mac->san_addr)) {
6781 rtnl_lock();
6782 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6783 rtnl_unlock();
6784 }
6785 return err;
6786}
6787
Auke Kok9a799d72007-09-15 14:07:45 -07006788#ifdef CONFIG_NET_POLL_CONTROLLER
6789/*
6790 * Polling 'interrupt' - used by things like netconsole to send skbs
6791 * without having to re-enable interrupts. It's not called while
6792 * the interrupt routine is executing.
6793 */
6794static void ixgbe_netpoll(struct net_device *netdev)
6795{
6796 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006797 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006798
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006799 /* if interface is down do nothing */
6800 if (test_bit(__IXGBE_DOWN, &adapter->state))
6801 return;
6802
Auke Kok9a799d72007-09-15 14:07:45 -07006803 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006804 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006805 for (i = 0; i < adapter->num_q_vectors; i++)
6806 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006807 } else {
6808 ixgbe_intr(adapter->pdev->irq, netdev);
6809 }
Auke Kok9a799d72007-09-15 14:07:45 -07006810 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006811}
Auke Kok9a799d72007-09-15 14:07:45 -07006812
Alexander Duyck581330b2012-02-08 07:51:47 +00006813#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006814static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6815 struct rtnl_link_stats64 *stats)
6816{
6817 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6818 int i;
6819
Eric Dumazet1a515022010-11-16 19:26:42 -08006820 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006821 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006822 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006823 u64 bytes, packets;
6824 unsigned int start;
6825
Eric Dumazet1a515022010-11-16 19:26:42 -08006826 if (ring) {
6827 do {
6828 start = u64_stats_fetch_begin_bh(&ring->syncp);
6829 packets = ring->stats.packets;
6830 bytes = ring->stats.bytes;
6831 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6832 stats->rx_packets += packets;
6833 stats->rx_bytes += bytes;
6834 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006835 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006836
6837 for (i = 0; i < adapter->num_tx_queues; i++) {
6838 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6839 u64 bytes, packets;
6840 unsigned int start;
6841
6842 if (ring) {
6843 do {
6844 start = u64_stats_fetch_begin_bh(&ring->syncp);
6845 packets = ring->stats.packets;
6846 bytes = ring->stats.bytes;
6847 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6848 stats->tx_packets += packets;
6849 stats->tx_bytes += bytes;
6850 }
6851 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006852 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006853 /* following stats updated by ixgbe_watchdog_task() */
6854 stats->multicast = netdev->stats.multicast;
6855 stats->rx_errors = netdev->stats.rx_errors;
6856 stats->rx_length_errors = netdev->stats.rx_length_errors;
6857 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6858 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6859 return stats;
6860}
6861
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006862#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006863/**
6864 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6865 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006866 * @tc: number of traffic classes currently enabled
6867 *
6868 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6869 * 802.1Q priority maps to a packet buffer that exists.
6870 */
6871static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6872{
6873 struct ixgbe_hw *hw = &adapter->hw;
6874 u32 reg, rsave;
6875 int i;
6876
6877 /* 82598 have a static priority to TC mapping that can not
6878 * be changed so no validation is needed.
6879 */
6880 if (hw->mac.type == ixgbe_mac_82598EB)
6881 return;
6882
6883 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6884 rsave = reg;
6885
6886 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6887 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6888
6889 /* If up2tc is out of bounds default to zero */
6890 if (up2tc > tc)
6891 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6892 }
6893
6894 if (reg != rsave)
6895 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6896
6897 return;
6898}
6899
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006900/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006901 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6902 * @adapter: Pointer to adapter struct
6903 *
6904 * Populate the netdev user priority to tc map
6905 */
6906static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6907{
6908 struct net_device *dev = adapter->netdev;
6909 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6910 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6911 u8 prio;
6912
6913 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6914 u8 tc = 0;
6915
6916 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6917 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6918 else if (ets)
6919 tc = ets->prio_tc[prio];
6920
6921 netdev_set_prio_tc_map(dev, prio, tc);
6922 }
6923}
6924
Alexander Duyckcca73c52013-01-12 06:33:44 +00006925#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00006926/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006927 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006928 *
6929 * @netdev: net device to configure
6930 * @tc: number of traffic classes to enable
6931 */
6932int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6933{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006934 struct ixgbe_adapter *adapter = netdev_priv(dev);
6935 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006936
John Fastabend8b1c0b22011-05-03 02:26:48 +00006937 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006938 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006939 (hw->mac.type == ixgbe_mac_82598EB &&
6940 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006941 return -EINVAL;
6942
6943 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006944 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006945 * hardware is not flexible enough to do this dynamically.
6946 */
6947 if (netif_running(dev))
6948 ixgbe_close(dev);
6949 ixgbe_clear_interrupt_scheme(adapter);
6950
Alexander Duyckcca73c52013-01-12 06:33:44 +00006951#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00006952 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006953 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006954 ixgbe_set_prio_tc_map(adapter);
6955
John Fastabende7589ea2011-07-18 22:38:36 +00006956 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006957
Alexander Duyck943561d2012-05-09 22:14:44 -07006958 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6959 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006960 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006961 }
John Fastabende7589ea2011-07-18 22:38:36 +00006962 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006963 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006964
Alexander Duyck943561d2012-05-09 22:14:44 -07006965 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6966 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006967
6968 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006969
6970 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6971 adapter->dcb_cfg.pfc_mode_enable = false;
6972 }
6973
John Fastabend8b1c0b22011-05-03 02:26:48 +00006974 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00006975
6976#endif /* CONFIG_IXGBE_DCB */
6977 ixgbe_init_interrupt_scheme(adapter);
6978
John Fastabend8b1c0b22011-05-03 02:26:48 +00006979 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00006980 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00006981
6982 return 0;
6983}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006984
Greg Roseda36b642012-12-11 08:26:43 +00006985#ifdef CONFIG_PCI_IOV
6986void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
6987{
6988 struct net_device *netdev = adapter->netdev;
6989
6990 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00006991 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00006992 rtnl_unlock();
6993}
6994
6995#endif
Don Skidmore082757a2011-07-21 05:55:00 +00006996void ixgbe_do_reset(struct net_device *netdev)
6997{
6998 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6999
7000 if (netif_running(netdev))
7001 ixgbe_reinit_locked(adapter);
7002 else
7003 ixgbe_reset(adapter);
7004}
7005
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007006static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007007 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007008{
7009 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7010
Don Skidmore082757a2011-07-21 05:55:00 +00007011 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007012 if (!(features & NETIF_F_RXCSUM))
7013 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00007014
Alexander Duyck567d2de2012-02-11 07:18:57 +00007015 /* Turn off LRO if not RSC capable */
7016 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7017 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007018
Alexander Duyck567d2de2012-02-11 07:18:57 +00007019 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00007020}
7021
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007022static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00007023 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00007024{
7025 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00007026 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00007027 bool need_reset = false;
7028
Don Skidmore082757a2011-07-21 05:55:00 +00007029 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00007030 if (!(features & NETIF_F_LRO)) {
7031 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00007032 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00007033 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7034 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7035 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7036 if (adapter->rx_itr_setting == 1 ||
7037 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7038 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7039 need_reset = true;
7040 } else if ((changed ^ features) & NETIF_F_LRO) {
7041 e_info(probe, "rx-usecs set too low, "
7042 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00007043 }
7044 }
7045
7046 /*
7047 * Check if Flow Director n-tuple support was enabled or disabled. If
7048 * the state changed, we need to reset.
7049 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007050 switch (features & NETIF_F_NTUPLE) {
7051 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00007052 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00007053 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7054 need_reset = true;
7055
Alexander Duyck567d2de2012-02-11 07:18:57 +00007056 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7057 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00007058 break;
7059 default:
7060 /* turn off perfect filters, enable ATR and reset */
7061 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7062 need_reset = true;
7063
7064 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7065
7066 /* We cannot enable ATR if SR-IOV is enabled */
7067 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7068 break;
7069
7070 /* We cannot enable ATR if we have 2 or more traffic classes */
7071 if (netdev_get_num_tc(netdev) > 1)
7072 break;
7073
7074 /* We cannot enable ATR if RSS is disabled */
7075 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7076 break;
7077
7078 /* A sample rate of 0 indicates ATR disabled */
7079 if (!adapter->atr_sample_rate)
7080 break;
7081
7082 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7083 break;
Don Skidmore082757a2011-07-21 05:55:00 +00007084 }
7085
Patrick McHardyf6469682013-04-19 02:04:27 +00007086 if (features & NETIF_F_HW_VLAN_CTAG_RX)
John Fastabend146d4cc2012-05-15 05:59:26 +00007087 ixgbe_vlan_strip_enable(adapter);
7088 else
7089 ixgbe_vlan_strip_disable(adapter);
7090
Ben Greear3f2d1c02012-03-08 08:28:41 +00007091 if (changed & NETIF_F_RXALL)
7092 need_reset = true;
7093
Alexander Duyck567d2de2012-02-11 07:18:57 +00007094 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00007095 if (need_reset)
7096 ixgbe_do_reset(netdev);
7097
7098 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00007099}
7100
stephen hemmingeredc7d572012-10-01 12:32:33 +00007101static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007102 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00007103 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007104 u16 flags)
7105{
7106 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00007107 int err;
7108
7109 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
Vlad Yasevichfaaf02d2013-03-06 15:39:43 +00007110 return ndo_dflt_fdb_add(ndm, tb, dev, addr, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007111
John Fastabendb1ac1ef2012-11-01 05:00:44 +00007112 /* Hardware does not support aging addresses so if a
7113 * ndm_state is given only allow permanent addresses
7114 */
7115 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007116 pr_info("%s: FDB only supports static addresses\n",
7117 ixgbe_driver_name);
7118 return -EINVAL;
7119 }
7120
Ben Hutchings46acc462012-11-01 09:11:11 +00007121 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00007122 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
7123
7124 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007125 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007126 else
John Fastabend95447462012-05-31 12:42:26 +00007127 err = -ENOMEM;
7128 } else if (is_multicast_ether_addr(addr)) {
7129 err = dev_mc_add_excl(dev, addr);
7130 } else {
7131 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007132 }
7133
7134 /* Only return duplicate errors if NLM_F_EXCL is set */
7135 if (err == -EEXIST && !(flags & NLM_F_EXCL))
7136 err = 0;
7137
7138 return err;
7139}
7140
John Fastabend815cccb2012-10-24 08:13:09 +00007141static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7142 struct nlmsghdr *nlh)
7143{
7144 struct ixgbe_adapter *adapter = netdev_priv(dev);
7145 struct nlattr *attr, *br_spec;
7146 int rem;
7147
7148 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7149 return -EOPNOTSUPP;
7150
7151 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7152
7153 nla_for_each_nested(attr, br_spec, rem) {
7154 __u16 mode;
7155 u32 reg = 0;
7156
7157 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7158 continue;
7159
7160 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007161 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007162 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007163 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7164 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007165 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007166 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7167 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007168 return -EINVAL;
7169
7170 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7171
7172 e_info(drv, "enabling bridge mode: %s\n",
7173 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7174 }
7175
7176 return 0;
7177}
7178
7179static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00007180 struct net_device *dev,
7181 u32 filter_mask)
John Fastabend815cccb2012-10-24 08:13:09 +00007182{
7183 struct ixgbe_adapter *adapter = netdev_priv(dev);
7184 u16 mode;
7185
7186 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7187 return 0;
7188
Greg Rose9b735982012-11-08 02:41:35 +00007189 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007190 mode = BRIDGE_MODE_VEB;
7191 else
7192 mode = BRIDGE_MODE_VEPA;
7193
7194 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7195}
7196
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007197static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007198 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007199 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007200 .ndo_start_xmit = ixgbe_xmit_frame,
Alexander Duyck97488bd2013-01-12 06:33:37 +00007201#ifdef IXGBE_FCOE
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007202 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck97488bd2013-01-12 06:33:37 +00007203#endif
Alexander Duyck581330b2012-02-08 07:51:47 +00007204 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007205 .ndo_validate_addr = eth_validate_addr,
7206 .ndo_set_mac_address = ixgbe_set_mac,
7207 .ndo_change_mtu = ixgbe_change_mtu,
7208 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007209 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7210 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007211 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007212 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7213 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7214 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007215 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007216 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007217 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007218#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007219 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007220#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007221#ifdef CONFIG_NET_POLL_CONTROLLER
7222 .ndo_poll_controller = ixgbe_netpoll,
7223#endif
Eliezer Tamir5a85e732013-06-10 11:40:20 +03007224#ifdef CONFIG_NET_LL_RX_POLL
7225 .ndo_ll_poll = ixgbe_low_latency_recv,
7226#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007227#ifdef IXGBE_FCOE
7228 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007229 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007230 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007231 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7232 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007233 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007234 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007235#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007236 .ndo_set_features = ixgbe_set_features,
7237 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007238 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00007239 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7240 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007241};
7242
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007243/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007244 * ixgbe_wol_supported - Check whether device supports WoL
7245 * @hw: hw specific details
7246 * @device_id: the device ID
7247 * @subdev_id: the subsystem device ID
7248 *
7249 * This function is used by probe and ethtool to determine
7250 * which devices have WoL support
7251 *
7252 **/
7253int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7254 u16 subdevice_id)
7255{
7256 struct ixgbe_hw *hw = &adapter->hw;
7257 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7258 int is_wol_supported = 0;
7259
7260 switch (device_id) {
7261 case IXGBE_DEV_ID_82599_SFP:
7262 /* Only these subdevices could supports WOL */
7263 switch (subdevice_id) {
7264 case IXGBE_SUBDEV_ID_82599_560FLR:
7265 /* only support first port */
7266 if (hw->bus.func != 0)
7267 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00007268 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007269 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007270 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007271 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller979fe5f2013-04-03 04:41:37 +00007272 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007273 is_wol_supported = 1;
7274 break;
7275 }
7276 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00007277 case IXGBE_DEV_ID_82599EN_SFP:
7278 /* Only this subdevice supports WOL */
7279 switch (subdevice_id) {
7280 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
7281 is_wol_supported = 1;
7282 break;
7283 }
7284 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007285 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7286 /* All except this subdevice support WOL */
7287 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7288 is_wol_supported = 1;
7289 break;
7290 case IXGBE_DEV_ID_82599_KX4:
7291 is_wol_supported = 1;
7292 break;
7293 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007294 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007295 /* check eeprom to see if enabled wol */
7296 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7297 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7298 (hw->bus.func == 0))) {
7299 is_wol_supported = 1;
7300 }
7301 break;
7302 }
7303
7304 return is_wol_supported;
7305}
7306
7307/**
Auke Kok9a799d72007-09-15 14:07:45 -07007308 * ixgbe_probe - Device Initialization Routine
7309 * @pdev: PCI device information struct
7310 * @ent: entry in ixgbe_pci_tbl
7311 *
7312 * Returns 0 on success, negative on failure
7313 *
7314 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7315 * The OS initialization, configuring of the adapter private structure,
7316 * and a hardware reset occur.
7317 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007318static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007319{
7320 struct net_device *netdev;
7321 struct ixgbe_adapter *adapter = NULL;
7322 struct ixgbe_hw *hw;
7323 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007324 static int cards_found;
7325 int i, err, pci_using_dac;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007326 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00007327 u8 part_str[IXGBE_PBANUM_LENGTH];
Yi Zoueacd73f2009-05-13 13:11:06 +00007328#ifdef IXGBE_FCOE
7329 u16 device_caps;
7330#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007331 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007332
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007333 /* Catch broken hardware that put the wrong VF device ID in
7334 * the PCIe SR-IOV capability.
7335 */
7336 if (pdev->is_virtfn) {
7337 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7338 pci_name(pdev), pdev->vendor, pdev->device);
7339 return -EINVAL;
7340 }
7341
gouji-new9ce77662009-05-06 10:44:45 +00007342 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007343 if (err)
7344 return err;
7345
Nick Nunley1b507732010-04-27 13:10:27 +00007346 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7347 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007348 pci_using_dac = 1;
7349 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007350 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007351 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007352 err = dma_set_coherent_mask(&pdev->dev,
7353 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007354 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007355 dev_err(&pdev->dev,
7356 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007357 goto err_dma;
7358 }
7359 }
7360 pci_using_dac = 0;
7361 }
7362
gouji-new9ce77662009-05-06 10:44:45 +00007363 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007364 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007365 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007366 dev_err(&pdev->dev,
7367 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007368 goto err_pci_reg;
7369 }
7370
Frans Pop19d5afd2009-10-02 10:04:12 -07007371 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007372
Auke Kok9a799d72007-09-15 14:07:45 -07007373 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007374 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007375
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007376 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00007377#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007378 /* 8 TC w/ 4 queues per TC */
7379 indices = 4 * MAX_TRAFFIC_CLASS;
7380#else
7381 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00007382#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007383 }
John Fastabende901acd2011-04-26 07:26:08 +00007384
John Fastabendc85a2612010-02-25 23:15:21 +00007385 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007386 if (!netdev) {
7387 err = -ENOMEM;
7388 goto err_alloc_etherdev;
7389 }
7390
Auke Kok9a799d72007-09-15 14:07:45 -07007391 SET_NETDEV_DEV(netdev, &pdev->dev);
7392
Auke Kok9a799d72007-09-15 14:07:45 -07007393 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007394 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007395
7396 adapter->netdev = netdev;
7397 adapter->pdev = pdev;
7398 hw = &adapter->hw;
7399 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007400 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007401
Jeff Kirsher05857982008-09-11 19:57:00 -07007402 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007403 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007404 if (!hw->hw_addr) {
7405 err = -EIO;
7406 goto err_ioremap;
7407 }
7408
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007409 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007410 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007411 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007412 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007413
Auke Kok9a799d72007-09-15 14:07:45 -07007414 adapter->bd_number = cards_found;
7415
Auke Kok9a799d72007-09-15 14:07:45 -07007416 /* Setup hw api */
7417 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007418 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007419
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007420 /* EEPROM */
7421 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7422 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7423 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7424 if (!(eec & (1 << 8)))
7425 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7426
7427 /* PHY */
7428 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007429 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007430 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7431 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7432 hw->phy.mdio.mmds = 0;
7433 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7434 hw->phy.mdio.dev = netdev;
7435 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7436 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007437
Don Skidmore8ca783a2009-05-26 20:40:47 -07007438 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007439
7440 /* setup the private structure */
7441 err = ixgbe_sw_init(adapter);
7442 if (err)
7443 goto err_sw_init;
7444
Don Skidmore0b2679d2013-02-21 03:00:04 +00007445 /* Cache if MNG FW is up so we don't have to read the REG later */
7446 if (hw->mac.ops.mng_fw_enabled)
7447 hw->mng_fw_enabled = hw->mac.ops.mng_fw_enabled(hw);
7448
Don Skidmoree86bff02010-02-11 04:14:08 +00007449 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007450 switch (adapter->hw.mac.type) {
7451 case ixgbe_mac_82599EB:
7452 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007453 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007454 break;
7455 default:
7456 break;
7457 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007458
Don Skidmorebf069c92009-05-07 10:39:54 +00007459 /*
7460 * If there is a fan on this device and it has failed log the
7461 * failure.
7462 */
7463 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7464 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7465 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007466 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007467 }
7468
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007469 if (allow_unsupported_sfp)
7470 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7471
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007472 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007473 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007474 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007475 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007476 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7477 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007478 err = 0;
7479 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007480 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007481 "module type was detected.\n");
7482 e_dev_err("Reload the driver after installing a supported "
7483 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007484 goto err_sw_init;
7485 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007486 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007487 goto err_sw_init;
7488 }
7489
Alexander Duyck99d74482012-05-09 08:09:25 +00007490#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00007491 /* SR-IOV not supported on the 82598 */
7492 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7493 goto skip_sriov;
7494 /* Mailbox */
7495 ixgbe_init_mbx_params_pf(hw);
7496 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
7497 ixgbe_enable_sriov(adapter);
Donald Dutile43dc4e02012-12-11 08:26:48 +00007498 pci_sriov_set_totalvfs(pdev, 63);
Greg Rose60a1a682012-12-11 08:26:33 +00007499skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007500
Alexander Duyck99d74482012-05-09 08:09:25 +00007501#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007502 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007503 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007504 NETIF_F_IPV6_CSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00007505 NETIF_F_HW_VLAN_CTAG_TX |
7506 NETIF_F_HW_VLAN_CTAG_RX |
7507 NETIF_F_HW_VLAN_CTAG_FILTER |
Don Skidmore082757a2011-07-21 05:55:00 +00007508 NETIF_F_TSO |
7509 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007510 NETIF_F_RXHASH |
7511 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007512
Don Skidmore082757a2011-07-21 05:55:00 +00007513 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007514
Don Skidmore58be7662011-04-12 09:42:11 +00007515 switch (adapter->hw.mac.type) {
7516 case ixgbe_mac_82599EB:
7517 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007518 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007519 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7520 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007521 break;
7522 default:
7523 break;
7524 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007525
Ben Greear3f2d1c02012-03-08 08:28:41 +00007526 netdev->hw_features |= NETIF_F_RXALL;
7527
Jeff Kirsherad31c402008-06-05 04:05:30 -07007528 netdev->vlan_features |= NETIF_F_TSO;
7529 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007530 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007531 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007532 netdev->vlan_features |= NETIF_F_SG;
7533
Jiri Pirko01789342011-08-16 06:29:00 +00007534 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007535 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007536
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007537#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007538 netdev->dcbnl_ops = &dcbnl_ops;
7539#endif
7540
Yi Zoueacd73f2009-05-13 13:11:06 +00007541#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007542 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007543 unsigned int fcoe_l;
7544
Yi Zoueacd73f2009-05-13 13:11:06 +00007545 if (hw->mac.ops.get_device_caps) {
7546 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007547 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7548 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007549 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007550
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007551
7552 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
7553 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007554
Alexander Duycka58915c2012-05-25 06:38:18 +00007555 netdev->features |= NETIF_F_FSO |
7556 NETIF_F_FCOE_CRC;
7557
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007558 netdev->vlan_features |= NETIF_F_FSO |
7559 NETIF_F_FCOE_CRC |
7560 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007561 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007562#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007563 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007564 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007565 netdev->vlan_features |= NETIF_F_HIGHDMA;
7566 }
Auke Kok9a799d72007-09-15 14:07:45 -07007567
Don Skidmore082757a2011-07-21 05:55:00 +00007568 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7569 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007570 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007571 netdev->features |= NETIF_F_LRO;
7572
Auke Kok9a799d72007-09-15 14:07:45 -07007573 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007574 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007575 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007576 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007577 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007578 }
7579
7580 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007581
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007582 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007583 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007584 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007585 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007586 }
7587
Alexander Duyck70864002011-04-27 09:13:56 +00007588 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007589 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007590
Alexander Duyck70864002011-04-27 09:13:56 +00007591 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7592 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007593
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007594 err = ixgbe_init_interrupt_scheme(adapter);
7595 if (err)
7596 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007597
Jacob Keller8e2813f2012-04-21 06:05:40 +00007598 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007599 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007600 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00007601 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +00007602 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +00007603 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007604 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007605
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007606 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7607
Emil Tantilov15e52092011-09-29 05:01:29 +00007608 /* save off EEPROM version number */
7609 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7610 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7611
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007612 /* pick up the PCI bus settings for reporting later */
7613 hw->mac.ops.get_bus_info(hw);
Jacob Kellerb8e82002013-04-09 07:20:09 +00007614 if (hw->device_id == IXGBE_DEV_ID_82599_SFP_SF_QP)
7615 ixgbe_get_parent_bus_info(adapter);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007616
Auke Kok9a799d72007-09-15 14:07:45 -07007617 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007618 e_dev_info("(PCI Express:%s:%s) %pM\n",
Jacob Kellere8710a52013-02-15 09:18:10 +00007619 (hw->bus.speed == ixgbe_bus_speed_8000 ? "8.0GT/s" :
7620 hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
Don Skidmore67163442011-04-26 08:00:00 +00007621 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007622 "Unknown"),
7623 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7624 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7625 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7626 "Unknown"),
7627 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007628
7629 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7630 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007631 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007632 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007633 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007634 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007635 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007636 else
Don Skidmore289700db2010-12-03 03:32:58 +00007637 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7638 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007639
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007640 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007641 e_dev_warn("PCI-Express bandwidth available for this card is "
7642 "not sufficient for optimal performance.\n");
7643 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7644 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007645 }
7646
Auke Kok9a799d72007-09-15 14:07:45 -07007647 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007648 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007649 if (err == IXGBE_ERR_EEPROM_VERSION) {
7650 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007651 e_dev_warn("This device is a pre-production adapter/LOM. "
7652 "Please be aware there may be issues associated "
7653 "with your hardware. If you are experiencing "
7654 "problems please contact your Intel or hardware "
7655 "representative who provided you with this "
7656 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007657 }
Auke Kok9a799d72007-09-15 14:07:45 -07007658 strcpy(netdev->name, "eth%d");
7659 err = register_netdev(netdev);
7660 if (err)
7661 goto err_register;
7662
Emil Tantilovec74a472012-09-20 03:33:56 +00007663 /* power down the optics for 82599 SFP+ fiber */
7664 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007665 hw->mac.ops.disable_tx_laser(hw);
7666
Jesse Brandeburg54386462009-04-17 20:44:27 +00007667 /* carrier off reporting is important to ethtool even BEFORE open */
7668 netif_carrier_off(netdev);
7669
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007670#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007671 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007672 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007673 ixgbe_setup_dca(adapter);
7674 }
7675#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007676 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007677 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007678 for (i = 0; i < adapter->num_vfs; i++)
7679 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7680 }
7681
Jacob Keller2466dd92011-09-08 03:50:54 +00007682 /* firmware requires driver version to be 0xFFFFFFFF
7683 * since os does not support feature
7684 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007685 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007686 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7687 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007688
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007689 /* add san mac addr to netdev */
7690 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007691
Neerav Parikhea818752012-01-04 20:23:40 +00007692 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007693 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007694
Don Skidmore12109822012-05-04 06:07:08 +00007695#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007696 if (ixgbe_sysfs_init(adapter))
7697 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007698#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007699
Catherine Sullivan00949162012-08-10 01:59:10 +00007700 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00007701
Don Skidmore0b2679d2013-02-21 03:00:04 +00007702 /* Need link setup for MNG FW, else wait for IXGBE_UP */
7703 if (hw->mng_fw_enabled && hw->mac.ops.setup_link)
7704 hw->mac.ops.setup_link(hw,
7705 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
7706 true);
7707
Auke Kok9a799d72007-09-15 14:07:45 -07007708 return 0;
7709
7710err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007711 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007712 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007713err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007714 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007715 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007716 iounmap(hw->hw_addr);
7717err_ioremap:
7718 free_netdev(netdev);
7719err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007720 pci_release_selected_regions(pdev,
7721 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007722err_pci_reg:
7723err_dma:
7724 pci_disable_device(pdev);
7725 return err;
7726}
7727
7728/**
7729 * ixgbe_remove - Device Removal Routine
7730 * @pdev: PCI device information struct
7731 *
7732 * ixgbe_remove is called by the PCI subsystem to alert the driver
7733 * that it should release a PCI device. The could be caused by a
7734 * Hot-Plug event, or because the driver is going to be removed from
7735 * memory.
7736 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007737static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007738{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007739 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7740 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007741
Catherine Sullivan00949162012-08-10 01:59:10 +00007742 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +00007743
Auke Kok9a799d72007-09-15 14:07:45 -07007744 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007745 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007746
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007747
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007748#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007749 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7750 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7751 dca_remove_requester(&pdev->dev);
7752 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7753 }
7754
7755#endif
Don Skidmore12109822012-05-04 06:07:08 +00007756#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007757 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007758#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007759
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007760 /* remove the added san mac */
7761 ixgbe_del_sanmac_netdev(netdev);
7762
Donald Skidmorec4900be2008-11-20 21:11:42 -08007763 if (netdev->reg_state == NETREG_REGISTERED)
7764 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007765
Greg Roseda36b642012-12-11 08:26:43 +00007766#ifdef CONFIG_PCI_IOV
7767 /*
7768 * Only disable SR-IOV on unload if the user specified the now
7769 * deprecated max_vfs module parameter.
7770 */
7771 if (max_vfs)
7772 ixgbe_disable_sriov(adapter);
7773#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00007774 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007775
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007776 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007777
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007778#ifdef CONFIG_DCB
7779 kfree(adapter->ixgbe_ieee_pfc);
7780 kfree(adapter->ixgbe_ieee_ets);
7781
7782#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007783 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007784 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007785 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007786
Emil Tantilov849c4542010-06-03 16:53:41 +00007787 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007788
Auke Kok9a799d72007-09-15 14:07:45 -07007789 free_netdev(netdev);
7790
Frans Pop19d5afd2009-10-02 10:04:12 -07007791 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007792
Auke Kok9a799d72007-09-15 14:07:45 -07007793 pci_disable_device(pdev);
7794}
7795
7796/**
7797 * ixgbe_io_error_detected - called when PCI error is detected
7798 * @pdev: Pointer to PCI device
7799 * @state: The current pci connection state
7800 *
7801 * This function is called after a PCI bus error affecting
7802 * this device has been detected.
7803 */
7804static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007805 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007806{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007807 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7808 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007809
Greg Rose83c61fa2011-09-07 05:59:35 +00007810#ifdef CONFIG_PCI_IOV
7811 struct pci_dev *bdev, *vfdev;
7812 u32 dw0, dw1, dw2, dw3;
7813 int vf, pos;
7814 u16 req_id, pf_func;
7815
7816 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7817 adapter->num_vfs == 0)
7818 goto skip_bad_vf_detection;
7819
7820 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007821 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007822 bdev = bdev->bus->self;
7823
7824 if (!bdev)
7825 goto skip_bad_vf_detection;
7826
7827 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7828 if (!pos)
7829 goto skip_bad_vf_detection;
7830
7831 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7832 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7833 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7834 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7835
7836 req_id = dw1 >> 16;
7837 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7838 if (!(req_id & 0x0080))
7839 goto skip_bad_vf_detection;
7840
7841 pf_func = req_id & 0x01;
7842 if ((pf_func & 1) == (pdev->devfn & 1)) {
7843 unsigned int device_id;
7844
7845 vf = (req_id & 0x7F) >> 1;
7846 e_dev_err("VF %d has caused a PCIe error\n", vf);
7847 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7848 "%8.8x\tdw3: %8.8x\n",
7849 dw0, dw1, dw2, dw3);
7850 switch (adapter->hw.mac.type) {
7851 case ixgbe_mac_82599EB:
7852 device_id = IXGBE_82599_VF_DEVICE_ID;
7853 break;
7854 case ixgbe_mac_X540:
7855 device_id = IXGBE_X540_VF_DEVICE_ID;
7856 break;
7857 default:
7858 device_id = 0;
7859 break;
7860 }
7861
7862 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007863 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007864 while (vfdev) {
7865 if (vfdev->devfn == (req_id & 0xFF))
7866 break;
Jon Mason36e90312012-07-19 21:02:09 +00007867 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007868 device_id, vfdev);
7869 }
7870 /*
7871 * There's a slim chance the VF could have been hot plugged,
7872 * so if it is no longer present we don't need to issue the
7873 * VFLR. Just clean up the AER in that case.
7874 */
7875 if (vfdev) {
7876 e_dev_err("Issuing VFLR to VF %d\n", vf);
7877 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
Greg Roseb4fafbe2012-12-13 01:14:06 +00007878 /* Free device reference count */
7879 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00007880 }
7881
7882 pci_cleanup_aer_uncorrect_error_status(pdev);
7883 }
7884
7885 /*
7886 * Even though the error may have occurred on the other port
7887 * we still need to increment the vf error reference count for
7888 * both ports because the I/O resume function will be called
7889 * for both of them.
7890 */
7891 adapter->vferr_refcount++;
7892
7893 return PCI_ERS_RESULT_RECOVERED;
7894
7895skip_bad_vf_detection:
7896#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007897 netif_device_detach(netdev);
7898
Breno Leitao3044b8d2009-05-06 10:44:26 +00007899 if (state == pci_channel_io_perm_failure)
7900 return PCI_ERS_RESULT_DISCONNECT;
7901
Auke Kok9a799d72007-09-15 14:07:45 -07007902 if (netif_running(netdev))
7903 ixgbe_down(adapter);
7904 pci_disable_device(pdev);
7905
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007906 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007907 return PCI_ERS_RESULT_NEED_RESET;
7908}
7909
7910/**
7911 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7912 * @pdev: Pointer to PCI device
7913 *
7914 * Restart the card from scratch, as if from a cold-boot.
7915 */
7916static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7917{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007918 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007919 pci_ers_result_t result;
7920 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007921
gouji-new9ce77662009-05-06 10:44:45 +00007922 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007923 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007924 result = PCI_ERS_RESULT_DISCONNECT;
7925 } else {
7926 pci_set_master(pdev);
7927 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007928 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007929
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007930 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007931
7932 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007933 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007934 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007935 }
Auke Kok9a799d72007-09-15 14:07:45 -07007936
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007937 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7938 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007939 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7940 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007941 /* non-fatal, continue */
7942 }
Auke Kok9a799d72007-09-15 14:07:45 -07007943
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007944 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007945}
7946
7947/**
7948 * ixgbe_io_resume - called when traffic can start flowing again.
7949 * @pdev: Pointer to PCI device
7950 *
7951 * This callback is called when the error recovery driver tells us that
7952 * its OK to resume normal operation.
7953 */
7954static void ixgbe_io_resume(struct pci_dev *pdev)
7955{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007956 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7957 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007958
Greg Rose83c61fa2011-09-07 05:59:35 +00007959#ifdef CONFIG_PCI_IOV
7960 if (adapter->vferr_refcount) {
7961 e_info(drv, "Resuming after VF err\n");
7962 adapter->vferr_refcount--;
7963 return;
7964 }
7965
7966#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007967 if (netif_running(netdev))
7968 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007969
7970 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007971}
7972
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007973static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007974 .error_detected = ixgbe_io_error_detected,
7975 .slot_reset = ixgbe_io_slot_reset,
7976 .resume = ixgbe_io_resume,
7977};
7978
7979static struct pci_driver ixgbe_driver = {
7980 .name = ixgbe_driver_name,
7981 .id_table = ixgbe_pci_tbl,
7982 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007983 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07007984#ifdef CONFIG_PM
7985 .suspend = ixgbe_suspend,
7986 .resume = ixgbe_resume,
7987#endif
7988 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00007989 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07007990 .err_handler = &ixgbe_err_handler
7991};
7992
7993/**
7994 * ixgbe_init_module - Driver Registration Routine
7995 *
7996 * ixgbe_init_module is the first routine called when the driver is
7997 * loaded. All it does is register with the PCI subsystem.
7998 **/
7999static int __init ixgbe_init_module(void)
8000{
8001 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008002 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008003 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008004
Catherine Sullivan00949162012-08-10 01:59:10 +00008005 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +00008006
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008007 ret = pci_register_driver(&ixgbe_driver);
8008 if (ret) {
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008009 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008010 return ret;
8011 }
8012
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008013#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008014 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008015#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008016
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +00008017 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008018}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008019
Auke Kok9a799d72007-09-15 14:07:45 -07008020module_init(ixgbe_init_module);
8021
8022/**
8023 * ixgbe_exit_module - Driver Exit Cleanup Routine
8024 *
8025 * ixgbe_exit_module is called just before the driver is removed
8026 * from memory.
8027 **/
8028static void __exit ixgbe_exit_module(void)
8029{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008030#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008031 dca_unregister_notify(&dca_notifier);
8032#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008033 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00008034
Catherine Sullivan00949162012-08-10 01:59:10 +00008035 ixgbe_dbg_exit();
Catherine Sullivan00949162012-08-10 01:59:10 +00008036
Eric Dumazet1a515022010-11-16 19:26:42 -08008037 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008038}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008039
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008040#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008041static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008042 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008043{
8044 int ret_val;
8045
8046 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008047 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008048
8049 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8050}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008051
Alexander Duyckb4533682009-03-31 21:32:42 +00008052#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008053
Auke Kok9a799d72007-09-15 14:07:45 -07008054module_exit(ixgbe_exit_module);
8055
8056/* ixgbe_main.c */