blob: 20a5af6d87d0e8747027964ba01a03bd7e3ca24c [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000047#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000049#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070050
51#include "ixgbe.h"
52#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000053#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000054#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070055
56char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070057static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000058 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000059#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000060char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000062#else
63static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
65#endif
Don Skidmore14a8d4bb2012-11-09 05:03:53 +000066#define DRV_VERSION "3.11.33-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 Skidmore94971822012-01-06 03:24:16 +000069 "Copyright (c) 1999-2012 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 Skidmorefe15e8e12010-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
Alexander Duyck70864002011-04-27 09:13:56 +0000152static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
153{
154 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
155 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
156 schedule_work(&adapter->service_task);
157}
158
159static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
160{
161 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
162
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000163 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000164 smp_mb__before_clear_bit();
165 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
166}
167
Taku Izumidcd79ae2010-04-27 14:39:53 +0000168struct ixgbe_reg_info {
169 u32 ofs;
170 char *name;
171};
172
173static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
174
175 /* General Registers */
176 {IXGBE_CTRL, "CTRL"},
177 {IXGBE_STATUS, "STATUS"},
178 {IXGBE_CTRL_EXT, "CTRL_EXT"},
179
180 /* Interrupt Registers */
181 {IXGBE_EICR, "EICR"},
182
183 /* RX Registers */
184 {IXGBE_SRRCTL(0), "SRRCTL"},
185 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
186 {IXGBE_RDLEN(0), "RDLEN"},
187 {IXGBE_RDH(0), "RDH"},
188 {IXGBE_RDT(0), "RDT"},
189 {IXGBE_RXDCTL(0), "RXDCTL"},
190 {IXGBE_RDBAL(0), "RDBAL"},
191 {IXGBE_RDBAH(0), "RDBAH"},
192
193 /* TX Registers */
194 {IXGBE_TDBAL(0), "TDBAL"},
195 {IXGBE_TDBAH(0), "TDBAH"},
196 {IXGBE_TDLEN(0), "TDLEN"},
197 {IXGBE_TDH(0), "TDH"},
198 {IXGBE_TDT(0), "TDT"},
199 {IXGBE_TXDCTL(0), "TXDCTL"},
200
201 /* List Terminator */
202 {}
203};
204
205
206/*
207 * ixgbe_regdump - register printout routine
208 */
209static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
210{
211 int i = 0, j = 0;
212 char rname[16];
213 u32 regs[64];
214
215 switch (reginfo->ofs) {
216 case IXGBE_SRRCTL(0):
217 for (i = 0; i < 64; i++)
218 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
219 break;
220 case IXGBE_DCA_RXCTRL(0):
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
223 break;
224 case IXGBE_RDLEN(0):
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
227 break;
228 case IXGBE_RDH(0):
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
231 break;
232 case IXGBE_RDT(0):
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
235 break;
236 case IXGBE_RXDCTL(0):
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
239 break;
240 case IXGBE_RDBAL(0):
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
243 break;
244 case IXGBE_RDBAH(0):
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
247 break;
248 case IXGBE_TDBAL(0):
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
251 break;
252 case IXGBE_TDBAH(0):
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
255 break;
256 case IXGBE_TDLEN(0):
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
259 break;
260 case IXGBE_TDH(0):
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
263 break;
264 case IXGBE_TDT(0):
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
267 break;
268 case IXGBE_TXDCTL(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
271 break;
272 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000273 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000274 IXGBE_READ_REG(hw, reginfo->ofs));
275 return;
276 }
277
278 for (i = 0; i < 8; i++) {
279 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000280 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000281 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000282 pr_cont(" %08x", regs[i*8+j]);
283 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000284 }
285
286}
287
288/*
289 * ixgbe_dump - Print registers, tx-rings and rx-rings
290 */
291static void ixgbe_dump(struct ixgbe_adapter *adapter)
292{
293 struct net_device *netdev = adapter->netdev;
294 struct ixgbe_hw *hw = &adapter->hw;
295 struct ixgbe_reg_info *reginfo;
296 int n = 0;
297 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000298 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000299 union ixgbe_adv_tx_desc *tx_desc;
300 struct my_u0 { u64 a; u64 b; } *u0;
301 struct ixgbe_ring *rx_ring;
302 union ixgbe_adv_rx_desc *rx_desc;
303 struct ixgbe_rx_buffer *rx_buffer_info;
304 u32 staterr;
305 int i = 0;
306
307 if (!netif_msg_hw(adapter))
308 return;
309
310 /* Print netdevice Info */
311 if (netdev) {
312 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000313 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000315 pr_info("%-15s %016lX %016lX %016lX\n",
316 netdev->name,
317 netdev->state,
318 netdev->trans_start,
319 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000320 }
321
322 /* Print Registers */
323 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000324 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000325 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
326 reginfo->name; reginfo++) {
327 ixgbe_regdump(hw, reginfo);
328 }
329
330 /* Print TX Ring Summary */
331 if (!netdev || !netif_running(netdev))
332 goto exit;
333
334 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000335 pr_info(" %s %s %s %s\n",
336 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
337 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000338 for (n = 0; n < adapter->num_tx_queues; n++) {
339 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000340 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000341 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000342 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000343 (u64)dma_unmap_addr(tx_buffer, dma),
344 dma_unmap_len(tx_buffer, len),
345 tx_buffer->next_to_watch,
346 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000347 }
348
349 /* Print TX Rings */
350 if (!netif_msg_tx_done(adapter))
351 goto rx_ring_summary;
352
353 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
354
355 /* Transmit Descriptor Formats
356 *
Josh Hay39ac8682012-09-26 05:59:36 +0000357 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000358 * +--------------------------------------------------------------+
359 * 0 | Buffer Address [63:0] |
360 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000361 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000362 * +--------------------------------------------------------------+
363 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000364 *
365 * 82598 Advanced Transmit Descriptor (Write-Back Format)
366 * +--------------------------------------------------------------+
367 * 0 | RSV [63:0] |
368 * +--------------------------------------------------------------+
369 * 8 | RSV | STA | NXTSEQ |
370 * +--------------------------------------------------------------+
371 * 63 36 35 32 31 0
372 *
373 * 82599+ Advanced Transmit Descriptor
374 * +--------------------------------------------------------------+
375 * 0 | Buffer Address [63:0] |
376 * +--------------------------------------------------------------+
377 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
378 * +--------------------------------------------------------------+
379 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
380 *
381 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
382 * +--------------------------------------------------------------+
383 * 0 | RSV [63:0] |
384 * +--------------------------------------------------------------+
385 * 8 | RSV | STA | RSV |
386 * +--------------------------------------------------------------+
387 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 */
389
390 for (n = 0; n < adapter->num_tx_queues; n++) {
391 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000392 pr_info("------------------------------------\n");
393 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
394 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000395 pr_info("%s%s %s %s %s %s\n",
396 "T [desc] [address 63:0 ] ",
397 "[PlPOIdStDDt Ln] [bi->dma ] ",
398 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000399
400 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000401 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000402 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000403 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000404 if (dma_unmap_len(tx_buffer, len) > 0) {
405 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
406 i,
407 le64_to_cpu(u0->a),
408 le64_to_cpu(u0->b),
409 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000410 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000411 tx_buffer->next_to_watch,
412 (u64)tx_buffer->time_stamp,
413 tx_buffer->skb);
414 if (i == tx_ring->next_to_use &&
415 i == tx_ring->next_to_clean)
416 pr_cont(" NTC/U\n");
417 else if (i == tx_ring->next_to_use)
418 pr_cont(" NTU\n");
419 else if (i == tx_ring->next_to_clean)
420 pr_cont(" NTC\n");
421 else
422 pr_cont("\n");
423
424 if (netif_msg_pktdata(adapter) &&
425 tx_buffer->skb)
426 print_hex_dump(KERN_INFO, "",
427 DUMP_PREFIX_ADDRESS, 16, 1,
428 tx_buffer->skb->data,
429 dma_unmap_len(tx_buffer, len),
430 true);
431 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000432 }
433 }
434
435 /* Print RX Rings Summary */
436rx_ring_summary:
437 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000439 for (n = 0; n < adapter->num_rx_queues; n++) {
440 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000441 pr_info("%5d %5X %5X\n",
442 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000443 }
444
445 /* Print RX Rings */
446 if (!netif_msg_rx_status(adapter))
447 goto exit;
448
449 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
450
Josh Hay39ac8682012-09-26 05:59:36 +0000451 /* Receive Descriptor Formats
452 *
453 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000454 * 63 1 0
455 * +-----------------------------------------------------+
456 * 0 | Packet Buffer Address [63:1] |A0/NSE|
457 * +----------------------------------------------+------+
458 * 8 | Header Buffer Address [63:1] | DD |
459 * +-----------------------------------------------------+
460 *
461 *
Josh Hay39ac8682012-09-26 05:59:36 +0000462 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000463 *
464 * 63 48 47 32 31 30 21 20 16 15 4 3 0
465 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000466 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
467 * | Packet | IP | | | | Type | Type |
468 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000469 * +------------------------------------------------------+
470 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
471 * +------------------------------------------------------+
472 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000473 *
474 * 82599+ Advanced Receive Descriptor (Read) Format
475 * 63 1 0
476 * +-----------------------------------------------------+
477 * 0 | Packet Buffer Address [63:1] |A0/NSE|
478 * +----------------------------------------------+------+
479 * 8 | Header Buffer Address [63:1] | DD |
480 * +-----------------------------------------------------+
481 *
482 *
483 * 82599+ Advanced Receive Descriptor (Write-Back) Format
484 *
485 * 63 48 47 32 31 30 21 20 17 16 4 3 0
486 * +------------------------------------------------------+
487 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
488 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
489 * |/ Flow Dir Flt ID | | | | | |
490 * +------------------------------------------------------+
491 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
492 * +------------------------------------------------------+
493 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000494 */
Josh Hay39ac8682012-09-26 05:59:36 +0000495
Taku Izumidcd79ae2010-04-27 14:39:53 +0000496 for (n = 0; n < adapter->num_rx_queues; n++) {
497 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000498 pr_info("------------------------------------\n");
499 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
500 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000501 pr_info("%s%s%s",
502 "R [desc] [ PktBuf A0] ",
503 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000504 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000505 pr_info("%s%s%s",
506 "RWB[desc] [PcsmIpSHl PtRs] ",
507 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000508 "<-- Adv Rx Write-Back format\n");
509
510 for (i = 0; i < rx_ring->count; i++) {
511 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000512 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000513 u0 = (struct my_u0 *)rx_desc;
514 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
515 if (staterr & IXGBE_RXD_STAT_DD) {
516 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000517 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000518 "%016llX ---------------- %p", i,
519 le64_to_cpu(u0->a),
520 le64_to_cpu(u0->b),
521 rx_buffer_info->skb);
522 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000523 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000524 "%016llX %016llX %p", i,
525 le64_to_cpu(u0->a),
526 le64_to_cpu(u0->b),
527 (u64)rx_buffer_info->dma,
528 rx_buffer_info->skb);
529
Emil Tantilov9c50c032012-07-26 01:21:24 +0000530 if (netif_msg_pktdata(adapter) &&
531 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000532 print_hex_dump(KERN_INFO, "",
533 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000534 page_address(rx_buffer_info->page) +
535 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000536 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000537 }
538 }
539
540 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000542 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000543 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000544 else
Joe Perchesc7689572010-09-07 21:35:17 +0000545 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000546
547 }
548 }
549
550exit:
551 return;
552}
553
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800554static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
555{
556 u32 ctrl_ext;
557
558 /* Let firmware take over control of h/w */
559 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
560 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000561 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800562}
563
564static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
565{
566 u32 ctrl_ext;
567
568 /* Let firmware know the driver has taken over */
569 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800572}
Auke Kok9a799d72007-09-15 14:07:45 -0700573
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000574/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000575 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
576 * @adapter: pointer to adapter struct
577 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
578 * @queue: queue to map the corresponding interrupt to
579 * @msix_vector: the vector to map to the corresponding queue
580 *
581 */
582static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000583 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700584{
585 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000586 struct ixgbe_hw *hw = &adapter->hw;
587 switch (hw->mac.type) {
588 case ixgbe_mac_82598EB:
589 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
590 if (direction == -1)
591 direction = 0;
592 index = (((direction * 64) + queue) >> 2) & 0x1F;
593 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
594 ivar &= ~(0xFF << (8 * (queue & 0x3)));
595 ivar |= (msix_vector << (8 * (queue & 0x3)));
596 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
597 break;
598 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800599 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000600 if (direction == -1) {
601 /* other causes */
602 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
603 index = ((queue & 1) * 8);
604 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
605 ivar &= ~(0xFF << index);
606 ivar |= (msix_vector << index);
607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
608 break;
609 } else {
610 /* tx or rx causes */
611 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
612 index = ((16 * (queue & 1)) + (8 * direction));
613 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
614 ivar &= ~(0xFF << index);
615 ivar |= (msix_vector << index);
616 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
617 break;
618 }
619 default:
620 break;
621 }
Auke Kok9a799d72007-09-15 14:07:45 -0700622}
623
Alexander Duyckfe49f042009-06-04 16:00:09 +0000624static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000625 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000626{
627 u32 mask;
628
Alexander Duyckbd508172010-11-16 19:27:03 -0800629 switch (adapter->hw.mac.type) {
630 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000631 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
632 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800633 break;
634 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800635 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000636 mask = (qmask & 0xFFFFFFFF);
637 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
638 mask = (qmask >> 32);
639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800640 break;
641 default:
642 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000643 }
644}
645
Alexander Duyck729739b2012-02-08 07:51:06 +0000646void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
647 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000648{
Alexander Duyck729739b2012-02-08 07:51:06 +0000649 if (tx_buffer->skb) {
650 dev_kfree_skb_any(tx_buffer->skb);
651 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000652 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000653 dma_unmap_addr(tx_buffer, dma),
654 dma_unmap_len(tx_buffer, len),
655 DMA_TO_DEVICE);
656 } else if (dma_unmap_len(tx_buffer, len)) {
657 dma_unmap_page(ring->dev,
658 dma_unmap_addr(tx_buffer, dma),
659 dma_unmap_len(tx_buffer, len),
660 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000661 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000662 tx_buffer->next_to_watch = NULL;
663 tx_buffer->skb = NULL;
664 dma_unmap_len_set(tx_buffer, len, 0);
665 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700666}
667
Alexander Duyck943561d2012-05-09 22:14:44 -0700668static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
669{
670 struct ixgbe_hw *hw = &adapter->hw;
671 struct ixgbe_hw_stats *hwstats = &adapter->stats;
672 int i;
673 u32 data;
674
675 if ((hw->fc.current_mode != ixgbe_fc_full) &&
676 (hw->fc.current_mode != ixgbe_fc_rx_pause))
677 return;
678
679 switch (hw->mac.type) {
680 case ixgbe_mac_82598EB:
681 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
682 break;
683 default:
684 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
685 }
686 hwstats->lxoffrxc += data;
687
688 /* refill credits (no tx hang) if we received xoff */
689 if (!data)
690 return;
691
692 for (i = 0; i < adapter->num_tx_queues; i++)
693 clear_bit(__IXGBE_HANG_CHECK_ARMED,
694 &adapter->tx_ring[i]->state);
695}
696
John Fastabendc84d3242010-11-16 19:27:12 -0800697static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700698{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700699 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800700 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800701 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000702 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800703 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700704 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700705
Alexander Duyck943561d2012-05-09 22:14:44 -0700706 if (adapter->ixgbe_ieee_pfc)
707 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800708
Alexander Duyck943561d2012-05-09 22:14:44 -0700709 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
710 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800711 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700712 }
John Fastabendc84d3242010-11-16 19:27:12 -0800713
714 /* update stats for each tc, only valid with PFC enabled */
715 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000716 u32 pxoffrxc;
717
John Fastabendc84d3242010-11-16 19:27:12 -0800718 switch (hw->mac.type) {
719 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000720 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800721 break;
722 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000723 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800724 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000725 hwstats->pxoffrxc[i] += pxoffrxc;
726 /* Get the TC for given UP */
727 tc = netdev_get_prio_tc_map(adapter->netdev, i);
728 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700729 }
730
John Fastabendc84d3242010-11-16 19:27:12 -0800731 /* disarm tx queues that have received xoff frames */
732 for (i = 0; i < adapter->num_tx_queues; i++) {
733 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800734
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000735 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800736 if (xoff[tc])
737 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
738 }
739}
740
741static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
742{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000743 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800744}
745
746static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
747{
748 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
749 struct ixgbe_hw *hw = &adapter->hw;
750
751 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
752 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
753
754 if (head != tail)
755 return (head < tail) ?
756 tail - head : (tail + ring->count - head);
757
758 return 0;
759}
760
761static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
762{
763 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
764 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
765 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
766 bool ret = false;
767
768 clear_check_for_tx_hang(tx_ring);
769
770 /*
771 * Check for a hung queue, but be thorough. This verifies
772 * that a transmit has been completed since the previous
773 * check AND there is at least one packet pending. The
774 * ARMED bit is set to indicate a potential hang. The
775 * bit is cleared if a pause frame is received to remove
776 * false hang detection due to PFC or 802.3x frames. By
777 * requiring this to fail twice we avoid races with
778 * pfc clearing the ARMED bit and conditions where we
779 * run the check_tx_hang logic with a transmit completion
780 * pending but without time to complete it yet.
781 */
782 if ((tx_done_old == tx_done) && tx_pending) {
783 /* make sure it is true for two checks in a row */
784 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
785 &tx_ring->state);
786 } else {
787 /* update completed stats and continue */
788 tx_ring->tx_stats.tx_done_old = tx_done;
789 /* reset the countdown */
790 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
791 }
792
793 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700794}
795
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000796/**
797 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
798 * @adapter: driver private struct
799 **/
800static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
801{
802
803 /* Do the reset outside of interrupt context */
804 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
805 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
806 ixgbe_service_event_schedule(adapter);
807 }
808}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700809
Auke Kok9a799d72007-09-15 14:07:45 -0700810/**
811 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000812 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700813 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700814 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000815static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000816 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700817{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000818 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000819 struct ixgbe_tx_buffer *tx_buffer;
820 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700821 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000822 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000823 unsigned int i = tx_ring->next_to_clean;
824
825 if (test_bit(__IXGBE_DOWN, &adapter->state))
826 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700827
Alexander Duyckd3d00232011-07-15 02:31:25 +0000828 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000829 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000830 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800831
Alexander Duyck729739b2012-02-08 07:51:06 +0000832 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000833 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700834
Alexander Duyckd3d00232011-07-15 02:31:25 +0000835 /* if next_to_watch is not set then there is no work pending */
836 if (!eop_desc)
837 break;
838
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000839 /* prevent any other reads prior to eop_desc */
840 rmb();
841
Alexander Duyckd3d00232011-07-15 02:31:25 +0000842 /* if DD is not set pending work has not been completed */
843 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
844 break;
845
Alexander Duyckd3d00232011-07-15 02:31:25 +0000846 /* clear next_to_watch to prevent false hangs */
847 tx_buffer->next_to_watch = NULL;
848
Alexander Duyck091a6242012-02-08 07:51:01 +0000849 /* update the statistics for this packet */
850 total_bytes += tx_buffer->bytecount;
851 total_packets += tx_buffer->gso_segs;
852
Jacob Keller0ede4a62012-05-22 06:08:32 +0000853 if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP))
854 ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb);
Jacob Keller0ede4a62012-05-22 06:08:32 +0000855
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000856 /* free the skb */
857 dev_kfree_skb_any(tx_buffer->skb);
858
Alexander Duyck729739b2012-02-08 07:51:06 +0000859 /* unmap skb header data */
860 dma_unmap_single(tx_ring->dev,
861 dma_unmap_addr(tx_buffer, dma),
862 dma_unmap_len(tx_buffer, len),
863 DMA_TO_DEVICE);
864
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000865 /* clear tx_buffer data */
866 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000867 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000868
Alexander Duyck729739b2012-02-08 07:51:06 +0000869 /* unmap remaining buffers */
870 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000871 tx_buffer++;
872 tx_desc++;
873 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000874 if (unlikely(!i)) {
875 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000876 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000877 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000878 }
879
Alexander Duyck729739b2012-02-08 07:51:06 +0000880 /* unmap any remaining paged data */
881 if (dma_unmap_len(tx_buffer, len)) {
882 dma_unmap_page(tx_ring->dev,
883 dma_unmap_addr(tx_buffer, dma),
884 dma_unmap_len(tx_buffer, len),
885 DMA_TO_DEVICE);
886 dma_unmap_len_set(tx_buffer, len, 0);
887 }
888 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800889
Alexander Duyck729739b2012-02-08 07:51:06 +0000890 /* move us one more past the eop_desc for start of next pkt */
891 tx_buffer++;
892 tx_desc++;
893 i++;
894 if (unlikely(!i)) {
895 i -= tx_ring->count;
896 tx_buffer = tx_ring->tx_buffer_info;
897 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
898 }
899
900 /* issue prefetch for next Tx descriptor */
901 prefetch(tx_desc);
902
903 /* update budget accounting */
904 budget--;
905 } while (likely(budget));
906
907 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700908 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000909 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800910 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000911 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000912 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000913 q_vector->tx.total_bytes += total_bytes;
914 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800915
John Fastabendc84d3242010-11-16 19:27:12 -0800916 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800917 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800918 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800919 e_err(drv, "Detected Tx Unit Hang\n"
920 " Tx Queue <%d>\n"
921 " TDH, TDT <%x>, <%x>\n"
922 " next_to_use <%x>\n"
923 " next_to_clean <%x>\n"
924 "tx_buffer_info[next_to_clean]\n"
925 " time_stamp <%lx>\n"
926 " jiffies <%lx>\n",
927 tx_ring->queue_index,
928 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
929 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000930 tx_ring->next_to_use, i,
931 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800932
933 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
934
935 e_info(probe,
936 "tx hang %d detected on queue %d, resetting adapter\n",
937 adapter->tx_timeout_count + 1, tx_ring->queue_index);
938
939 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000940 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800941
942 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000943 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800944 }
Auke Kok9a799d72007-09-15 14:07:45 -0700945
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000946 netdev_tx_completed_queue(txring_txq(tx_ring),
947 total_packets, total_bytes);
948
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800949#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000950 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000951 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800952 /* Make sure that anybody stopping the queue after this
953 * sees the new next_to_clean.
954 */
955 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000956 if (__netif_subqueue_stopped(tx_ring->netdev,
957 tx_ring->queue_index)
958 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
959 netif_wake_subqueue(tx_ring->netdev,
960 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800961 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800962 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800963 }
Auke Kok9a799d72007-09-15 14:07:45 -0700964
Alexander Duyck59224552011-08-31 00:01:06 +0000965 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700966}
967
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400968#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800969static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800970 struct ixgbe_ring *tx_ring,
971 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800972{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000973 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000974 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
975 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800976
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800977 switch (hw->mac.type) {
978 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000979 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800980 break;
981 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800982 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000983 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
984 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
985 break;
986 default:
987 /* for unknown hardware do not write register */
988 return;
989 }
990
991 /*
992 * We can enable relaxed ordering for reads, but not writes when
993 * DCA is enabled. This is due to a known issue in some chipsets
994 * which will cause the DCA tag to be cleared.
995 */
996 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
997 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
998 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
999
1000 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1001}
1002
1003static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1004 struct ixgbe_ring *rx_ring,
1005 int cpu)
1006{
1007 struct ixgbe_hw *hw = &adapter->hw;
1008 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1009 u8 reg_idx = rx_ring->reg_idx;
1010
1011
1012 switch (hw->mac.type) {
1013 case ixgbe_mac_82599EB:
1014 case ixgbe_mac_X540:
1015 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001016 break;
1017 default:
1018 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001019 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001020
1021 /*
1022 * We can enable relaxed ordering for reads, but not writes when
1023 * DCA is enabled. This is due to a known issue in some chipsets
1024 * which will cause the DCA tag to be cleared.
1025 */
1026 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001027 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1028
1029 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001030}
1031
1032static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1033{
1034 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001035 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001036 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001037
1038 if (q_vector->cpu == cpu)
1039 goto out_no_update;
1040
Alexander Duycka5579282012-02-08 07:50:04 +00001041 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001042 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001043
Alexander Duycka5579282012-02-08 07:50:04 +00001044 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001045 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001046
1047 q_vector->cpu = cpu;
1048out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001049 put_cpu();
1050}
1051
1052static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1053{
1054 int i;
1055
1056 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1057 return;
1058
Alexander Duycke35ec122009-05-21 13:07:12 +00001059 /* always use CB2 mode, difference is masked in the CB driver */
1060 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1061
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001062 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001063 adapter->q_vector[i]->cpu = -1;
1064 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001065 }
1066}
1067
1068static int __ixgbe_notify_dca(struct device *dev, void *data)
1069{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001070 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001071 unsigned long event = *(unsigned long *)data;
1072
Don Skidmore2a72c312011-07-20 02:27:05 +00001073 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001074 return 0;
1075
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001076 switch (event) {
1077 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001078 /* if we're already enabled, don't do it again */
1079 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1080 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001081 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001082 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001083 ixgbe_setup_dca(adapter);
1084 break;
1085 }
1086 /* Fall Through since DCA is disabled. */
1087 case DCA_PROVIDER_REMOVE:
1088 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1089 dca_remove_requester(dev);
1090 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1091 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1092 }
1093 break;
1094 }
1095
Denis V. Lunev652f0932008-03-27 14:39:17 +03001096 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001097}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001098
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001099#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001100static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1101 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001102 struct sk_buff *skb)
1103{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001104 if (ring->netdev->features & NETIF_F_RXHASH)
1105 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001106}
1107
Alexander Duyckf8003262012-03-03 02:35:52 +00001108#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001109/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001110 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001111 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001112 * @rx_desc: advanced rx descriptor
1113 *
1114 * Returns : true if it is FCoE pkt
1115 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001116static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001117 union ixgbe_adv_rx_desc *rx_desc)
1118{
1119 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1120
Alexander Duyck57efd442012-06-25 21:54:46 +00001121 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001122 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1123 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1124 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1125}
1126
Alexander Duyckf8003262012-03-03 02:35:52 +00001127#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001128/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001129 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001130 * @ring: structure containing ring specific data
1131 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001132 * @skb: skb currently being received and modified
1133 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001134static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001135 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001136 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001137{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001138 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001139
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001140 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001141 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001142 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001143
1144 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001145 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1146 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001147 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001148 return;
1149 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001150
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001151 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001152 return;
1153
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001154 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001155 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001156
1157 /*
1158 * 82599 errata, UDP frames with a 0 checksum can be marked as
1159 * checksum errors.
1160 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001161 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1162 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001163 return;
1164
Alexander Duyck8a0da212012-01-31 02:59:49 +00001165 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001166 return;
1167 }
1168
Auke Kok9a799d72007-09-15 14:07:45 -07001169 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001170 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001171}
1172
Alexander Duyck84ea2592010-11-16 19:26:49 -08001173static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001174{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001175 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001176
1177 /* update next to alloc since we have filled the ring */
1178 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001179 /*
1180 * Force memory writes to complete before letting h/w
1181 * know there are new descriptors to fetch. (Only
1182 * applicable for weak-ordered memory model archs,
1183 * such as IA-64).
1184 */
1185 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001186 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001187}
1188
Alexander Duyckf990b792012-01-31 02:59:34 +00001189static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1190 struct ixgbe_rx_buffer *bi)
1191{
1192 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001193 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001194
Alexander Duyckf8003262012-03-03 02:35:52 +00001195 /* since we are recycling buffers we should seldom need to alloc */
1196 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001197 return true;
1198
Alexander Duyckf8003262012-03-03 02:35:52 +00001199 /* alloc new page for storage */
1200 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001201 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1202 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001203 if (unlikely(!page)) {
1204 rx_ring->rx_stats.alloc_rx_page_failed++;
1205 return false;
1206 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001207 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001208 }
1209
Alexander Duyckf8003262012-03-03 02:35:52 +00001210 /* map page for use */
1211 dma = dma_map_page(rx_ring->dev, page, 0,
1212 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001213
Alexander Duyckf8003262012-03-03 02:35:52 +00001214 /*
1215 * if mapping failed free memory back to system since
1216 * there isn't much point in holding memory we can't use
1217 */
1218 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001219 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001220 bi->page = NULL;
1221
Alexander Duyckf990b792012-01-31 02:59:34 +00001222 rx_ring->rx_stats.alloc_rx_page_failed++;
1223 return false;
1224 }
1225
Alexander Duyckf8003262012-03-03 02:35:52 +00001226 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001227 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001228
Alexander Duyckf990b792012-01-31 02:59:34 +00001229 return true;
1230}
1231
Auke Kok9a799d72007-09-15 14:07:45 -07001232/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001233 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001234 * @rx_ring: ring to place buffers on
1235 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001236 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001237void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001238{
Auke Kok9a799d72007-09-15 14:07:45 -07001239 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001240 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001241 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001242
Alexander Duyckf8003262012-03-03 02:35:52 +00001243 /* nothing to do */
1244 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001245 return;
1246
Alexander Duycke4f74022012-01-31 02:59:44 +00001247 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001248 bi = &rx_ring->rx_buffer_info[i];
1249 i -= rx_ring->count;
1250
Alexander Duyckf8003262012-03-03 02:35:52 +00001251 do {
1252 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001253 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001254
Alexander Duyckf8003262012-03-03 02:35:52 +00001255 /*
1256 * Refresh the desc even if buffer_addrs didn't change
1257 * because each write-back erases this info.
1258 */
1259 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001260
Alexander Duyckf990b792012-01-31 02:59:34 +00001261 rx_desc++;
1262 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001263 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001264 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001265 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001266 bi = rx_ring->rx_buffer_info;
1267 i -= rx_ring->count;
1268 }
1269
1270 /* clear the hdr_addr for the next_to_use descriptor */
1271 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001272
1273 cleaned_count--;
1274 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001275
Alexander Duyckf990b792012-01-31 02:59:34 +00001276 i += rx_ring->count;
1277
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001278 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001279 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001280}
1281
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001282/**
1283 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1284 * @data: pointer to the start of the headers
1285 * @max_len: total length of section to find headers in
1286 *
1287 * This function is meant to determine the length of headers that will
1288 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1289 * motivation of doing this is to only perform one pull for IPv4 TCP
1290 * packets so that we can do basic things like calculating the gso_size
1291 * based on the average data per packet.
1292 **/
1293static unsigned int ixgbe_get_headlen(unsigned char *data,
1294 unsigned int max_len)
1295{
1296 union {
1297 unsigned char *network;
1298 /* l2 headers */
1299 struct ethhdr *eth;
1300 struct vlan_hdr *vlan;
1301 /* l3 headers */
1302 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001303 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001304 } hdr;
1305 __be16 protocol;
1306 u8 nexthdr = 0; /* default to not TCP */
1307 u8 hlen;
1308
1309 /* this should never happen, but better safe than sorry */
1310 if (max_len < ETH_HLEN)
1311 return max_len;
1312
1313 /* initialize network frame pointer */
1314 hdr.network = data;
1315
1316 /* set first protocol and move network header forward */
1317 protocol = hdr.eth->h_proto;
1318 hdr.network += ETH_HLEN;
1319
1320 /* handle any vlan tag if present */
1321 if (protocol == __constant_htons(ETH_P_8021Q)) {
1322 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1323 return max_len;
1324
1325 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1326 hdr.network += VLAN_HLEN;
1327 }
1328
1329 /* handle L3 protocols */
1330 if (protocol == __constant_htons(ETH_P_IP)) {
1331 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1332 return max_len;
1333
1334 /* access ihl as a u8 to avoid unaligned access on ia64 */
1335 hlen = (hdr.network[0] & 0x0F) << 2;
1336
1337 /* verify hlen meets minimum size requirements */
1338 if (hlen < sizeof(struct iphdr))
1339 return hdr.network - data;
1340
Alexander Duycked83da12012-11-13 01:13:33 +00001341 /* record next protocol if header is present */
1342 if (!hdr.ipv4->frag_off)
1343 nexthdr = hdr.ipv4->protocol;
Alexander Duycka048b402012-05-24 08:26:29 +00001344 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1345 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1346 return max_len;
1347
1348 /* record next protocol */
1349 nexthdr = hdr.ipv6->nexthdr;
Alexander Duycked83da12012-11-13 01:13:33 +00001350 hlen = sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001351#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001352 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1353 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1354 return max_len;
Alexander Duycked83da12012-11-13 01:13:33 +00001355 hlen = FCOE_HEADER_LEN;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001356#endif
1357 } else {
1358 return hdr.network - data;
1359 }
1360
Alexander Duycked83da12012-11-13 01:13:33 +00001361 /* relocate pointer to start of L4 header */
1362 hdr.network += hlen;
1363
Alexander Duycka048b402012-05-24 08:26:29 +00001364 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001365 if (nexthdr == IPPROTO_TCP) {
1366 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1367 return max_len;
1368
1369 /* access doff as a u8 to avoid unaligned access on ia64 */
1370 hlen = (hdr.network[12] & 0xF0) >> 2;
1371
1372 /* verify hlen meets minimum size requirements */
1373 if (hlen < sizeof(struct tcphdr))
1374 return hdr.network - data;
1375
1376 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001377 } else if (nexthdr == IPPROTO_UDP) {
1378 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1379 return max_len;
1380
1381 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001382 }
1383
1384 /*
1385 * If everything has gone correctly hdr.network should be the
1386 * data section of the packet and will be the end of the header.
1387 * If not then it probably represents the end of the last recognized
1388 * header.
1389 */
1390 if ((hdr.network - data) < max_len)
1391 return hdr.network - data;
1392 else
1393 return max_len;
1394}
1395
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001396static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1397 struct sk_buff *skb)
1398{
Alexander Duyckf8003262012-03-03 02:35:52 +00001399 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001400
1401 /* set gso_size to avoid messing up TCP MSS */
1402 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1403 IXGBE_CB(skb)->append_cnt);
1404}
1405
1406static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1407 struct sk_buff *skb)
1408{
1409 /* if append_cnt is 0 then frame is not RSC */
1410 if (!IXGBE_CB(skb)->append_cnt)
1411 return;
1412
1413 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1414 rx_ring->rx_stats.rsc_flush++;
1415
1416 ixgbe_set_rsc_gso_size(rx_ring, skb);
1417
1418 /* gso_size is computed using append_cnt so always clear it last */
1419 IXGBE_CB(skb)->append_cnt = 0;
1420}
1421
Alexander Duyck8a0da212012-01-31 02:59:49 +00001422/**
1423 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1424 * @rx_ring: rx descriptor ring packet is being transacted on
1425 * @rx_desc: pointer to the EOP Rx descriptor
1426 * @skb: pointer to current skb being populated
1427 *
1428 * This function checks the ring, descriptor, and packet information in
1429 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1430 * other fields within the skb.
1431 **/
1432static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1433 union ixgbe_adv_rx_desc *rx_desc,
1434 struct sk_buff *skb)
1435{
John Fastabend43e95f12012-05-15 06:12:17 +00001436 struct net_device *dev = rx_ring->netdev;
1437
Alexander Duyck8a0da212012-01-31 02:59:49 +00001438 ixgbe_update_rsc_stats(rx_ring, skb);
1439
1440 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1441
1442 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1443
Jacob Keller1d1a79b2012-05-22 06:18:08 +00001444 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001445
John Fastabend43e95f12012-05-15 06:12:17 +00001446 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1447 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001448 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1449 __vlan_hwaccel_put_tag(skb, vid);
1450 }
1451
1452 skb_record_rx_queue(skb, rx_ring->queue_index);
1453
John Fastabend43e95f12012-05-15 06:12:17 +00001454 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001455}
1456
1457static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1458 struct sk_buff *skb)
1459{
1460 struct ixgbe_adapter *adapter = q_vector->adapter;
1461
1462 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1463 napi_gro_receive(&q_vector->napi, skb);
1464 else
1465 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001466}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001467
Alexander Duyckf8003262012-03-03 02:35:52 +00001468/**
1469 * ixgbe_is_non_eop - process handling of non-EOP buffers
1470 * @rx_ring: Rx ring being processed
1471 * @rx_desc: Rx descriptor for current buffer
1472 * @skb: Current socket buffer containing buffer in progress
1473 *
1474 * This function updates next to clean. If the buffer is an EOP buffer
1475 * this function exits returning false, otherwise it will place the
1476 * sk_buff in the next buffer to be chained and return true indicating
1477 * that this is in fact a non-EOP buffer.
1478 **/
1479static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1480 union ixgbe_adv_rx_desc *rx_desc,
1481 struct sk_buff *skb)
1482{
1483 u32 ntc = rx_ring->next_to_clean + 1;
1484
1485 /* fetch, update, and store next to clean */
1486 ntc = (ntc < rx_ring->count) ? ntc : 0;
1487 rx_ring->next_to_clean = ntc;
1488
1489 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1490
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001491 /* update RSC append count if present */
1492 if (ring_is_rsc_enabled(rx_ring)) {
1493 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1494 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1495
1496 if (unlikely(rsc_enabled)) {
1497 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1498
1499 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1500 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1501
1502 /* update ntc based on RSC value */
1503 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1504 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1505 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1506 }
1507 }
1508
1509 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001510 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1511 return false;
1512
Alexander Duyckf8003262012-03-03 02:35:52 +00001513 /* place skb in next buffer to be received */
1514 rx_ring->rx_buffer_info[ntc].skb = skb;
1515 rx_ring->rx_stats.non_eop_descs++;
1516
1517 return true;
1518}
1519
1520/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001521 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1522 * @rx_ring: rx descriptor ring packet is being transacted on
1523 * @skb: pointer to current skb being adjusted
1524 *
1525 * This function is an ixgbe specific version of __pskb_pull_tail. The
1526 * main difference between this version and the original function is that
1527 * this function can make several assumptions about the state of things
1528 * that allow for significant optimizations versus the standard function.
1529 * As a result we can do things like drop a frag and maintain an accurate
1530 * truesize for the skb.
1531 */
1532static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1533 struct sk_buff *skb)
1534{
1535 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1536 unsigned char *va;
1537 unsigned int pull_len;
1538
1539 /*
1540 * it is valid to use page_address instead of kmap since we are
1541 * working with pages allocated out of the lomem pool per
1542 * alloc_page(GFP_ATOMIC)
1543 */
1544 va = skb_frag_address(frag);
1545
1546 /*
1547 * we need the header to contain the greater of either ETH_HLEN or
1548 * 60 bytes if the skb->len is less than 60 for skb_pad.
1549 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001550 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001551
1552 /* align pull length to size of long to optimize memcpy performance */
1553 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1554
1555 /* update all of the pointers */
1556 skb_frag_size_sub(frag, pull_len);
1557 frag->page_offset += pull_len;
1558 skb->data_len -= pull_len;
1559 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001560}
1561
1562/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001563 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1564 * @rx_ring: rx descriptor ring packet is being transacted on
1565 * @skb: pointer to current skb being updated
1566 *
1567 * This function provides a basic DMA sync up for the first fragment of an
1568 * skb. The reason for doing this is that the first fragment cannot be
1569 * unmapped until we have reached the end of packet descriptor for a buffer
1570 * chain.
1571 */
1572static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1573 struct sk_buff *skb)
1574{
1575 /* if the page was released unmap it, else just sync our portion */
1576 if (unlikely(IXGBE_CB(skb)->page_released)) {
1577 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1578 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1579 IXGBE_CB(skb)->page_released = false;
1580 } else {
1581 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1582
1583 dma_sync_single_range_for_cpu(rx_ring->dev,
1584 IXGBE_CB(skb)->dma,
1585 frag->page_offset,
1586 ixgbe_rx_bufsz(rx_ring),
1587 DMA_FROM_DEVICE);
1588 }
1589 IXGBE_CB(skb)->dma = 0;
1590}
1591
1592/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001593 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1594 * @rx_ring: rx descriptor ring packet is being transacted on
1595 * @rx_desc: pointer to the EOP Rx descriptor
1596 * @skb: pointer to current skb being fixed
1597 *
1598 * Check for corrupted packet headers caused by senders on the local L2
1599 * embedded NIC switch not setting up their Tx Descriptors right. These
1600 * should be very rare.
1601 *
1602 * Also address the case where we are pulling data in on pages only
1603 * and as such no data is present in the skb header.
1604 *
1605 * In addition if skb is not at least 60 bytes we need to pad it so that
1606 * it is large enough to qualify as a valid Ethernet frame.
1607 *
1608 * Returns true if an error was encountered and skb was freed.
1609 **/
1610static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1611 union ixgbe_adv_rx_desc *rx_desc,
1612 struct sk_buff *skb)
1613{
Alexander Duyckf8003262012-03-03 02:35:52 +00001614 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001615
1616 /* verify that the packet does not have any known errors */
1617 if (unlikely(ixgbe_test_staterr(rx_desc,
1618 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1619 !(netdev->features & NETIF_F_RXALL))) {
1620 dev_kfree_skb_any(skb);
1621 return true;
1622 }
1623
Alexander Duyck19861ce2012-07-20 08:08:33 +00001624 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001625 if (skb_is_nonlinear(skb))
1626 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001627
Alexander Duyck57efd442012-06-25 21:54:46 +00001628#ifdef IXGBE_FCOE
1629 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1630 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1631 return false;
1632
1633#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001634 /* if skb_pad returns an error the skb was freed */
1635 if (unlikely(skb->len < 60)) {
1636 int pad_len = 60 - skb->len;
1637
1638 if (skb_pad(skb, pad_len))
1639 return true;
1640 __skb_put(skb, pad_len);
1641 }
1642
1643 return false;
1644}
1645
1646/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001647 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1648 * @rx_ring: rx descriptor ring to store buffers on
1649 * @old_buff: donor buffer to have page reused
1650 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001651 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001652 **/
1653static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1654 struct ixgbe_rx_buffer *old_buff)
1655{
1656 struct ixgbe_rx_buffer *new_buff;
1657 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001658
1659 new_buff = &rx_ring->rx_buffer_info[nta];
1660
1661 /* update, and store next to alloc */
1662 nta++;
1663 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1664
1665 /* transfer page from old buffer to new buffer */
1666 new_buff->page = old_buff->page;
1667 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001668 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001669
1670 /* sync the buffer for use by the device */
1671 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001672 new_buff->page_offset,
1673 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001674 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001675}
1676
1677/**
1678 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1679 * @rx_ring: rx descriptor ring to transact packets on
1680 * @rx_buffer: buffer containing page to add
1681 * @rx_desc: descriptor containing length of buffer written by hardware
1682 * @skb: sk_buff to place the data into
1683 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001684 * This function will add the data contained in rx_buffer->page to the skb.
1685 * This is done either through a direct copy if the data in the buffer is
1686 * less than the skb header size, otherwise it will just attach the page as
1687 * a frag to the skb.
1688 *
1689 * The function will then update the page offset if necessary and return
1690 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001691 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001692static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001693 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001694 union ixgbe_adv_rx_desc *rx_desc,
1695 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001696{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001697 struct page *page = rx_buffer->page;
1698 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001699#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001700 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001701#else
1702 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1703 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1704 ixgbe_rx_bufsz(rx_ring);
1705#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001706
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001707 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1708 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1709
1710 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1711
1712 /* we can reuse buffer as-is, just make sure it is local */
1713 if (likely(page_to_nid(page) == numa_node_id()))
1714 return true;
1715
1716 /* this page cannot be reused so discard it */
1717 put_page(page);
1718 return false;
1719 }
1720
Alexander Duyck0549ae22012-07-20 08:08:18 +00001721 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1722 rx_buffer->page_offset, size, truesize);
1723
Alexander Duyck09816fb2012-07-20 08:08:23 +00001724 /* avoid re-using remote pages */
1725 if (unlikely(page_to_nid(page) != numa_node_id()))
1726 return false;
1727
1728#if (PAGE_SIZE < 8192)
1729 /* if we are only owner of page we can reuse it */
1730 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001731 return false;
1732
1733 /* flip page offset to other buffer */
1734 rx_buffer->page_offset ^= truesize;
1735
Alexander Duyck09816fb2012-07-20 08:08:23 +00001736 /*
1737 * since we are the only owner of the page and we need to
1738 * increment it, just set the value to 2 in order to avoid
1739 * an unecessary locked operation
1740 */
1741 atomic_set(&page->_count, 2);
1742#else
1743 /* move offset up to the next cache line */
1744 rx_buffer->page_offset += truesize;
1745
1746 if (rx_buffer->page_offset > last_offset)
1747 return false;
1748
Alexander Duyck0549ae22012-07-20 08:08:18 +00001749 /* bump ref count on page before it is given to the stack */
1750 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001751#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001752
1753 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001754}
1755
Alexander Duyck18806c92012-07-20 08:08:44 +00001756static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1757 union ixgbe_adv_rx_desc *rx_desc)
1758{
1759 struct ixgbe_rx_buffer *rx_buffer;
1760 struct sk_buff *skb;
1761 struct page *page;
1762
1763 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1764 page = rx_buffer->page;
1765 prefetchw(page);
1766
1767 skb = rx_buffer->skb;
1768
1769 if (likely(!skb)) {
1770 void *page_addr = page_address(page) +
1771 rx_buffer->page_offset;
1772
1773 /* prefetch first cache line of first page */
1774 prefetch(page_addr);
1775#if L1_CACHE_BYTES < 128
1776 prefetch(page_addr + L1_CACHE_BYTES);
1777#endif
1778
1779 /* allocate a skb to store the frags */
1780 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1781 IXGBE_RX_HDR_SIZE);
1782 if (unlikely(!skb)) {
1783 rx_ring->rx_stats.alloc_rx_buff_failed++;
1784 return NULL;
1785 }
1786
1787 /*
1788 * we will be copying header into skb->data in
1789 * pskb_may_pull so it is in our interest to prefetch
1790 * it now to avoid a possible cache miss
1791 */
1792 prefetchw(skb->data);
1793
1794 /*
1795 * Delay unmapping of the first packet. It carries the
1796 * header information, HW may still access the header
1797 * after the writeback. Only unmap it when EOP is
1798 * reached
1799 */
1800 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1801 goto dma_sync;
1802
1803 IXGBE_CB(skb)->dma = rx_buffer->dma;
1804 } else {
1805 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1806 ixgbe_dma_sync_frag(rx_ring, skb);
1807
1808dma_sync:
1809 /* we are reusing so sync this buffer for CPU use */
1810 dma_sync_single_range_for_cpu(rx_ring->dev,
1811 rx_buffer->dma,
1812 rx_buffer->page_offset,
1813 ixgbe_rx_bufsz(rx_ring),
1814 DMA_FROM_DEVICE);
1815 }
1816
1817 /* pull page into skb */
1818 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1819 /* hand second half of page back to the ring */
1820 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1821 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1822 /* the page has been released from the ring */
1823 IXGBE_CB(skb)->page_released = true;
1824 } else {
1825 /* we are not reusing the buffer so unmap it */
1826 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1827 ixgbe_rx_pg_size(rx_ring),
1828 DMA_FROM_DEVICE);
1829 }
1830
1831 /* clear contents of buffer_info */
1832 rx_buffer->skb = NULL;
1833 rx_buffer->dma = 0;
1834 rx_buffer->page = NULL;
1835
1836 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001837}
1838
1839/**
1840 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1841 * @q_vector: structure containing interrupt and ring information
1842 * @rx_ring: rx descriptor ring to transact packets on
1843 * @budget: Total limit on number of packets to process
1844 *
1845 * This function provides a "bounce buffer" approach to Rx interrupt
1846 * processing. The advantage to this is that on systems that have
1847 * expensive overhead for IOMMU access this provides a means of avoiding
1848 * it by maintaining the mapping of the page to the syste.
1849 *
1850 * Returns true if all work is completed without reaching budget
1851 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001852static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001853 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001854 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001855{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001856 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001857#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001858 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001859 int ddp_bytes;
1860 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001861#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001862 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001863
Alexander Duyckf8003262012-03-03 02:35:52 +00001864 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001865 union ixgbe_adv_rx_desc *rx_desc;
1866 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001867
Alexander Duyckf8003262012-03-03 02:35:52 +00001868 /* return some buffers to hardware, one at a time is too slow */
1869 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1870 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1871 cleaned_count = 0;
1872 }
Auke Kok9a799d72007-09-15 14:07:45 -07001873
Alexander Duyck18806c92012-07-20 08:08:44 +00001874 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001875
Alexander Duyckf8003262012-03-03 02:35:52 +00001876 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1877 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001878
Alexander Duyckf8003262012-03-03 02:35:52 +00001879 /*
1880 * This memory barrier is needed to keep us from reading
1881 * any other fields out of the rx_desc until we know the
1882 * RXD_STAT_DD bit is set
1883 */
1884 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001885
Alexander Duyck18806c92012-07-20 08:08:44 +00001886 /* retrieve a buffer from the ring */
1887 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001888
Alexander Duyck18806c92012-07-20 08:08:44 +00001889 /* exit if we failed to retrieve a buffer */
1890 if (!skb)
1891 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001892
Auke Kok9a799d72007-09-15 14:07:45 -07001893 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001894
Alexander Duyckf8003262012-03-03 02:35:52 +00001895 /* place incomplete frames back on ring for completion */
1896 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1897 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001898
Alexander Duyckf8003262012-03-03 02:35:52 +00001899 /* verify the packet layout is correct */
1900 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1901 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001902
1903 /* probably a little skewed due to removing CRC */
1904 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001905
Alexander Duyck8a0da212012-01-31 02:59:49 +00001906 /* populate checksum, timestamp, VLAN, and protocol */
1907 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1908
Yi Zou332d4a72009-05-13 13:11:53 +00001909#ifdef IXGBE_FCOE
1910 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001911 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001912 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001913 /* include DDPed FCoE data */
1914 if (ddp_bytes > 0) {
1915 if (!mss) {
1916 mss = rx_ring->netdev->mtu -
1917 sizeof(struct fcoe_hdr) -
1918 sizeof(struct fc_frame_header) -
1919 sizeof(struct fcoe_crc_eof);
1920 if (mss > 512)
1921 mss &= ~511;
1922 }
1923 total_rx_bytes += ddp_bytes;
1924 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1925 mss);
1926 }
David S. Miller823dcd22011-08-20 10:39:12 -07001927 if (!ddp_bytes) {
1928 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001929 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001930 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001931 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001932
Yi Zou332d4a72009-05-13 13:11:53 +00001933#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001934 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001935
Alexander Duyckf8003262012-03-03 02:35:52 +00001936 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001937 total_rx_packets++;
1938 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001939
Alexander Duyckc267fc12010-11-16 19:27:00 -08001940 u64_stats_update_begin(&rx_ring->syncp);
1941 rx_ring->stats.packets += total_rx_packets;
1942 rx_ring->stats.bytes += total_rx_bytes;
1943 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001944 q_vector->rx.total_packets += total_rx_packets;
1945 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001946
Alexander Duyckf8003262012-03-03 02:35:52 +00001947 if (cleaned_count)
1948 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1949
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001950 return (total_rx_packets < budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001951}
1952
Auke Kok9a799d72007-09-15 14:07:45 -07001953/**
1954 * ixgbe_configure_msix - Configure MSI-X hardware
1955 * @adapter: board private structure
1956 *
1957 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1958 * interrupts.
1959 **/
1960static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1961{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001962 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001963 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001964 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001965
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001966 /* Populate MSIX to EITR Select */
1967 if (adapter->num_vfs > 32) {
1968 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1969 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1970 }
1971
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001972 /*
1973 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001974 * corresponding register.
1975 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001976 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001977 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001978 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001979
Alexander Duycka5579282012-02-08 07:50:04 +00001980 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001981 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001982
Alexander Duycka5579282012-02-08 07:50:04 +00001983 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001984 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001985
Alexander Duyckfe49f042009-06-04 16:00:09 +00001986 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001987 }
1988
Alexander Duyckbd508172010-11-16 19:27:03 -08001989 switch (adapter->hw.mac.type) {
1990 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001991 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001992 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001993 break;
1994 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001995 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001996 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001997 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001998 default:
1999 break;
2000 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002001 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002002
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002003 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002004 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002005 mask &= ~(IXGBE_EIMS_OTHER |
2006 IXGBE_EIMS_MAILBOX |
2007 IXGBE_EIMS_LSC);
2008
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002009 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002010}
2011
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002012enum latency_range {
2013 lowest_latency = 0,
2014 low_latency = 1,
2015 bulk_latency = 2,
2016 latency_invalid = 255
2017};
2018
2019/**
2020 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002021 * @q_vector: structure containing interrupt and ring information
2022 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002023 *
2024 * Stores a new ITR value based on packets and byte
2025 * counts during the last interrupt. The advantage of per interrupt
2026 * computation is faster updates and more accurate ITR for the current
2027 * traffic pattern. Constants in this function were computed
2028 * based on theoretical maximum wire speed and thresholds were set based
2029 * on testing data as well as attempting to minimize response time
2030 * while increasing bulk throughput.
2031 * this functionality is controlled by the InterruptThrottleRate module
2032 * parameter (see ixgbe_param.c)
2033 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002034static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2035 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002036{
Alexander Duyckbd198052011-06-11 01:45:08 +00002037 int bytes = ring_container->total_bytes;
2038 int packets = ring_container->total_packets;
2039 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002040 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002041 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002042
2043 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002044 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002045
2046 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002047 * 0-10MB/s lowest (100000 ints/s)
2048 * 10-20MB/s low (20000 ints/s)
2049 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002050 */
2051 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002052 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002053 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2054
2055 switch (itr_setting) {
2056 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002057 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002058 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002059 break;
2060 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002061 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002062 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002063 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002064 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002065 break;
2066 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002067 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002068 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002069 break;
2070 }
2071
Alexander Duyckbd198052011-06-11 01:45:08 +00002072 /* clear work counters since we have the values we need */
2073 ring_container->total_bytes = 0;
2074 ring_container->total_packets = 0;
2075
2076 /* write updated itr to ring container */
2077 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002078}
2079
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002080/**
2081 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002082 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002083 *
2084 * This function is made to be called by ethtool and by the driver
2085 * when it needs to update EITR registers at runtime. Hardware
2086 * specific quirks/differences are taken care of here.
2087 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002088void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002089{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002090 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002091 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002092 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002093 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002094
Alexander Duyckbd508172010-11-16 19:27:03 -08002095 switch (adapter->hw.mac.type) {
2096 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002097 /* must write high and low 16 bits to reset counter */
2098 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002099 break;
2100 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002101 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002102 /*
2103 * set the WDIS bit to not clear the timer bits and cause an
2104 * immediate assertion of the interrupt
2105 */
2106 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002107 break;
2108 default:
2109 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002110 }
2111 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2112}
2113
Alexander Duyckbd198052011-06-11 01:45:08 +00002114static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002115{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002116 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002117 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002118
Alexander Duyckbd198052011-06-11 01:45:08 +00002119 ixgbe_update_itr(q_vector, &q_vector->tx);
2120 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002121
Alexander Duyck08c88332011-06-11 01:45:03 +00002122 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002123
2124 switch (current_itr) {
2125 /* counts and packets in update_itr are dependent on these numbers */
2126 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002127 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002128 break;
2129 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002130 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002131 break;
2132 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002133 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002134 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002135 default:
2136 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002137 }
2138
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002139 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002140 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002141 new_itr = (10 * new_itr * q_vector->itr) /
2142 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002143
Alexander Duyckbd198052011-06-11 01:45:08 +00002144 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002145 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002146
2147 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002148 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002149}
2150
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002151/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002152 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002153 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002154 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002155static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002156{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002157 struct ixgbe_hw *hw = &adapter->hw;
2158 u32 eicr = adapter->interrupt_event;
2159
Alexander Duyckf0f97782011-04-22 04:08:09 +00002160 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002161 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002162
Alexander Duyckf0f97782011-04-22 04:08:09 +00002163 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2164 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2165 return;
2166
2167 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2168
Joe Perches7ca647b2010-09-07 21:35:40 +00002169 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002170 case IXGBE_DEV_ID_82599_T3_LOM:
2171 /*
2172 * Since the warning interrupt is for both ports
2173 * we don't have to check if:
2174 * - This interrupt wasn't for our port.
2175 * - We may have missed the interrupt so always have to
2176 * check if we got a LSC
2177 */
2178 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2179 !(eicr & IXGBE_EICR_LSC))
2180 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002181
Alexander Duyckf0f97782011-04-22 04:08:09 +00002182 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2183 u32 autoneg;
2184 bool link_up = false;
2185
Joe Perches7ca647b2010-09-07 21:35:40 +00002186 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2187
Alexander Duyckf0f97782011-04-22 04:08:09 +00002188 if (link_up)
2189 return;
2190 }
2191
2192 /* Check if this is not due to overtemp */
2193 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2194 return;
2195
2196 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002197 default:
2198 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2199 return;
2200 break;
2201 }
2202 e_crit(drv,
2203 "Network adapter has been stopped because it has over heated. "
2204 "Restart the computer. If the problem persists, "
2205 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002206
2207 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002208}
2209
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002210static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2211{
2212 struct ixgbe_hw *hw = &adapter->hw;
2213
2214 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2215 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002216 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002217 /* write to clear the interrupt */
2218 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2219 }
2220}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002221
Jacob Keller4f51bf72011-08-20 04:49:45 +00002222static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2223{
2224 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2225 return;
2226
2227 switch (adapter->hw.mac.type) {
2228 case ixgbe_mac_82599EB:
2229 /*
2230 * Need to check link state so complete overtemp check
2231 * on service task
2232 */
2233 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2234 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2235 adapter->interrupt_event = eicr;
2236 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2237 ixgbe_service_event_schedule(adapter);
2238 return;
2239 }
2240 return;
2241 case ixgbe_mac_X540:
2242 if (!(eicr & IXGBE_EICR_TS))
2243 return;
2244 break;
2245 default:
2246 return;
2247 }
2248
2249 e_crit(drv,
2250 "Network adapter has been stopped because it has over heated. "
2251 "Restart the computer. If the problem persists, "
2252 "power off the system and replace the adapter\n");
2253}
2254
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002255static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2256{
2257 struct ixgbe_hw *hw = &adapter->hw;
2258
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002259 if (eicr & IXGBE_EICR_GPI_SDP2) {
2260 /* Clear the interrupt */
2261 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002262 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2263 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2264 ixgbe_service_event_schedule(adapter);
2265 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002266 }
2267
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002268 if (eicr & IXGBE_EICR_GPI_SDP1) {
2269 /* Clear the interrupt */
2270 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002271 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2272 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2273 ixgbe_service_event_schedule(adapter);
2274 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002275 }
2276}
2277
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002278static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2279{
2280 struct ixgbe_hw *hw = &adapter->hw;
2281
2282 adapter->lsc_int++;
2283 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2284 adapter->link_check_timeout = jiffies;
2285 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2286 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002287 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002288 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002289 }
2290}
2291
Alexander Duyckfe49f042009-06-04 16:00:09 +00002292static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2293 u64 qmask)
2294{
2295 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002296 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002297
Alexander Duyckbd508172010-11-16 19:27:03 -08002298 switch (hw->mac.type) {
2299 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002300 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002301 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2302 break;
2303 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002304 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002305 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002306 if (mask)
2307 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002308 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002309 if (mask)
2310 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2311 break;
2312 default:
2313 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002314 }
2315 /* skip the flush */
2316}
2317
2318static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002319 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002320{
2321 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002322 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002323
Alexander Duyckbd508172010-11-16 19:27:03 -08002324 switch (hw->mac.type) {
2325 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002326 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002327 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2328 break;
2329 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002330 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002331 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002332 if (mask)
2333 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002334 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002335 if (mask)
2336 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2337 break;
2338 default:
2339 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002340 }
2341 /* skip the flush */
2342}
2343
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002345 * ixgbe_irq_enable - Enable default interrupt generation settings
2346 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002347 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002348static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2349 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002350{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002351 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002352
Alexander Duyck2c4af692011-07-15 07:29:55 +00002353 /* don't reenable LSC while waiting for link */
2354 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2355 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002356
Alexander Duyck2c4af692011-07-15 07:29:55 +00002357 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002358 switch (adapter->hw.mac.type) {
2359 case ixgbe_mac_82599EB:
2360 mask |= IXGBE_EIMS_GPI_SDP0;
2361 break;
2362 case ixgbe_mac_X540:
2363 mask |= IXGBE_EIMS_TS;
2364 break;
2365 default:
2366 break;
2367 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002368 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2369 mask |= IXGBE_EIMS_GPI_SDP1;
2370 switch (adapter->hw.mac.type) {
2371 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002372 mask |= IXGBE_EIMS_GPI_SDP1;
2373 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002374 case ixgbe_mac_X540:
2375 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002376 mask |= IXGBE_EIMS_MAILBOX;
2377 break;
2378 default:
2379 break;
2380 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002381
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002382 if (adapter->hw.mac.type == ixgbe_mac_X540)
2383 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002384
Alexander Duyck2c4af692011-07-15 07:29:55 +00002385 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2386 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2387 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002388
Alexander Duyck2c4af692011-07-15 07:29:55 +00002389 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2390 if (queues)
2391 ixgbe_irq_enable_queues(adapter, ~0);
2392 if (flush)
2393 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002394}
2395
Alexander Duyck2c4af692011-07-15 07:29:55 +00002396static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002397{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002398 struct ixgbe_adapter *adapter = data;
2399 struct ixgbe_hw *hw = &adapter->hw;
2400 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002401
Alexander Duyck2c4af692011-07-15 07:29:55 +00002402 /*
2403 * Workaround for Silicon errata. Use clear-by-write instead
2404 * of clear-by-read. Reading with EICS will return the
2405 * interrupt causes without clearing, which later be done
2406 * with the write to EICR.
2407 */
2408 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2409 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002410
Alexander Duyck2c4af692011-07-15 07:29:55 +00002411 if (eicr & IXGBE_EICR_LSC)
2412 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002413
Alexander Duyck2c4af692011-07-15 07:29:55 +00002414 if (eicr & IXGBE_EICR_MAILBOX)
2415 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002416
Alexander Duyck2c4af692011-07-15 07:29:55 +00002417 switch (hw->mac.type) {
2418 case ixgbe_mac_82599EB:
2419 case ixgbe_mac_X540:
2420 if (eicr & IXGBE_EICR_ECC)
2421 e_info(link, "Received unrecoverable ECC Err, please "
2422 "reboot\n");
2423 /* Handle Flow Director Full threshold interrupt */
2424 if (eicr & IXGBE_EICR_FLOW_DIR) {
2425 int reinit_count = 0;
2426 int i;
2427 for (i = 0; i < adapter->num_tx_queues; i++) {
2428 struct ixgbe_ring *ring = adapter->tx_ring[i];
2429 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2430 &ring->state))
2431 reinit_count++;
2432 }
2433 if (reinit_count) {
2434 /* no more flow director interrupts until after init */
2435 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2436 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2437 ixgbe_service_event_schedule(adapter);
2438 }
2439 }
2440 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002441 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002442 break;
2443 default:
2444 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002445 }
2446
Alexander Duyck2c4af692011-07-15 07:29:55 +00002447 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002448
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002449 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2450 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002451
Alexander Duyck2c4af692011-07-15 07:29:55 +00002452 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002453 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002454 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002455
Alexander Duyck2c4af692011-07-15 07:29:55 +00002456 return IRQ_HANDLED;
2457}
2458
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002459static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002460{
2461 struct ixgbe_q_vector *q_vector = data;
2462
Auke Kok9a799d72007-09-15 14:07:45 -07002463 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002464
2465 if (q_vector->rx.ring || q_vector->tx.ring)
2466 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002467
2468 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002469}
2470
Auke Kok9a799d72007-09-15 14:07:45 -07002471/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002472 * ixgbe_poll - NAPI Rx polling callback
2473 * @napi: structure for representing this polling device
2474 * @budget: how many packets driver is allowed to clean
2475 *
2476 * This function is used for legacy and MSI, NAPI mode
2477 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002478int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002479{
2480 struct ixgbe_q_vector *q_vector =
2481 container_of(napi, struct ixgbe_q_vector, napi);
2482 struct ixgbe_adapter *adapter = q_vector->adapter;
2483 struct ixgbe_ring *ring;
2484 int per_ring_budget;
2485 bool clean_complete = true;
2486
2487#ifdef CONFIG_IXGBE_DCA
2488 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2489 ixgbe_update_dca(q_vector);
2490#endif
2491
2492 ixgbe_for_each_ring(ring, q_vector->tx)
2493 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2494
2495 /* attempt to distribute budget to each queue fairly, but don't allow
2496 * the budget to go below 1 because we'll exit polling */
2497 if (q_vector->rx.count > 1)
2498 per_ring_budget = max(budget/q_vector->rx.count, 1);
2499 else
2500 per_ring_budget = budget;
2501
2502 ixgbe_for_each_ring(ring, q_vector->rx)
2503 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2504 per_ring_budget);
2505
2506 /* If all work not completed, return budget and keep polling */
2507 if (!clean_complete)
2508 return budget;
2509
2510 /* all work done, exit the polling mode */
2511 napi_complete(napi);
2512 if (adapter->rx_itr_setting & 1)
2513 ixgbe_set_itr(q_vector);
2514 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2515 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2516
2517 return 0;
2518}
2519
2520/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002521 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2522 * @adapter: board private structure
2523 *
2524 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2525 * interrupts from the kernel.
2526 **/
2527static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2528{
2529 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002530 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002531 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002533 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002534 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002535 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002536
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002537 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002538 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002539 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002540 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002541 } else if (q_vector->rx.ring) {
2542 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2543 "%s-%s-%d", netdev->name, "rx", ri++);
2544 } else if (q_vector->tx.ring) {
2545 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2546 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002547 } else {
2548 /* skip this unused q_vector */
2549 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002550 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002551 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2552 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002554 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002555 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002556 goto free_queue_irqs;
2557 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002558 /* If Flow Director is enabled, set interrupt affinity */
2559 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2560 /* assign the mask for this irq */
2561 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002562 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002563 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002564 }
2565
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002566 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002567 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002568 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002569 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002570 goto free_queue_irqs;
2571 }
2572
2573 return 0;
2574
2575free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002576 while (vector) {
2577 vector--;
2578 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2579 NULL);
2580 free_irq(adapter->msix_entries[vector].vector,
2581 adapter->q_vector[vector]);
2582 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002583 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2584 pci_disable_msix(adapter->pdev);
2585 kfree(adapter->msix_entries);
2586 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002587 return err;
2588}
2589
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002590/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002591 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002592 * @irq: interrupt number
2593 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002594 **/
2595static irqreturn_t ixgbe_intr(int irq, void *data)
2596{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002597 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002598 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002599 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002600 u32 eicr;
2601
Don Skidmore54037502009-02-21 15:42:56 -08002602 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002603 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002604 * before the read of EICR.
2605 */
2606 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2607
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002608 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002609 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002610 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002611 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002612 /*
2613 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002614 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002615 * have disabled interrupts due to EIAM
2616 * finish the workaround of silicon errata on 82598. Unmask
2617 * the interrupt that we masked before the EICR read.
2618 */
2619 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2620 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002621 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002622 }
Auke Kok9a799d72007-09-15 14:07:45 -07002623
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002624 if (eicr & IXGBE_EICR_LSC)
2625 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002626
Alexander Duyckbd508172010-11-16 19:27:03 -08002627 switch (hw->mac.type) {
2628 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002629 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002630 /* Fall through */
2631 case ixgbe_mac_X540:
2632 if (eicr & IXGBE_EICR_ECC)
2633 e_info(link, "Received unrecoverable ECC err, please "
2634 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002635 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002636 break;
2637 default:
2638 break;
2639 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002640
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002641 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002642 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2643 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002644
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002645 /* would disable interrupts here but EIAM disabled it */
2646 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002647
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002648 /*
2649 * re-enable link(maybe) and non-queue interrupts, no flush.
2650 * ixgbe_poll will re-enable the queue interrupts
2651 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002652 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2653 ixgbe_irq_enable(adapter, false, false);
2654
Auke Kok9a799d72007-09-15 14:07:45 -07002655 return IRQ_HANDLED;
2656}
2657
2658/**
2659 * ixgbe_request_irq - initialize interrupts
2660 * @adapter: board private structure
2661 *
2662 * Attempts to configure interrupts using the best available
2663 * capabilities of the hardware and kernel.
2664 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002666{
2667 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002668 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002669
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002670 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002671 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002672 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002673 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002674 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002675 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002676 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002677 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002678
Alexander Duyckde88eee2012-02-08 07:49:59 +00002679 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002680 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002681
Auke Kok9a799d72007-09-15 14:07:45 -07002682 return err;
2683}
2684
2685static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2686{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002687 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002688
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002689 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002690 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002691 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002692 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002693
2694 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2695 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2696 struct msix_entry *entry = &adapter->msix_entries[vector];
2697
2698 /* free only the irqs that were actually requested */
2699 if (!q_vector->rx.ring && !q_vector->tx.ring)
2700 continue;
2701
2702 /* clear the affinity_mask in the IRQ descriptor */
2703 irq_set_affinity_hint(entry->vector, NULL);
2704
2705 free_irq(entry->vector, q_vector);
2706 }
2707
2708 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002709}
2710
2711/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002712 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2713 * @adapter: board private structure
2714 **/
2715static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2716{
Alexander Duyckbd508172010-11-16 19:27:03 -08002717 switch (adapter->hw.mac.type) {
2718 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002719 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002720 break;
2721 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002722 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002723 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2724 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002725 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002726 break;
2727 default:
2728 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002729 }
2730 IXGBE_WRITE_FLUSH(&adapter->hw);
2731 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002732 int vector;
2733
2734 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2735 synchronize_irq(adapter->msix_entries[vector].vector);
2736
2737 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002738 } else {
2739 synchronize_irq(adapter->pdev->irq);
2740 }
2741}
2742
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002743/**
Auke Kok9a799d72007-09-15 14:07:45 -07002744 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2745 *
2746 **/
2747static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2748{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002749 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002750
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002751 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002752
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002753 ixgbe_set_ivar(adapter, 0, 0, 0);
2754 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002755
Emil Tantilov396e7992010-07-01 20:05:12 +00002756 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002757}
2758
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002759/**
2760 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2761 * @adapter: board private structure
2762 * @ring: structure containing ring specific data
2763 *
2764 * Configure the Tx descriptor ring after a reset.
2765 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002766void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2767 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002768{
2769 struct ixgbe_hw *hw = &adapter->hw;
2770 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002771 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002772 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002773 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002774
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002775 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002776 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002777 IXGBE_WRITE_FLUSH(hw);
2778
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002779 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002780 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002781 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2782 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2783 ring->count * sizeof(union ixgbe_adv_tx_desc));
2784 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2785 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002786 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002787
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002788 /*
2789 * set WTHRESH to encourage burst writeback, it should not be set
2790 * higher than 1 when ITR is 0 as it could cause false TX hangs
2791 *
2792 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2793 * to or less than the number of on chip descriptors, which is
2794 * currently 40.
2795 */
Alexander Duycke954b372012-02-08 07:49:38 +00002796 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002797 txdctl |= (1 << 16); /* WTHRESH = 1 */
2798 else
2799 txdctl |= (8 << 16); /* WTHRESH = 8 */
2800
Alexander Duycke954b372012-02-08 07:49:38 +00002801 /*
2802 * Setting PTHRESH to 32 both improves performance
2803 * and avoids a TX hang with DFP enabled
2804 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002805 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2806 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002807
2808 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002809 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002810 ring->atr_sample_rate = adapter->atr_sample_rate;
2811 ring->atr_count = 0;
2812 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2813 } else {
2814 ring->atr_sample_rate = 0;
2815 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002816
John Fastabendc84d3242010-11-16 19:27:12 -08002817 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2818
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002819 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002820 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2821
2822 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2823 if (hw->mac.type == ixgbe_mac_82598EB &&
2824 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2825 return;
2826
2827 /* poll to verify queue is enabled */
2828 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002829 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002830 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2831 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2832 if (!wait_loop)
2833 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002834}
2835
Alexander Duyck120ff942010-08-19 13:34:50 +00002836static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2837{
2838 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002839 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002840 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002841
2842 if (hw->mac.type == ixgbe_mac_82598EB)
2843 return;
2844
2845 /* disable the arbiter while setting MTQC */
2846 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2847 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2848 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2849
2850 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002851 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2852 mtqc = IXGBE_MTQC_VT_ENA;
2853 if (tcs > 4)
2854 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2855 else if (tcs > 1)
2856 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2857 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2858 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002859 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002860 mtqc |= IXGBE_MTQC_64VF;
2861 } else {
2862 if (tcs > 4)
2863 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2864 else if (tcs > 1)
2865 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2866 else
2867 mtqc = IXGBE_MTQC_64Q_1PB;
2868 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002869
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002870 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002871
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002872 /* Enable Security TX Buffer IFG for multiple pb */
2873 if (tcs) {
2874 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2875 sectx |= IXGBE_SECTX_DCB;
2876 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002877 }
2878
2879 /* re-enable the arbiter */
2880 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2881 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2882}
2883
Auke Kok9a799d72007-09-15 14:07:45 -07002884/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002885 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002886 * @adapter: board private structure
2887 *
2888 * Configure the Tx unit of the MAC after a reset.
2889 **/
2890static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2891{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002892 struct ixgbe_hw *hw = &adapter->hw;
2893 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002894 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002895
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002896 ixgbe_setup_mtqc(adapter);
2897
2898 if (hw->mac.type != ixgbe_mac_82598EB) {
2899 /* DMATXCTL.EN must be before Tx queues are enabled */
2900 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2901 dmatxctl |= IXGBE_DMATXCTL_TE;
2902 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2903 }
2904
Auke Kok9a799d72007-09-15 14:07:45 -07002905 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002906 for (i = 0; i < adapter->num_tx_queues; i++)
2907 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002908}
2909
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002910static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2911 struct ixgbe_ring *ring)
2912{
2913 struct ixgbe_hw *hw = &adapter->hw;
2914 u8 reg_idx = ring->reg_idx;
2915 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2916
2917 srrctl |= IXGBE_SRRCTL_DROP_EN;
2918
2919 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2920}
2921
2922static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2923 struct ixgbe_ring *ring)
2924{
2925 struct ixgbe_hw *hw = &adapter->hw;
2926 u8 reg_idx = ring->reg_idx;
2927 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2928
2929 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2930
2931 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2932}
2933
2934#ifdef CONFIG_IXGBE_DCB
2935void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2936#else
2937static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2938#endif
2939{
2940 int i;
2941 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2942
2943 if (adapter->ixgbe_ieee_pfc)
2944 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2945
2946 /*
2947 * We should set the drop enable bit if:
2948 * SR-IOV is enabled
2949 * or
2950 * Number of Rx queues > 1 and flow control is disabled
2951 *
2952 * This allows us to avoid head of line blocking for security
2953 * and performance reasons.
2954 */
2955 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2956 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2957 for (i = 0; i < adapter->num_rx_queues; i++)
2958 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2959 } else {
2960 for (i = 0; i < adapter->num_rx_queues; i++)
2961 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2962 }
2963}
2964
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002965#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002966
Yi Zoua6616b42009-08-06 13:05:23 +00002967static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002968 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002969{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002970 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002971 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002972 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002973
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002974 if (hw->mac.type == ixgbe_mac_82598EB) {
2975 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2976
2977 /*
2978 * if VMDq is not active we must program one srrctl register
2979 * per RSS queue since we have enabled RDRXCTL.MVMEN
2980 */
2981 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002982 }
2983
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002984 /* configure header buffer length, needed for RSC */
2985 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002986
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002987 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00002988 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002989
2990 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00002991 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002992
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002993 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002994}
2995
Alexander Duyck05abb122010-08-19 13:35:41 +00002996static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002997{
Alexander Duyck05abb122010-08-19 13:35:41 +00002998 struct ixgbe_hw *hw = &adapter->hw;
2999 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003000 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3001 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003002 u32 mrqc = 0, reta = 0;
3003 u32 rxcsum;
3004 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003005 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003006
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003007 /*
3008 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3009 * make full use of any rings they may have. We will use the
3010 * PSRTYPE register to control how many rings we use within the PF.
3011 */
3012 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3013 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003014
Alexander Duyck05abb122010-08-19 13:35:41 +00003015 /* Fill out hash function seeds */
3016 for (i = 0; i < 10; i++)
3017 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003018
Alexander Duyck05abb122010-08-19 13:35:41 +00003019 /* Fill out redirection table */
3020 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003021 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003022 j = 0;
3023 /* reta = 4-byte sliding window of
3024 * 0x00..(indices-1)(indices-1)00..etc. */
3025 reta = (reta << 8) | (j * 0x11);
3026 if ((i & 3) == 3)
3027 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3028 }
3029
3030 /* Disable indicating checksum in descriptor, enables RSS hash */
3031 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3032 rxcsum |= IXGBE_RXCSUM_PCSD;
3033 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3034
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003035 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003036 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003037 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003038 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003039 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003040
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003041 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3042 if (tcs > 4)
3043 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3044 else if (tcs > 1)
3045 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3046 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3047 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3048 else
3049 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3050 } else {
3051 if (tcs > 4)
3052 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3053 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003054 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3055 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003056 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003057 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003058 }
3059
Alexander Duyck05abb122010-08-19 13:35:41 +00003060 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003061 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3062 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3063 IXGBE_MRQC_RSS_FIELD_IPV6 |
3064 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003065
Alexander Duyckef6afc02012-02-08 07:51:53 +00003066 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3067 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3068 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3069 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3070
Alexander Duyck05abb122010-08-19 13:35:41 +00003071 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003072}
3073
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003074/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003075 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3076 * @adapter: address of board private structure
3077 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003078 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003079static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003080 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003081{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003082 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003083 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003084 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003085
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003086 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003087 return;
3088
Alexander Duyck73670962010-08-19 13:38:34 +00003089 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003090 rscctrl |= IXGBE_RSCCTL_RSCEN;
3091 /*
3092 * we must limit the number of descriptors so that the
3093 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003094 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003095 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003096 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003097 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003098}
3099
Alexander Duyck9e10e042010-08-19 13:40:06 +00003100#define IXGBE_MAX_RX_DESC_POLL 10
3101static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3102 struct ixgbe_ring *ring)
3103{
3104 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003105 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3106 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003107 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003108
3109 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3110 if (hw->mac.type == ixgbe_mac_82598EB &&
3111 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3112 return;
3113
3114 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003115 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003116 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3117 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3118
3119 if (!wait_loop) {
3120 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3121 "the polling period\n", reg_idx);
3122 }
3123}
3124
Yi Zou2d39d572011-01-06 14:29:56 +00003125void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3126 struct ixgbe_ring *ring)
3127{
3128 struct ixgbe_hw *hw = &adapter->hw;
3129 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3130 u32 rxdctl;
3131 u8 reg_idx = ring->reg_idx;
3132
3133 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3134 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3135
3136 /* write value back with RXDCTL.ENABLE bit cleared */
3137 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3138
3139 if (hw->mac.type == ixgbe_mac_82598EB &&
3140 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3141 return;
3142
3143 /* the hardware may take up to 100us to really disable the rx queue */
3144 do {
3145 udelay(10);
3146 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3147 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3148
3149 if (!wait_loop) {
3150 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3151 "the polling period\n", reg_idx);
3152 }
3153}
3154
Alexander Duyck84418e32010-08-19 13:40:54 +00003155void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3156 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003157{
3158 struct ixgbe_hw *hw = &adapter->hw;
3159 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003160 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003161 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003162
Alexander Duyck9e10e042010-08-19 13:40:06 +00003163 /* disable queue to avoid issues while updating state */
3164 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003165 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003166
Alexander Duyckacd37172010-08-19 13:36:05 +00003167 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3168 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3169 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3170 ring->count * sizeof(union ixgbe_adv_rx_desc));
3171 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3172 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003173 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003174
3175 ixgbe_configure_srrctl(adapter, ring);
3176 ixgbe_configure_rscctl(adapter, ring);
3177
3178 if (hw->mac.type == ixgbe_mac_82598EB) {
3179 /*
3180 * enable cache line friendly hardware writes:
3181 * PTHRESH=32 descriptors (half the internal cache),
3182 * this also removes ugly rx_no_buffer_count increment
3183 * HTHRESH=4 descriptors (to minimize latency on fetch)
3184 * WTHRESH=8 burst writeback up to two cache lines
3185 */
3186 rxdctl &= ~0x3FFFFF;
3187 rxdctl |= 0x080420;
3188 }
3189
3190 /* enable receive descriptor ring */
3191 rxdctl |= IXGBE_RXDCTL_ENABLE;
3192 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3193
3194 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003195 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003196}
3197
Alexander Duyck48654522010-08-19 13:36:27 +00003198static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3199{
3200 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003201 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003202 int p;
3203
3204 /* PSRTYPE must be initialized in non 82598 adapters */
3205 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003206 IXGBE_PSRTYPE_UDPHDR |
3207 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003208 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003209 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003210
3211 if (hw->mac.type == ixgbe_mac_82598EB)
3212 return;
3213
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003214 if (rss_i > 3)
3215 psrtype |= 2 << 29;
3216 else if (rss_i > 1)
3217 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003218
3219 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003220 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003221 psrtype);
3222}
3223
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003224static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3225{
3226 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003227 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003228 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003229 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003230
3231 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3232 return;
3233
3234 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003235 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3236 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003237 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003238 vmdctl |= IXGBE_VT_CTL_REPLEN;
3239 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003240
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003241 vf_shift = VMDQ_P(0) % 32;
3242 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003243
3244 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003245 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3246 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3247 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3248 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003249 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3250 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003251
3252 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003253 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003254
3255 /*
3256 * Set up VF register offsets for selected VT Mode,
3257 * i.e. 32 or 64 VFs for SR-IOV
3258 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003259 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3260 case IXGBE_82599_VMDQ_8Q_MASK:
3261 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3262 break;
3263 case IXGBE_82599_VMDQ_4Q_MASK:
3264 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3265 break;
3266 default:
3267 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3268 break;
3269 }
3270
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003271 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3272
Alexander Duyck435b19f2012-05-18 06:34:08 +00003273
Greg Rosea985b6c32010-11-18 03:02:52 +00003274 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003275 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003276 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003277 /* For VFs that have spoof checking turned off */
3278 for (i = 0; i < adapter->num_vfs; i++) {
3279 if (!adapter->vfinfo[i].spoofchk_enabled)
3280 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3281 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003282}
3283
Alexander Duyck477de6e2010-08-19 13:38:11 +00003284static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003285{
Auke Kok9a799d72007-09-15 14:07:45 -07003286 struct ixgbe_hw *hw = &adapter->hw;
3287 struct net_device *netdev = adapter->netdev;
3288 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003289 struct ixgbe_ring *rx_ring;
3290 int i;
3291 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003292
Alexander Duyck477de6e2010-08-19 13:38:11 +00003293#ifdef IXGBE_FCOE
3294 /* adjust max frame to be able to do baby jumbo for FCoE */
3295 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3296 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3297 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3298
3299#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003300
3301 /* adjust max frame to be at least the size of a standard frame */
3302 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3303 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3304
Alexander Duyck477de6e2010-08-19 13:38:11 +00003305 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3306 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3307 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3308 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3309
3310 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003311 }
3312
Auke Kok9a799d72007-09-15 14:07:45 -07003313 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003314 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3315 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003316 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3317
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003318 /*
3319 * Setup the HW Rx Head and Tail Descriptor Pointers and
3320 * the Base and Length of the Rx Descriptor Ring
3321 */
Auke Kok9a799d72007-09-15 14:07:45 -07003322 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003323 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003324 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3325 set_ring_rsc_enabled(rx_ring);
3326 else
3327 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003328 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003329}
3330
Alexander Duyck73670962010-08-19 13:38:34 +00003331static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3332{
3333 struct ixgbe_hw *hw = &adapter->hw;
3334 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3335
3336 switch (hw->mac.type) {
3337 case ixgbe_mac_82598EB:
3338 /*
3339 * For VMDq support of different descriptor types or
3340 * buffer sizes through the use of multiple SRRCTL
3341 * registers, RDRXCTL.MVMEN must be set to 1
3342 *
3343 * also, the manual doesn't mention it clearly but DCA hints
3344 * will only use queue 0's tags unless this bit is set. Side
3345 * effects of setting this bit are only that SRRCTL must be
3346 * fully programmed [0..15]
3347 */
3348 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3349 break;
3350 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003351 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003352 /* Disable RSC for ACK packets */
3353 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3354 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3355 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3356 /* hardware requires some bits to be set by default */
3357 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3358 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3359 break;
3360 default:
3361 /* We should do nothing since we don't know this hardware */
3362 return;
3363 }
3364
3365 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3366}
3367
Alexander Duyck477de6e2010-08-19 13:38:11 +00003368/**
3369 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3370 * @adapter: board private structure
3371 *
3372 * Configure the Rx unit of the MAC after a reset.
3373 **/
3374static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3375{
3376 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003377 int i;
3378 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003379
3380 /* disable receives while setting up the descriptors */
3381 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3382 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3383
3384 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003385 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003386
Alexander Duyck9e10e042010-08-19 13:40:06 +00003387 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003388 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003389
Alexander Duyck477de6e2010-08-19 13:38:11 +00003390 /* set_rx_buffer_len must be called before ring initialization */
3391 ixgbe_set_rx_buffer_len(adapter);
3392
3393 /*
3394 * Setup the HW Rx Head and Tail Descriptor Pointers and
3395 * the Base and Length of the Rx Descriptor Ring
3396 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003397 for (i = 0; i < adapter->num_rx_queues; i++)
3398 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003399
Alexander Duyck9e10e042010-08-19 13:40:06 +00003400 /* disable drop enable for 82598 parts */
3401 if (hw->mac.type == ixgbe_mac_82598EB)
3402 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3403
3404 /* enable all receives */
3405 rxctrl |= IXGBE_RXCTRL_RXEN;
3406 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003407}
3408
Jiri Pirko8e586132011-12-08 19:52:37 -05003409static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003410{
3411 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003412 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003413
3414 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003415 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003416 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003417
3418 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003419}
3420
Jiri Pirko8e586132011-12-08 19:52:37 -05003421static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003422{
3423 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003424 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003425
Auke Kok9a799d72007-09-15 14:07:45 -07003426 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003427 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003428 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003429
3430 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003431}
3432
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003433/**
3434 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3435 * @adapter: driver data
3436 */
3437static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3438{
3439 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003440 u32 vlnctrl;
3441
3442 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3443 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3444 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3445}
3446
3447/**
3448 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3449 * @adapter: driver data
3450 */
3451static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3452{
3453 struct ixgbe_hw *hw = &adapter->hw;
3454 u32 vlnctrl;
3455
3456 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3457 vlnctrl |= IXGBE_VLNCTRL_VFE;
3458 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3459 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3460}
3461
3462/**
3463 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3464 * @adapter: driver data
3465 */
3466static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3467{
3468 struct ixgbe_hw *hw = &adapter->hw;
3469 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003470 int i, j;
3471
3472 switch (hw->mac.type) {
3473 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003474 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3475 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003476 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3477 break;
3478 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003479 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003480 for (i = 0; i < adapter->num_rx_queues; i++) {
3481 j = adapter->rx_ring[i]->reg_idx;
3482 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3483 vlnctrl &= ~IXGBE_RXDCTL_VME;
3484 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3485 }
3486 break;
3487 default:
3488 break;
3489 }
3490}
3491
3492/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003493 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003494 * @adapter: driver data
3495 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003496static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003497{
3498 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003499 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003500 int i, j;
3501
3502 switch (hw->mac.type) {
3503 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003504 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3505 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003506 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3507 break;
3508 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003509 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003510 for (i = 0; i < adapter->num_rx_queues; i++) {
3511 j = adapter->rx_ring[i]->reg_idx;
3512 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3513 vlnctrl |= IXGBE_RXDCTL_VME;
3514 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3515 }
3516 break;
3517 default:
3518 break;
3519 }
3520}
3521
Auke Kok9a799d72007-09-15 14:07:45 -07003522static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3523{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003524 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003525
Jesse Grossf62bbb52010-10-20 13:56:10 +00003526 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3527
3528 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3529 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003530}
3531
3532/**
Alexander Duyck28500622010-06-15 09:25:48 +00003533 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3534 * @netdev: network interface device structure
3535 *
3536 * Writes unicast address list to the RAR table.
3537 * Returns: -ENOMEM on failure/insufficient address space
3538 * 0 on no addresses written
3539 * X on writing X addresses to the RAR table
3540 **/
3541static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3542{
3543 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3544 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003545 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003546 int count = 0;
3547
John Fastabend95447462012-05-31 12:42:26 +00003548 /* In SR-IOV mode significantly less RAR entries are available */
3549 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3550 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3551
Alexander Duyck28500622010-06-15 09:25:48 +00003552 /* return ENOMEM indicating insufficient memory for addresses */
3553 if (netdev_uc_count(netdev) > rar_entries)
3554 return -ENOMEM;
3555
John Fastabend95447462012-05-31 12:42:26 +00003556 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003557 struct netdev_hw_addr *ha;
3558 /* return error if we do not support writing to RAR table */
3559 if (!hw->mac.ops.set_rar)
3560 return -ENOMEM;
3561
3562 netdev_for_each_uc_addr(ha, netdev) {
3563 if (!rar_entries)
3564 break;
3565 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003566 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003567 count++;
3568 }
3569 }
3570 /* write the addresses in reverse order to avoid write combining */
3571 for (; rar_entries > 0 ; rar_entries--)
3572 hw->mac.ops.clear_rar(hw, rar_entries);
3573
3574 return count;
3575}
3576
3577/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003578 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003579 * @netdev: network interface device structure
3580 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003581 * The set_rx_method entry point is called whenever the unicast/multicast
3582 * address list or the network interface flags are updated. This routine is
3583 * responsible for configuring the hardware for proper unicast, multicast and
3584 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003585 **/
Greg Rose7f870472010-01-09 02:25:29 +00003586void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003587{
3588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3589 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003590 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3591 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003592
3593 /* Check for Promiscuous and All Multicast modes */
3594
3595 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3596
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003597 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003598 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003599 fctrl |= IXGBE_FCTRL_BAM;
3600 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3601 fctrl |= IXGBE_FCTRL_PMCF;
3602
Alexander Duyck28500622010-06-15 09:25:48 +00003603 /* clear the bits we are changing the status of */
3604 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3605
Auke Kok9a799d72007-09-15 14:07:45 -07003606 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003607 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003608 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003609 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003610 /* don't hardware filter vlans in promisc mode */
3611 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003612 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003613 if (netdev->flags & IFF_ALLMULTI) {
3614 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003615 vmolr |= IXGBE_VMOLR_MPE;
3616 } else {
3617 /*
3618 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003619 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003620 * that we can at least receive multicast traffic
3621 */
3622 hw->mac.ops.update_mc_addr_list(hw, netdev);
3623 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003624 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003625 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003626 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003627 }
3628
3629 /*
3630 * Write addresses to available RAR registers, if there is not
3631 * sufficient space to store all the addresses then enable
3632 * unicast promiscuous mode
3633 */
3634 count = ixgbe_write_uc_addr_list(netdev);
3635 if (count < 0) {
3636 fctrl |= IXGBE_FCTRL_UPE;
3637 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003638 }
3639
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003640 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003641 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003642
3643 if (hw->mac.type != ixgbe_mac_82598EB) {
3644 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003645 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3646 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003647 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003648 }
3649
Ben Greear3f2d1c02012-03-08 08:28:41 +00003650 /* This is useful for sniffing bad packets. */
3651 if (adapter->netdev->features & NETIF_F_RXALL) {
3652 /* UPE and MPE will be handled by normal PROMISC logic
3653 * in e1000e_set_rx_mode */
3654 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3655 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3656 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3657
3658 fctrl &= ~(IXGBE_FCTRL_DPF);
3659 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3660 }
3661
Auke Kok9a799d72007-09-15 14:07:45 -07003662 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003663
3664 if (netdev->features & NETIF_F_HW_VLAN_RX)
3665 ixgbe_vlan_strip_enable(adapter);
3666 else
3667 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003668}
3669
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003670static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3671{
3672 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003673
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003674 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3675 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003676}
3677
3678static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3679{
3680 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003681
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003682 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3683 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003684}
3685
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003686#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003687/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003688 * ixgbe_configure_dcb - Configure DCB hardware
3689 * @adapter: ixgbe adapter struct
3690 *
3691 * This is called by the driver on open to configure the DCB hardware.
3692 * This is also called by the gennetlink interface when reconfiguring
3693 * the DCB state.
3694 */
3695static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3696{
3697 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003698 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003699
Alexander Duyck67ebd792010-08-19 13:34:04 +00003700 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3701 if (hw->mac.type == ixgbe_mac_82598EB)
3702 netif_set_gso_max_size(adapter->netdev, 65536);
3703 return;
3704 }
3705
3706 if (hw->mac.type == ixgbe_mac_82598EB)
3707 netif_set_gso_max_size(adapter->netdev, 32768);
3708
John Fastabendb1208182011-10-15 05:00:10 +00003709#ifdef IXGBE_FCOE
3710 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3711 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3712#endif
3713
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003714 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003715 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003716 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3717 DCB_TX_CONFIG);
3718 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3719 DCB_RX_CONFIG);
3720 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003721 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3722 ixgbe_dcb_hw_ets(&adapter->hw,
3723 adapter->ixgbe_ieee_ets,
3724 max_frame);
3725 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3726 adapter->ixgbe_ieee_pfc->pfc_en,
3727 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003728 }
John Fastabend8187cd42011-02-23 05:58:08 +00003729
3730 /* Enable RSS Hash per TC */
3731 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003732 u32 msb = 0;
3733 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003734
Alexander Duyckd411a932012-06-30 00:14:01 +00003735 while (rss_i) {
3736 msb++;
3737 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003738 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003739
Alexander Duyck4ae63732012-06-22 06:46:33 +00003740 /* write msb to all 8 TCs in one write */
3741 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003742 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003743}
John Fastabend9da712d2011-08-23 03:14:22 +00003744#endif
3745
3746/* Additional bittime to account for IXGBE framing */
3747#define IXGBE_ETH_FRAMING 20
3748
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003749/**
John Fastabend9da712d2011-08-23 03:14:22 +00003750 * ixgbe_hpbthresh - calculate high water mark for flow control
3751 *
3752 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003753 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003754 */
3755static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3756{
3757 struct ixgbe_hw *hw = &adapter->hw;
3758 struct net_device *dev = adapter->netdev;
3759 int link, tc, kb, marker;
3760 u32 dv_id, rx_pba;
3761
3762 /* Calculate max LAN frame size */
3763 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3764
3765#ifdef IXGBE_FCOE
3766 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003767 if ((dev->features & NETIF_F_FCOE_MTU) &&
3768 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3769 (pb == ixgbe_fcoe_get_tc(adapter)))
3770 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003771
3772#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003773 /* Calculate delay value for device */
3774 switch (hw->mac.type) {
3775 case ixgbe_mac_X540:
3776 dv_id = IXGBE_DV_X540(link, tc);
3777 break;
3778 default:
3779 dv_id = IXGBE_DV(link, tc);
3780 break;
3781 }
3782
3783 /* Loopback switch introduces additional latency */
3784 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3785 dv_id += IXGBE_B2BT(tc);
3786
3787 /* Delay value is calculated in bit times convert to KB */
3788 kb = IXGBE_BT2KB(dv_id);
3789 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3790
3791 marker = rx_pba - kb;
3792
3793 /* It is possible that the packet buffer is not large enough
3794 * to provide required headroom. In this case throw an error
3795 * to user and a do the best we can.
3796 */
3797 if (marker < 0) {
3798 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3799 "headroom to support flow control."
3800 "Decrease MTU or number of traffic classes\n", pb);
3801 marker = tc + 1;
3802 }
3803
3804 return marker;
3805}
3806
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003807/**
John Fastabend9da712d2011-08-23 03:14:22 +00003808 * ixgbe_lpbthresh - calculate low water mark for for flow control
3809 *
3810 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003811 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003812 */
3813static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3814{
3815 struct ixgbe_hw *hw = &adapter->hw;
3816 struct net_device *dev = adapter->netdev;
3817 int tc;
3818 u32 dv_id;
3819
3820 /* Calculate max LAN frame size */
3821 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3822
3823 /* Calculate delay value for device */
3824 switch (hw->mac.type) {
3825 case ixgbe_mac_X540:
3826 dv_id = IXGBE_LOW_DV_X540(tc);
3827 break;
3828 default:
3829 dv_id = IXGBE_LOW_DV(tc);
3830 break;
3831 }
3832
3833 /* Delay value is calculated in bit times convert to KB */
3834 return IXGBE_BT2KB(dv_id);
3835}
3836
3837/*
3838 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3839 */
3840static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3841{
3842 struct ixgbe_hw *hw = &adapter->hw;
3843 int num_tc = netdev_get_num_tc(adapter->netdev);
3844 int i;
3845
3846 if (!num_tc)
3847 num_tc = 1;
3848
3849 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3850
3851 for (i = 0; i < num_tc; i++) {
3852 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3853
3854 /* Low water marks must not be larger than high water marks */
3855 if (hw->fc.low_water > hw->fc.high_water[i])
3856 hw->fc.low_water = 0;
3857 }
3858}
John Fastabend80605c652011-05-02 12:34:10 +00003859
3860static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3861{
John Fastabend80605c652011-05-02 12:34:10 +00003862 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003863 int hdrm;
3864 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003865
3866 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3867 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003868 hdrm = 32 << adapter->fdir_pballoc;
3869 else
3870 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003871
Alexander Duyckf7e10272011-07-21 00:40:35 +00003872 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003873 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003874}
3875
Alexander Duycke4911d52011-05-11 07:18:52 +00003876static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3877{
3878 struct ixgbe_hw *hw = &adapter->hw;
3879 struct hlist_node *node, *node2;
3880 struct ixgbe_fdir_filter *filter;
3881
3882 spin_lock(&adapter->fdir_perfect_lock);
3883
3884 if (!hlist_empty(&adapter->fdir_filter_list))
3885 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3886
3887 hlist_for_each_entry_safe(filter, node, node2,
3888 &adapter->fdir_filter_list, fdir_node) {
3889 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003890 &filter->filter,
3891 filter->sw_idx,
3892 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3893 IXGBE_FDIR_DROP_QUEUE :
3894 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003895 }
3896
3897 spin_unlock(&adapter->fdir_perfect_lock);
3898}
3899
Auke Kok9a799d72007-09-15 14:07:45 -07003900static void ixgbe_configure(struct ixgbe_adapter *adapter)
3901{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003902 struct ixgbe_hw *hw = &adapter->hw;
3903
John Fastabend80605c652011-05-02 12:34:10 +00003904 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003905#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003906 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003907#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00003908 /*
3909 * We must restore virtualization before VLANs or else
3910 * the VLVF registers will not be populated
3911 */
3912 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003913
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003914 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003915 ixgbe_restore_vlan(adapter);
3916
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003917 switch (hw->mac.type) {
3918 case ixgbe_mac_82599EB:
3919 case ixgbe_mac_X540:
3920 hw->mac.ops.disable_rx_buff(hw);
3921 break;
3922 default:
3923 break;
3924 }
3925
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003926 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003927 ixgbe_init_fdir_signature_82599(&adapter->hw,
3928 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003929 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3930 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3931 adapter->fdir_pballoc);
3932 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003933 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003934
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003935 switch (hw->mac.type) {
3936 case ixgbe_mac_82599EB:
3937 case ixgbe_mac_X540:
3938 hw->mac.ops.enable_rx_buff(hw);
3939 break;
3940 default:
3941 break;
3942 }
3943
Alexander Duyck7c8ae652012-05-05 05:32:47 +00003944#ifdef IXGBE_FCOE
3945 /* configure FCoE L2 filters, redirection table, and Rx control */
3946 ixgbe_configure_fcoe(adapter);
3947
3948#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07003949 ixgbe_configure_tx(adapter);
3950 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003951}
3952
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003953static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3954{
3955 switch (hw->phy.type) {
3956 case ixgbe_phy_sfp_avago:
3957 case ixgbe_phy_sfp_ftl:
3958 case ixgbe_phy_sfp_intel:
3959 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003960 case ixgbe_phy_sfp_passive_tyco:
3961 case ixgbe_phy_sfp_passive_unknown:
3962 case ixgbe_phy_sfp_active_unknown:
3963 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003964 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003965 case ixgbe_phy_nl:
3966 if (hw->mac.type == ixgbe_mac_82598EB)
3967 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003968 default:
3969 return false;
3970 }
3971}
3972
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003973/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003974 * ixgbe_sfp_link_config - set up SFP+ link
3975 * @adapter: pointer to private adapter struct
3976 **/
3977static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3978{
Alexander Duyck70864002011-04-27 09:13:56 +00003979 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003980 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003981 * is that an SFP was inserted/removed after the reset
3982 * but before SFP detection was enabled. As such the best
3983 * solution is to just start searching as soon as we start
3984 */
3985 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3986 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003987
Alexander Duyck70864002011-04-27 09:13:56 +00003988 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003989}
3990
3991/**
3992 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003993 * @hw: pointer to private hardware struct
3994 *
3995 * Returns 0 on success, negative on failure
3996 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003997static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003998{
3999 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004000 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004001 u32 ret = IXGBE_ERR_LINK_SETUP;
4002
4003 if (hw->mac.ops.check_link)
4004 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
4005
4006 if (ret)
4007 goto link_cfg_out;
4008
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00004009 autoneg = hw->phy.autoneg_advertised;
4010 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00004011 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
4012 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004013 if (ret)
4014 goto link_cfg_out;
4015
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004016 if (hw->mac.ops.setup_link)
4017 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004018link_cfg_out:
4019 return ret;
4020}
4021
Alexander Duycka34bcff2010-08-19 13:39:20 +00004022static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004023{
Auke Kok9a799d72007-09-15 14:07:45 -07004024 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004025 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004026
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004027 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004028 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4029 IXGBE_GPIE_OCD;
4030 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004031 /*
4032 * use EIAM to auto-mask when MSI-X interrupt is asserted
4033 * this saves a register write for every interrupt
4034 */
4035 switch (hw->mac.type) {
4036 case ixgbe_mac_82598EB:
4037 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4038 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004039 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004040 case ixgbe_mac_X540:
4041 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004042 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4043 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4044 break;
4045 }
4046 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004047 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4048 * specifically only auto mask tx and rx interrupts */
4049 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004050 }
4051
Alexander Duycka34bcff2010-08-19 13:39:20 +00004052 /* XXX: to interrupt immediately for EICS writes, enable this */
4053 /* gpie |= IXGBE_GPIE_EIMEN; */
4054
4055 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4056 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004057
4058 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4059 case IXGBE_82599_VMDQ_8Q_MASK:
4060 gpie |= IXGBE_GPIE_VTMODE_16;
4061 break;
4062 case IXGBE_82599_VMDQ_4Q_MASK:
4063 gpie |= IXGBE_GPIE_VTMODE_32;
4064 break;
4065 default:
4066 gpie |= IXGBE_GPIE_VTMODE_64;
4067 break;
4068 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004069 }
4070
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004071 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004072 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4073 switch (adapter->hw.mac.type) {
4074 case ixgbe_mac_82599EB:
4075 gpie |= IXGBE_SDP0_GPIEN;
4076 break;
4077 case ixgbe_mac_X540:
4078 gpie |= IXGBE_EIMS_TS;
4079 break;
4080 default:
4081 break;
4082 }
4083 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004084
Alexander Duycka34bcff2010-08-19 13:39:20 +00004085 /* Enable fan failure interrupt */
4086 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004087 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004088
Don Skidmore2698b202011-04-13 07:01:52 +00004089 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004090 gpie |= IXGBE_SDP1_GPIEN;
4091 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004092 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004093
4094 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4095}
4096
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004097static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004098{
4099 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004100 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004101 u32 ctrl_ext;
4102
4103 ixgbe_get_hw_control(adapter);
4104 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004105
Auke Kok9a799d72007-09-15 14:07:45 -07004106 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4107 ixgbe_configure_msix(adapter);
4108 else
4109 ixgbe_configure_msi_and_legacy(adapter);
4110
Emil Tantilovec74a472012-09-20 03:33:56 +00004111 /* enable the optics for 82599 SFP+ fiber */
4112 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004113 hw->mac.ops.enable_tx_laser(hw);
4114
Auke Kok9a799d72007-09-15 14:07:45 -07004115 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004116 ixgbe_napi_enable_all(adapter);
4117
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004118 if (ixgbe_is_sfp(hw)) {
4119 ixgbe_sfp_link_config(adapter);
4120 } else {
4121 err = ixgbe_non_sfp_link_config(hw);
4122 if (err)
4123 e_err(probe, "link_config FAILED %d\n", err);
4124 }
4125
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004126 /* clear any pending interrupts, may auto mask */
4127 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004128 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004129
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004130 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004131 * If this adapter has a fan, check to see if we had a failure
4132 * before we enabled the interrupt.
4133 */
4134 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4135 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4136 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004137 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004138 }
4139
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004140 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004141 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004142
Auke Kok9a799d72007-09-15 14:07:45 -07004143 /* bring the link up in the watchdog, this could race with our first
4144 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004145 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4146 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004147 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004148
4149 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4150 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4151 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4152 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004153}
4154
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004155void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4156{
4157 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004158 /* put off any impending NetWatchDogTimeout */
4159 adapter->netdev->trans_start = jiffies;
4160
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004161 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004162 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004163 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004164 /*
4165 * If SR-IOV enabled then wait a bit before bringing the adapter
4166 * back up to give the VFs time to respond to the reset. The
4167 * two second wait is based upon the watchdog timer cycle in
4168 * the VF driver.
4169 */
4170 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4171 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004172 ixgbe_up(adapter);
4173 clear_bit(__IXGBE_RESETTING, &adapter->state);
4174}
4175
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004176void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004177{
4178 /* hardware has been reset, we need to reload some things */
4179 ixgbe_configure(adapter);
4180
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004181 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004182}
4183
4184void ixgbe_reset(struct ixgbe_adapter *adapter)
4185{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004186 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004187 int err;
4188
Alexander Duyck70864002011-04-27 09:13:56 +00004189 /* lock SFP init bit to prevent race conditions with the watchdog */
4190 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4191 usleep_range(1000, 2000);
4192
4193 /* clear all SFP and link config related flags while holding SFP_INIT */
4194 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4195 IXGBE_FLAG2_SFP_NEEDS_RESET);
4196 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4197
Don Skidmore8ca783a2009-05-26 20:40:47 -07004198 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004199 switch (err) {
4200 case 0:
4201 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004202 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004203 break;
4204 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004205 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004206 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004207 case IXGBE_ERR_EEPROM_VERSION:
4208 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004209 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004210 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004211 "your hardware. If you are experiencing problems "
4212 "please contact your Intel or hardware "
4213 "representative who provided you with this "
4214 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004215 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004216 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004217 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004218 }
Auke Kok9a799d72007-09-15 14:07:45 -07004219
Alexander Duyck70864002011-04-27 09:13:56 +00004220 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4221
Auke Kok9a799d72007-09-15 14:07:45 -07004222 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004223 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004224
4225 /* update SAN MAC vmdq pool selection */
4226 if (hw->mac.san_mac_rar_index)
4227 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004228
Jacob Keller1a71ab22012-08-25 03:54:19 +00004229 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4230 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004231}
4232
Auke Kok9a799d72007-09-15 14:07:45 -07004233/**
4234 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004235 * @rx_ring: ring to free buffers from
4236 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004237static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004238{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004239 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004240 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004241 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004242
Alexander Duyck84418e32010-08-19 13:40:54 +00004243 /* ring already cleared, nothing to do */
4244 if (!rx_ring->rx_buffer_info)
4245 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004246
Alexander Duyck84418e32010-08-19 13:40:54 +00004247 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004248 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004249 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004250
Alexander Duyckf8003262012-03-03 02:35:52 +00004251 rx_buffer = &rx_ring->rx_buffer_info[i];
4252 if (rx_buffer->skb) {
4253 struct sk_buff *skb = rx_buffer->skb;
4254 if (IXGBE_CB(skb)->page_released) {
4255 dma_unmap_page(dev,
4256 IXGBE_CB(skb)->dma,
4257 ixgbe_rx_bufsz(rx_ring),
4258 DMA_FROM_DEVICE);
4259 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004260 }
4261 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004262 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004263 rx_buffer->skb = NULL;
4264 if (rx_buffer->dma)
4265 dma_unmap_page(dev, rx_buffer->dma,
4266 ixgbe_rx_pg_size(rx_ring),
4267 DMA_FROM_DEVICE);
4268 rx_buffer->dma = 0;
4269 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004270 __free_pages(rx_buffer->page,
4271 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004272 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004273 }
4274
4275 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4276 memset(rx_ring->rx_buffer_info, 0, size);
4277
4278 /* Zero out the descriptor ring */
4279 memset(rx_ring->desc, 0, rx_ring->size);
4280
Alexander Duyckf8003262012-03-03 02:35:52 +00004281 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004282 rx_ring->next_to_clean = 0;
4283 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004284}
4285
4286/**
4287 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004288 * @tx_ring: ring to be cleaned
4289 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004290static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004291{
4292 struct ixgbe_tx_buffer *tx_buffer_info;
4293 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004294 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004295
Alexander Duyck84418e32010-08-19 13:40:54 +00004296 /* ring already cleared, nothing to do */
4297 if (!tx_ring->tx_buffer_info)
4298 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004299
Alexander Duyck84418e32010-08-19 13:40:54 +00004300 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004301 for (i = 0; i < tx_ring->count; i++) {
4302 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004303 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004304 }
4305
John Fastabenddad8a3b2012-04-23 12:22:39 +00004306 netdev_tx_reset_queue(txring_txq(tx_ring));
4307
Auke Kok9a799d72007-09-15 14:07:45 -07004308 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4309 memset(tx_ring->tx_buffer_info, 0, size);
4310
4311 /* Zero out the descriptor ring */
4312 memset(tx_ring->desc, 0, tx_ring->size);
4313
4314 tx_ring->next_to_use = 0;
4315 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004316}
4317
4318/**
Auke Kok9a799d72007-09-15 14:07:45 -07004319 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4320 * @adapter: board private structure
4321 **/
4322static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4323{
4324 int i;
4325
4326 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004327 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004328}
4329
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004330/**
4331 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4332 * @adapter: board private structure
4333 **/
4334static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4335{
4336 int i;
4337
4338 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004339 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004340}
4341
Alexander Duycke4911d52011-05-11 07:18:52 +00004342static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4343{
4344 struct hlist_node *node, *node2;
4345 struct ixgbe_fdir_filter *filter;
4346
4347 spin_lock(&adapter->fdir_perfect_lock);
4348
4349 hlist_for_each_entry_safe(filter, node, node2,
4350 &adapter->fdir_filter_list, fdir_node) {
4351 hlist_del(&filter->fdir_node);
4352 kfree(filter);
4353 }
4354 adapter->fdir_filter_count = 0;
4355
4356 spin_unlock(&adapter->fdir_perfect_lock);
4357}
4358
Auke Kok9a799d72007-09-15 14:07:45 -07004359void ixgbe_down(struct ixgbe_adapter *adapter)
4360{
4361 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004362 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004363 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004364 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004365
4366 /* signal that we are down to the interrupt handler */
4367 set_bit(__IXGBE_DOWN, &adapter->state);
4368
4369 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004370 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4371 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004372
Yi Zou2d39d572011-01-06 14:29:56 +00004373 /* disable all enabled rx queues */
4374 for (i = 0; i < adapter->num_rx_queues; i++)
4375 /* this call also flushes the previous write */
4376 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4377
Don Skidmore032b4322011-03-18 09:32:53 +00004378 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004379
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004380 netif_tx_stop_all_queues(netdev);
4381
Alexander Duyck70864002011-04-27 09:13:56 +00004382 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004383 netif_carrier_off(netdev);
4384 netif_tx_disable(netdev);
4385
4386 ixgbe_irq_disable(adapter);
4387
4388 ixgbe_napi_disable_all(adapter);
4389
Alexander Duyckd034acf2011-04-27 09:25:34 +00004390 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4391 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004392 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4393
4394 del_timer_sync(&adapter->service_timer);
4395
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004396 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004397 /* Clear EITR Select mapping */
4398 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4399
4400 /* Mark all the VFs as inactive */
4401 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004402 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004403
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004404 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004405 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004406
Auke Kok9a799d72007-09-15 14:07:45 -07004407 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004408 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004409 }
4410
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004411 /* disable transmits in the hardware now that interrupts are off */
4412 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004413 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004414 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004415 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004416
4417 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004418 switch (hw->mac.type) {
4419 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004420 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004421 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004422 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4423 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004424 break;
4425 default:
4426 break;
4427 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004428
Paul Larson6f4a0e42008-06-24 17:00:56 -07004429 if (!pci_channel_offline(adapter->pdev))
4430 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004431
Emil Tantilovec74a472012-09-20 03:33:56 +00004432 /* power down the optics for 82599 SFP+ fiber */
4433 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004434 hw->mac.ops.disable_tx_laser(hw);
4435
Auke Kok9a799d72007-09-15 14:07:45 -07004436 ixgbe_clean_all_tx_rings(adapter);
4437 ixgbe_clean_all_rx_rings(adapter);
4438
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004439#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004440 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004441 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004442#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004443}
4444
Auke Kok9a799d72007-09-15 14:07:45 -07004445/**
Auke Kok9a799d72007-09-15 14:07:45 -07004446 * ixgbe_tx_timeout - Respond to a Tx Hang
4447 * @netdev: network interface device structure
4448 **/
4449static void ixgbe_tx_timeout(struct net_device *netdev)
4450{
4451 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4452
4453 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004454 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004455}
4456
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004457/**
Auke Kok9a799d72007-09-15 14:07:45 -07004458 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4459 * @adapter: board private structure to initialize
4460 *
4461 * ixgbe_sw_init initializes the Adapter private data structure.
4462 * Fields are initialized based on PCI device information and
4463 * OS network device settings (MTU size).
4464 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004465static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004466{
4467 struct ixgbe_hw *hw = &adapter->hw;
4468 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004469 unsigned int rss;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004470 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004471#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004472 int j;
4473 struct tc_configuration *tc;
4474#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004475
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004476 /* PCI config space info */
4477
4478 hw->vendor_id = pdev->vendor;
4479 hw->device_id = pdev->device;
4480 hw->revision_id = pdev->revision;
4481 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4482 hw->subsystem_device_id = pdev->subsystem_device;
4483
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004484 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004485 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004486 adapter->ring_feature[RING_F_RSS].limit = rss;
Alexander Duyckbd508172010-11-16 19:27:03 -08004487 switch (hw->mac.type) {
4488 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004489 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4490 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004491 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004492 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004493 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004494 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
4495 if (fwsm & IXGBE_FWSM_TS_ENABLED)
4496 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Jacob Keller4f51bf72011-08-20 04:49:45 +00004497 case ixgbe_mac_82599EB:
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004498 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004499 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4500 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004501 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4502 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004503 /* Flow Director hash filters enabled */
Alexander Duyck45b9f502011-01-06 14:29:59 +00004504 adapter->atr_sample_rate = 20;
Alexander Duyckc0876632012-05-10 00:01:46 +00004505 adapter->ring_feature[RING_F_FDIR].limit =
Joe Perchese8e9f692010-09-07 21:34:53 +00004506 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004507 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004508#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004509 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4510 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
Yi Zou61a0f422009-12-03 11:32:22 +00004511#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004512 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004513 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004514#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004515#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004516 break;
4517 default:
4518 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004519 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004520
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004521#ifdef IXGBE_FCOE
4522 /* FCoE support exists, always init the FCoE lock */
4523 spin_lock_init(&adapter->fcoe.lock);
4524
4525#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004526 /* n-tuple support exists, always init our spinlock */
4527 spin_lock_init(&adapter->fdir_perfect_lock);
4528
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004529#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004530 switch (hw->mac.type) {
4531 case ixgbe_mac_X540:
4532 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4533 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4534 break;
4535 default:
4536 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4537 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4538 break;
4539 }
4540
Alexander Duyck2f90b862008-11-20 20:52:10 -08004541 /* Configure DCB traffic classes */
4542 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4543 tc = &adapter->dcb_cfg.tc_config[j];
4544 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4545 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4546 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4547 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4548 tc->dcb_pfc = pfc_disabled;
4549 }
John Fastabend4de2a022011-09-27 03:52:01 +00004550
4551 /* Initialize default user to priority mapping, UPx->TC0 */
4552 tc = &adapter->dcb_cfg.tc_config[0];
4553 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4554 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4555
Alexander Duyck2f90b862008-11-20 20:52:10 -08004556 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4557 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004558 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004559 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004560 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004561 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4562 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004563
4564#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004565
4566 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004567 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004568 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004569 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004570 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4571 hw->fc.send_xon = true;
Jacob Kellerdb2adc22012-10-24 07:26:02 +00004572 hw->fc.disable_fc_autoneg =
4573 (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
Auke Kok9a799d72007-09-15 14:07:45 -07004574
Alexander Duyck99d74482012-05-09 08:09:25 +00004575#ifdef CONFIG_PCI_IOV
4576 /* assign number of SR-IOV VFs */
4577 if (hw->mac.type != ixgbe_mac_82598EB)
4578 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4579
4580#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004581 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004582 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004583 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004584
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004585 /* set default ring sizes */
4586 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4587 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4588
Alexander Duyckbd198052011-06-11 01:45:08 +00004589 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004590 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004591
Auke Kok9a799d72007-09-15 14:07:45 -07004592 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004593 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004594 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004595 return -EIO;
4596 }
4597
Auke Kok9a799d72007-09-15 14:07:45 -07004598 set_bit(__IXGBE_DOWN, &adapter->state);
4599
4600 return 0;
4601}
4602
4603/**
4604 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004605 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004606 *
4607 * Return 0 on success, negative on failure
4608 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004609int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004610{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004611 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004612 int orig_node = dev_to_node(dev);
4613 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004614 int size;
4615
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004616 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004617
4618 if (tx_ring->q_vector)
4619 numa_node = tx_ring->q_vector->numa_node;
4620
4621 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004622 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004623 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004624 if (!tx_ring->tx_buffer_info)
4625 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004626
4627 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004628 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004629 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004630
Alexander Duyckde88eee2012-02-08 07:49:59 +00004631 set_dev_node(dev, numa_node);
4632 tx_ring->desc = dma_alloc_coherent(dev,
4633 tx_ring->size,
4634 &tx_ring->dma,
4635 GFP_KERNEL);
4636 set_dev_node(dev, orig_node);
4637 if (!tx_ring->desc)
4638 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4639 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004640 if (!tx_ring->desc)
4641 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004642
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004643 tx_ring->next_to_use = 0;
4644 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004645 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004646
4647err:
4648 vfree(tx_ring->tx_buffer_info);
4649 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004650 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004651 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004652}
4653
4654/**
Alexander Duyck69888672008-09-11 20:05:39 -07004655 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4656 * @adapter: board private structure
4657 *
4658 * If this function returns with an error, then it's possible one or
4659 * more of the rings is populated (while the rest are not). It is the
4660 * callers duty to clean those orphaned rings.
4661 *
4662 * Return 0 on success, negative on failure
4663 **/
4664static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4665{
4666 int i, err = 0;
4667
4668 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004669 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004670 if (!err)
4671 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004672
Emil Tantilov396e7992010-07-01 20:05:12 +00004673 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004674 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004675 }
4676
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004677 return 0;
4678err_setup_tx:
4679 /* rewind the index freeing the rings as we go */
4680 while (i--)
4681 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004682 return err;
4683}
4684
4685/**
Auke Kok9a799d72007-09-15 14:07:45 -07004686 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004687 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004688 *
4689 * Returns 0 on success, negative on failure
4690 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004691int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004692{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004693 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004694 int orig_node = dev_to_node(dev);
4695 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004696 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004697
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004698 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004699
4700 if (rx_ring->q_vector)
4701 numa_node = rx_ring->q_vector->numa_node;
4702
4703 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004704 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004705 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004706 if (!rx_ring->rx_buffer_info)
4707 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004708
Auke Kok9a799d72007-09-15 14:07:45 -07004709 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004710 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4711 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004712
Alexander Duyckde88eee2012-02-08 07:49:59 +00004713 set_dev_node(dev, numa_node);
4714 rx_ring->desc = dma_alloc_coherent(dev,
4715 rx_ring->size,
4716 &rx_ring->dma,
4717 GFP_KERNEL);
4718 set_dev_node(dev, orig_node);
4719 if (!rx_ring->desc)
4720 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4721 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004722 if (!rx_ring->desc)
4723 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004724
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004725 rx_ring->next_to_clean = 0;
4726 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004727
4728 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004729err:
4730 vfree(rx_ring->rx_buffer_info);
4731 rx_ring->rx_buffer_info = NULL;
4732 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004733 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004734}
4735
4736/**
Alexander Duyck69888672008-09-11 20:05:39 -07004737 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4738 * @adapter: board private structure
4739 *
4740 * If this function returns with an error, then it's possible one or
4741 * more of the rings is populated (while the rest are not). It is the
4742 * callers duty to clean those orphaned rings.
4743 *
4744 * Return 0 on success, negative on failure
4745 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004746static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4747{
4748 int i, err = 0;
4749
4750 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004751 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004752 if (!err)
4753 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004754
Emil Tantilov396e7992010-07-01 20:05:12 +00004755 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004756 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004757 }
4758
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004759#ifdef IXGBE_FCOE
4760 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4761 if (!err)
4762#endif
4763 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004764err_setup_rx:
4765 /* rewind the index freeing the rings as we go */
4766 while (i--)
4767 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004768 return err;
4769}
4770
4771/**
Auke Kok9a799d72007-09-15 14:07:45 -07004772 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004773 * @tx_ring: Tx descriptor ring for a specific queue
4774 *
4775 * Free all transmit software resources
4776 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004777void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004778{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004779 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004780
4781 vfree(tx_ring->tx_buffer_info);
4782 tx_ring->tx_buffer_info = NULL;
4783
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004784 /* if not set, then don't free */
4785 if (!tx_ring->desc)
4786 return;
4787
4788 dma_free_coherent(tx_ring->dev, tx_ring->size,
4789 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004790
4791 tx_ring->desc = NULL;
4792}
4793
4794/**
4795 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4796 * @adapter: board private structure
4797 *
4798 * Free all transmit software resources
4799 **/
4800static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4801{
4802 int i;
4803
4804 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004805 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004806 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004807}
4808
4809/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004810 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004811 * @rx_ring: ring to clean the resources from
4812 *
4813 * Free all receive software resources
4814 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004815void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004816{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004817 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004818
4819 vfree(rx_ring->rx_buffer_info);
4820 rx_ring->rx_buffer_info = NULL;
4821
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004822 /* if not set, then don't free */
4823 if (!rx_ring->desc)
4824 return;
4825
4826 dma_free_coherent(rx_ring->dev, rx_ring->size,
4827 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004828
4829 rx_ring->desc = NULL;
4830}
4831
4832/**
4833 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4834 * @adapter: board private structure
4835 *
4836 * Free all receive software resources
4837 **/
4838static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4839{
4840 int i;
4841
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004842#ifdef IXGBE_FCOE
4843 ixgbe_free_fcoe_ddp_resources(adapter);
4844
4845#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004846 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004847 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004848 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004849}
4850
4851/**
Auke Kok9a799d72007-09-15 14:07:45 -07004852 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4853 * @netdev: network interface device structure
4854 * @new_mtu: new value for maximum frame size
4855 *
4856 * Returns 0 on success, negative on failure
4857 **/
4858static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4859{
4860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4861 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4862
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004863 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004864 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4865 return -EINVAL;
4866
4867 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00004868 * For 82599EB we cannot allow legacy VFs to enable their receive
4869 * paths when MTU greater than 1500 is configured. So display a
4870 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00004871 */
4872 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4873 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4874 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Alexander Duyck872844d2012-08-15 02:10:43 +00004875 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004876
Emil Tantilov396e7992010-07-01 20:05:12 +00004877 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004878
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004879 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004880 netdev->mtu = new_mtu;
4881
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004882 if (netif_running(netdev))
4883 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004884
4885 return 0;
4886}
4887
4888/**
4889 * ixgbe_open - Called when a network interface is made active
4890 * @netdev: network interface device structure
4891 *
4892 * Returns 0 on success, negative value on failure
4893 *
4894 * The open entry point is called when a network interface is made
4895 * active by the system (IFF_UP). At this point all resources needed
4896 * for transmit and receive operations are allocated, the interrupt
4897 * handler is registered with the OS, the watchdog timer is started,
4898 * and the stack is notified that the interface is ready.
4899 **/
4900static int ixgbe_open(struct net_device *netdev)
4901{
4902 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4903 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004904
Auke Kok4bebfaa2008-02-11 09:26:01 -08004905 /* disallow open during test */
4906 if (test_bit(__IXGBE_TESTING, &adapter->state))
4907 return -EBUSY;
4908
Jesse Brandeburg54386462009-04-17 20:44:27 +00004909 netif_carrier_off(netdev);
4910
Auke Kok9a799d72007-09-15 14:07:45 -07004911 /* allocate transmit descriptors */
4912 err = ixgbe_setup_all_tx_resources(adapter);
4913 if (err)
4914 goto err_setup_tx;
4915
Auke Kok9a799d72007-09-15 14:07:45 -07004916 /* allocate receive descriptors */
4917 err = ixgbe_setup_all_rx_resources(adapter);
4918 if (err)
4919 goto err_setup_rx;
4920
4921 ixgbe_configure(adapter);
4922
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004923 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004924 if (err)
4925 goto err_req_irq;
4926
Alexander Duyckac802f52012-07-12 05:52:53 +00004927 /* Notify the stack of the actual queue counts. */
4928 err = netif_set_real_num_tx_queues(netdev,
4929 adapter->num_rx_pools > 1 ? 1 :
4930 adapter->num_tx_queues);
4931 if (err)
4932 goto err_set_queues;
4933
4934
4935 err = netif_set_real_num_rx_queues(netdev,
4936 adapter->num_rx_pools > 1 ? 1 :
4937 adapter->num_rx_queues);
4938 if (err)
4939 goto err_set_queues;
4940
Jacob Keller1a71ab22012-08-25 03:54:19 +00004941 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004942
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004943 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004944
4945 return 0;
4946
Alexander Duyckac802f52012-07-12 05:52:53 +00004947err_set_queues:
4948 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004949err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004950 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004951err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004952 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004953err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07004954 ixgbe_reset(adapter);
4955
4956 return err;
4957}
4958
4959/**
4960 * ixgbe_close - Disables a network interface
4961 * @netdev: network interface device structure
4962 *
4963 * Returns 0, this is not allowed to fail
4964 *
4965 * The close entry point is called when an interface is de-activated
4966 * by the OS. The hardware is still under the drivers control, but
4967 * needs to be disabled. A global MAC reset is issued to stop the
4968 * hardware, and all transmit and receive resources are freed.
4969 **/
4970static int ixgbe_close(struct net_device *netdev)
4971{
4972 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004973
Jacob Keller1a71ab22012-08-25 03:54:19 +00004974 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004975
Auke Kok9a799d72007-09-15 14:07:45 -07004976 ixgbe_down(adapter);
4977 ixgbe_free_irq(adapter);
4978
Alexander Duycke4911d52011-05-11 07:18:52 +00004979 ixgbe_fdir_filter_exit(adapter);
4980
Auke Kok9a799d72007-09-15 14:07:45 -07004981 ixgbe_free_all_tx_resources(adapter);
4982 ixgbe_free_all_rx_resources(adapter);
4983
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004984 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004985
4986 return 0;
4987}
4988
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004989#ifdef CONFIG_PM
4990static int ixgbe_resume(struct pci_dev *pdev)
4991{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004992 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4993 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004994 u32 err;
4995
4996 pci_set_power_state(pdev, PCI_D0);
4997 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004998 /*
4999 * pci_restore_state clears dev->state_saved so call
5000 * pci_save_state to restore it.
5001 */
5002 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005003
5004 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005005 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005006 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005007 return err;
5008 }
5009 pci_set_master(pdev);
5010
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005011 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005012
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005013 ixgbe_reset(adapter);
5014
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005015 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5016
Alexander Duyckac802f52012-07-12 05:52:53 +00005017 rtnl_lock();
5018 err = ixgbe_init_interrupt_scheme(adapter);
5019 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005020 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005021
5022 rtnl_unlock();
5023
5024 if (err)
5025 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005026
5027 netif_device_attach(netdev);
5028
5029 return 0;
5030}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005031#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005032
5033static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005034{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005035 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5036 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005037 struct ixgbe_hw *hw = &adapter->hw;
5038 u32 ctrl, fctrl;
5039 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005040#ifdef CONFIG_PM
5041 int retval = 0;
5042#endif
5043
5044 netif_device_detach(netdev);
5045
5046 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00005047 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005048 ixgbe_down(adapter);
5049 ixgbe_free_irq(adapter);
5050 ixgbe_free_all_tx_resources(adapter);
5051 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00005052 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005053 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005054
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005055 ixgbe_clear_interrupt_scheme(adapter);
5056
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005057#ifdef CONFIG_PM
5058 retval = pci_save_state(pdev);
5059 if (retval)
5060 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005061
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005062#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005063 if (wufc) {
5064 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005065
Emil Tantilovec74a472012-09-20 03:33:56 +00005066 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5067 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005068 hw->mac.ops.enable_tx_laser(hw);
5069
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005070 /* turn on all-multi mode if wake on multicast is enabled */
5071 if (wufc & IXGBE_WUFC_MC) {
5072 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5073 fctrl |= IXGBE_FCTRL_MPE;
5074 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5075 }
5076
5077 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5078 ctrl |= IXGBE_CTRL_GIO_DIS;
5079 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5080
5081 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5082 } else {
5083 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5084 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5085 }
5086
Alexander Duyckbd508172010-11-16 19:27:03 -08005087 switch (hw->mac.type) {
5088 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005089 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005090 break;
5091 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005092 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005093 pci_wake_from_d3(pdev, !!wufc);
5094 break;
5095 default:
5096 break;
5097 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005098
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005099 *enable_wake = !!wufc;
5100
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005101 ixgbe_release_hw_control(adapter);
5102
5103 pci_disable_device(pdev);
5104
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005105 return 0;
5106}
5107
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005108#ifdef CONFIG_PM
5109static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5110{
5111 int retval;
5112 bool wake;
5113
5114 retval = __ixgbe_shutdown(pdev, &wake);
5115 if (retval)
5116 return retval;
5117
5118 if (wake) {
5119 pci_prepare_to_sleep(pdev);
5120 } else {
5121 pci_wake_from_d3(pdev, false);
5122 pci_set_power_state(pdev, PCI_D3hot);
5123 }
5124
5125 return 0;
5126}
5127#endif /* CONFIG_PM */
5128
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005129static void ixgbe_shutdown(struct pci_dev *pdev)
5130{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005131 bool wake;
5132
5133 __ixgbe_shutdown(pdev, &wake);
5134
5135 if (system_state == SYSTEM_POWER_OFF) {
5136 pci_wake_from_d3(pdev, wake);
5137 pci_set_power_state(pdev, PCI_D3hot);
5138 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005139}
5140
5141/**
Auke Kok9a799d72007-09-15 14:07:45 -07005142 * ixgbe_update_stats - Update the board statistics counters.
5143 * @adapter: board private structure
5144 **/
5145void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5146{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005147 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005148 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005149 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005150 u64 total_mpc = 0;
5151 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005152 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5153 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005154 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005155
Don Skidmored08935c2010-06-11 13:20:29 +00005156 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5157 test_bit(__IXGBE_RESETTING, &adapter->state))
5158 return;
5159
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005160 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005161 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005162 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005163 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005164 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5165 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005166 }
5167 adapter->rsc_total_count = rsc_count;
5168 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005169 }
5170
Alexander Duyck5b7da512010-11-16 19:26:50 -08005171 for (i = 0; i < adapter->num_rx_queues; i++) {
5172 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5173 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5174 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5175 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005176 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005177 bytes += rx_ring->stats.bytes;
5178 packets += rx_ring->stats.packets;
5179 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005180 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005181 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5182 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005183 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005184 netdev->stats.rx_bytes = bytes;
5185 netdev->stats.rx_packets = packets;
5186
5187 bytes = 0;
5188 packets = 0;
5189 /* gather some stats to the adapter struct that are per queue */
5190 for (i = 0; i < adapter->num_tx_queues; i++) {
5191 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5192 restart_queue += tx_ring->tx_stats.restart_queue;
5193 tx_busy += tx_ring->tx_stats.tx_busy;
5194 bytes += tx_ring->stats.bytes;
5195 packets += tx_ring->stats.packets;
5196 }
5197 adapter->restart_queue = restart_queue;
5198 adapter->tx_busy = tx_busy;
5199 netdev->stats.tx_bytes = bytes;
5200 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005201
Joe Perches7ca647b2010-09-07 21:35:40 +00005202 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005203
5204 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005205 for (i = 0; i < 8; i++) {
5206 /* for packet buffers not used, the register should read 0 */
5207 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5208 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005209 hwstats->mpc[i] += mpc;
5210 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005211 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5212 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005213 switch (hw->mac.type) {
5214 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005215 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5216 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5217 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005218 hwstats->pxonrxc[i] +=
5219 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005220 break;
5221 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005222 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005223 hwstats->pxonrxc[i] +=
5224 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005225 break;
5226 default:
5227 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005228 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005229 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005230
5231 /*16 register reads */
5232 for (i = 0; i < 16; i++) {
5233 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5234 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5235 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5236 (hw->mac.type == ixgbe_mac_X540)) {
5237 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5238 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5239 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5240 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5241 }
5242 }
5243
Joe Perches7ca647b2010-09-07 21:35:40 +00005244 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005245 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005246 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005247
John Fastabendc84d3242010-11-16 19:27:12 -08005248 ixgbe_update_xoff_received(adapter);
5249
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005250 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005251 switch (hw->mac.type) {
5252 case ixgbe_mac_82598EB:
5253 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005254 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5255 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5256 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5257 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005258 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005259 /* OS2BMC stats are X540 only*/
5260 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5261 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5262 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5263 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5264 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005265 for (i = 0; i < 16; i++)
5266 adapter->hw_rx_no_dma_resources +=
5267 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005268 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005269 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005270 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005271 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005272 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005273 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005274 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005275 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5276 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005277#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005278 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5279 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5280 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5281 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5282 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5283 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005284 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005285 if (adapter->fcoe.ddp_pool) {
5286 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5287 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5288 unsigned int cpu;
5289 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005290 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005291 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5292 noddp += ddp_pool->noddp;
5293 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005294 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005295 hwstats->fcoe_noddp = noddp;
5296 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005297 }
Yi Zou6d455222009-05-13 13:12:16 +00005298#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005299 break;
5300 default:
5301 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005302 }
Auke Kok9a799d72007-09-15 14:07:45 -07005303 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005304 hwstats->bprc += bprc;
5305 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005306 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005307 hwstats->mprc -= bprc;
5308 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5309 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5310 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5311 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5312 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5313 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5314 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5315 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005316 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005317 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005318 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005319 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005320 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5321 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005322 /*
5323 * 82598 errata - tx of flow control packets is included in tx counters
5324 */
5325 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005326 hwstats->gptc -= xon_off_tot;
5327 hwstats->mptc -= xon_off_tot;
5328 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5329 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5330 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5331 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5332 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5333 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5334 hwstats->ptc64 -= xon_off_tot;
5335 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5336 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5337 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5338 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5339 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5340 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005341
5342 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005343 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005344
5345 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005346 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005347 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005348 netdev->stats.rx_length_errors = hwstats->rlec;
5349 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005350 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005351}
5352
5353/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005354 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005355 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005356 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005357static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005358{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005359 struct ixgbe_hw *hw = &adapter->hw;
5360 int i;
5361
Alexander Duyckd034acf2011-04-27 09:25:34 +00005362 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5363 return;
5364
5365 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5366
5367 /* if interface is down do nothing */
5368 if (test_bit(__IXGBE_DOWN, &adapter->state))
5369 return;
5370
5371 /* do nothing if we are not using signature filters */
5372 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5373 return;
5374
5375 adapter->fdir_overflow++;
5376
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005377 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5378 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005379 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005380 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005381 /* re-enable flow director interrupts */
5382 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005383 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005384 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005385 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005386 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005387}
5388
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005389/**
5390 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005391 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005392 *
5393 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005394 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005395 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005396 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005397 */
5398static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5399{
Auke Kok9a799d72007-09-15 14:07:45 -07005400 struct ixgbe_hw *hw = &adapter->hw;
5401 u64 eics = 0;
5402 int i;
5403
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005404 /* If we're down or resetting, just bail */
5405 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5406 test_bit(__IXGBE_RESETTING, &adapter->state))
5407 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005408
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005409 /* Force detection of hung controller */
5410 if (netif_carrier_ok(adapter->netdev)) {
5411 for (i = 0; i < adapter->num_tx_queues; i++)
5412 set_check_for_tx_hang(adapter->tx_ring[i]);
5413 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005414
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005415 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005416 /*
5417 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005418 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005419 * would set *both* EIMS and EICS for any bit in EIAM
5420 */
5421 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5422 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005423 } else {
5424 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005425 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005426 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005427 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005428 eics |= ((u64)1 << i);
5429 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005430 }
5431
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005432 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005433 ixgbe_irq_rearm_queues(adapter, eics);
5434
Alexander Duyckfe49f042009-06-04 16:00:09 +00005435}
5436
5437/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005438 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005439 * @adapter: pointer to the device adapter structure
5440 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005441 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005442static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005443{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005444 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005445 u32 link_speed = adapter->link_speed;
5446 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005447 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005448
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005449 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5450 return;
5451
5452 if (hw->mac.ops.check_link) {
5453 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005454 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005455 /* always assume link is up, if no check link function */
5456 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5457 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005458 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005459
5460 if (adapter->ixgbe_ieee_pfc)
5461 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5462
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005463 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005464 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005465 ixgbe_set_rx_drop_en(adapter);
5466 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005467
5468 if (link_up ||
5469 time_after(jiffies, (adapter->link_check_timeout +
5470 IXGBE_TRY_LINK_TIMEOUT))) {
5471 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5472 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5473 IXGBE_WRITE_FLUSH(hw);
5474 }
5475
5476 adapter->link_up = link_up;
5477 adapter->link_speed = link_speed;
5478}
5479
Alexander Duyck107d3012012-10-02 00:17:03 +00005480static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5481{
5482#ifdef CONFIG_IXGBE_DCB
5483 struct net_device *netdev = adapter->netdev;
5484 struct dcb_app app = {
5485 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5486 .protocol = 0,
5487 };
5488 u8 up = 0;
5489
5490 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5491 up = dcb_ieee_getapp_mask(netdev, &app);
5492
5493 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5494#endif
5495}
5496
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005497/**
5498 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5499 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005500 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005501 **/
5502static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5503{
5504 struct net_device *netdev = adapter->netdev;
5505 struct ixgbe_hw *hw = &adapter->hw;
5506 u32 link_speed = adapter->link_speed;
5507 bool flow_rx, flow_tx;
5508
5509 /* only continue if link was previously down */
5510 if (netif_carrier_ok(netdev))
5511 return;
5512
5513 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5514
5515 switch (hw->mac.type) {
5516 case ixgbe_mac_82598EB: {
5517 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5518 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5519 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5520 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5521 }
5522 break;
5523 case ixgbe_mac_X540:
5524 case ixgbe_mac_82599EB: {
5525 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5526 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5527 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5528 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5529 }
5530 break;
5531 default:
5532 flow_tx = false;
5533 flow_rx = false;
5534 break;
5535 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005536
Jacob Keller1a71ab22012-08-25 03:54:19 +00005537 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5538 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005539
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005540 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5541 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5542 "10 Gbps" :
5543 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5544 "1 Gbps" :
5545 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5546 "100 Mbps" :
5547 "unknown speed"))),
5548 ((flow_rx && flow_tx) ? "RX/TX" :
5549 (flow_rx ? "RX" :
5550 (flow_tx ? "TX" : "None"))));
5551
5552 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005553 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005554
Alexander Duyck107d3012012-10-02 00:17:03 +00005555 /* update the default user priority for VFs */
5556 ixgbe_update_default_up(adapter);
5557
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005558 /* ping all the active vfs to let them know link has changed */
5559 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005560}
5561
5562/**
5563 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5564 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005565 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005566 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005567static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005568{
5569 struct net_device *netdev = adapter->netdev;
5570 struct ixgbe_hw *hw = &adapter->hw;
5571
5572 adapter->link_up = false;
5573 adapter->link_speed = 0;
5574
5575 /* only continue if link was up previously */
5576 if (!netif_carrier_ok(netdev))
5577 return;
5578
5579 /* poll for SFP+ cable when link is down */
5580 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5581 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5582
Jacob Keller1a71ab22012-08-25 03:54:19 +00005583 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5584 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005585
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005586 e_info(drv, "NIC Link is Down\n");
5587 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005588
5589 /* ping all the active vfs to let them know link has changed */
5590 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005591}
5592
5593/**
5594 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005595 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005596 **/
5597static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5598{
5599 int i;
5600 int some_tx_pending = 0;
5601
5602 if (!netif_carrier_ok(adapter->netdev)) {
5603 for (i = 0; i < adapter->num_tx_queues; i++) {
5604 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5605 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5606 some_tx_pending = 1;
5607 break;
5608 }
5609 }
5610
5611 if (some_tx_pending) {
5612 /* We've lost link, so the controller stops DMA,
5613 * but we've got queued Tx work that's never going
5614 * to get done, so reset controller to flush Tx.
5615 * (Do the reset outside of interrupt context).
5616 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005617 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005618 }
5619 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005620}
5621
Greg Rosea985b6c32010-11-18 03:02:52 +00005622static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5623{
5624 u32 ssvpc;
5625
Greg Rose0584d992012-08-08 00:00:58 +00005626 /* Do not perform spoof check for 82598 or if not in IOV mode */
5627 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5628 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005629 return;
5630
5631 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5632
5633 /*
5634 * ssvpc register is cleared on read, if zero then no
5635 * spoofed packets in the last interval.
5636 */
5637 if (!ssvpc)
5638 return;
5639
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005640 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005641}
5642
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005643/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005644 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005645 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005646 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005647static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005648{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005649 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005650 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5651 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005652 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005653
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005654 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005655
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005656 if (adapter->link_up)
5657 ixgbe_watchdog_link_is_up(adapter);
5658 else
5659 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005660
Greg Rosea985b6c32010-11-18 03:02:52 +00005661 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005662 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005663
5664 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005665}
5666
Alexander Duyck70864002011-04-27 09:13:56 +00005667/**
5668 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005669 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005670 **/
5671static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5672{
5673 struct ixgbe_hw *hw = &adapter->hw;
5674 s32 err;
5675
5676 /* not searching for SFP so there is nothing to do here */
5677 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5678 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5679 return;
5680
5681 /* someone else is in init, wait until next service event */
5682 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5683 return;
5684
5685 err = hw->phy.ops.identify_sfp(hw);
5686 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5687 goto sfp_out;
5688
5689 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5690 /* If no cable is present, then we need to reset
5691 * the next time we find a good cable. */
5692 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5693 }
5694
5695 /* exit on error */
5696 if (err)
5697 goto sfp_out;
5698
5699 /* exit if reset not needed */
5700 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5701 goto sfp_out;
5702
5703 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5704
5705 /*
5706 * A module may be identified correctly, but the EEPROM may not have
5707 * support for that module. setup_sfp() will fail in that case, so
5708 * we should not allow that module to load.
5709 */
5710 if (hw->mac.type == ixgbe_mac_82598EB)
5711 err = hw->phy.ops.reset(hw);
5712 else
5713 err = hw->mac.ops.setup_sfp(hw);
5714
5715 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5716 goto sfp_out;
5717
5718 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5719 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5720
5721sfp_out:
5722 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5723
5724 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5725 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5726 e_dev_err("failed to initialize because an unsupported "
5727 "SFP+ module type was detected.\n");
5728 e_dev_err("Reload the driver after installing a "
5729 "supported module.\n");
5730 unregister_netdev(adapter->netdev);
5731 }
5732}
5733
5734/**
5735 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005736 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005737 **/
5738static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5739{
5740 struct ixgbe_hw *hw = &adapter->hw;
5741 u32 autoneg;
5742 bool negotiation;
5743
5744 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5745 return;
5746
5747 /* someone else is in init, wait until next service event */
5748 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5749 return;
5750
5751 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5752
5753 autoneg = hw->phy.autoneg_advertised;
5754 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5755 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005756 if (hw->mac.ops.setup_link)
5757 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5758
5759 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5760 adapter->link_check_timeout = jiffies;
5761 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5762}
5763
Greg Rose83c61fa2011-09-07 05:59:35 +00005764#ifdef CONFIG_PCI_IOV
5765static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5766{
5767 int vf;
5768 struct ixgbe_hw *hw = &adapter->hw;
5769 struct net_device *netdev = adapter->netdev;
5770 u32 gpc;
5771 u32 ciaa, ciad;
5772
5773 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5774 if (gpc) /* If incrementing then no need for the check below */
5775 return;
5776 /*
5777 * Check to see if a bad DMA write target from an errant or
5778 * malicious VF has caused a PCIe error. If so then we can
5779 * issue a VFLR to the offending VF(s) and then resume without
5780 * requesting a full slot reset.
5781 */
5782
5783 for (vf = 0; vf < adapter->num_vfs; vf++) {
5784 ciaa = (vf << 16) | 0x80000000;
5785 /* 32 bit read so align, we really want status at offset 6 */
5786 ciaa |= PCI_COMMAND;
5787 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5788 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5789 ciaa &= 0x7FFFFFFF;
5790 /* disable debug mode asap after reading data */
5791 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5792 /* Get the upper 16 bits which will be the PCI status reg */
5793 ciad >>= 16;
5794 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5795 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5796 /* Issue VFLR */
5797 ciaa = (vf << 16) | 0x80000000;
5798 ciaa |= 0xA8;
5799 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5800 ciad = 0x00008000; /* VFLR */
5801 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5802 ciaa &= 0x7FFFFFFF;
5803 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5804 }
5805 }
5806}
5807
5808#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005809/**
5810 * ixgbe_service_timer - Timer Call-back
5811 * @data: pointer to adapter cast into an unsigned long
5812 **/
5813static void ixgbe_service_timer(unsigned long data)
5814{
5815 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5816 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005817 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005818
5819 /* poll faster when waiting for link */
5820 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5821 next_event_offset = HZ / 10;
5822 else
5823 next_event_offset = HZ * 2;
5824
Greg Rose83c61fa2011-09-07 05:59:35 +00005825#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005826 /*
5827 * don't bother with SR-IOV VF DMA hang check if there are
5828 * no VFs or the link is down
5829 */
5830 if (!adapter->num_vfs ||
5831 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5832 goto normal_timer_service;
5833
5834 /* If we have VFs allocated then we must check for DMA hangs */
5835 ixgbe_check_for_bad_vf(adapter);
5836 next_event_offset = HZ / 50;
5837 adapter->timer_event_accumulator++;
5838
5839 if (adapter->timer_event_accumulator >= 100)
5840 adapter->timer_event_accumulator = 0;
5841 else
5842 ready = false;
5843
5844normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005845#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005846 /* Reset the timer */
5847 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5848
Greg Rose83c61fa2011-09-07 05:59:35 +00005849 if (ready)
5850 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005851}
5852
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005853static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5854{
5855 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5856 return;
5857
5858 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5859
5860 /* If we're already down or resetting, just bail */
5861 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5862 test_bit(__IXGBE_RESETTING, &adapter->state))
5863 return;
5864
5865 ixgbe_dump(adapter);
5866 netdev_err(adapter->netdev, "Reset adapter\n");
5867 adapter->tx_timeout_count++;
5868
5869 ixgbe_reinit_locked(adapter);
5870}
5871
Alexander Duyck70864002011-04-27 09:13:56 +00005872/**
5873 * ixgbe_service_task - manages and runs subtasks
5874 * @work: pointer to work_struct containing our data
5875 **/
5876static void ixgbe_service_task(struct work_struct *work)
5877{
5878 struct ixgbe_adapter *adapter = container_of(work,
5879 struct ixgbe_adapter,
5880 service_task);
5881
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005882 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005883 ixgbe_sfp_detection_subtask(adapter);
5884 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005885 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005886 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005887 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005888 ixgbe_check_hang_subtask(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005889 ixgbe_ptp_overflow_check(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005890
5891 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005892}
5893
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005894static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5895 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005896 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005897{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005898 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005899 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005900 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005901
Alexander Duyck897ab152011-05-27 05:31:47 +00005902 if (!skb_is_gso(skb))
5903 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005904
Alexander Duyck897ab152011-05-27 05:31:47 +00005905 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005906 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005907 if (err)
5908 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005909 }
5910
Alexander Duyck897ab152011-05-27 05:31:47 +00005911 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5912 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5913
Alexander Duyck244e27a2012-02-08 07:51:11 +00005914 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005915 struct iphdr *iph = ip_hdr(skb);
5916 iph->tot_len = 0;
5917 iph->check = 0;
5918 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5919 iph->daddr, 0,
5920 IPPROTO_TCP,
5921 0);
5922 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005923 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5924 IXGBE_TX_FLAGS_CSUM |
5925 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005926 } else if (skb_is_gso_v6(skb)) {
5927 ipv6_hdr(skb)->payload_len = 0;
5928 tcp_hdr(skb)->check =
5929 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5930 &ipv6_hdr(skb)->daddr,
5931 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005932 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5933 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005934 }
5935
Alexander Duyck091a6242012-02-08 07:51:01 +00005936 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005937 l4len = tcp_hdrlen(skb);
5938 *hdr_len = skb_transport_offset(skb) + l4len;
5939
Alexander Duyck091a6242012-02-08 07:51:01 +00005940 /* update gso size and bytecount with header size */
5941 first->gso_segs = skb_shinfo(skb)->gso_segs;
5942 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5943
Alexander Duyck897ab152011-05-27 05:31:47 +00005944 /* mss_l4len_id: use 1 as index for TSO */
5945 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5946 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5947 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5948
5949 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5950 vlan_macip_lens = skb_network_header_len(skb);
5951 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005952 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005953
5954 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005955 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005956
5957 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005958}
5959
Alexander Duyck244e27a2012-02-08 07:51:11 +00005960static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5961 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005962{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005963 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005964 u32 vlan_macip_lens = 0;
5965 u32 mss_l4len_idx = 0;
5966 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005967
Alexander Duyck897ab152011-05-27 05:31:47 +00005968 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck62748b72012-07-20 08:09:01 +00005969 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) {
5970 if (unlikely(skb->no_fcs))
5971 first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS;
5972 if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5973 return;
5974 }
Alexander Duyck897ab152011-05-27 05:31:47 +00005975 } else {
5976 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005977 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005978 case __constant_htons(ETH_P_IP):
5979 vlan_macip_lens |= skb_network_header_len(skb);
5980 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5981 l4_hdr = ip_hdr(skb)->protocol;
5982 break;
5983 case __constant_htons(ETH_P_IPV6):
5984 vlan_macip_lens |= skb_network_header_len(skb);
5985 l4_hdr = ipv6_hdr(skb)->nexthdr;
5986 break;
5987 default:
5988 if (unlikely(net_ratelimit())) {
5989 dev_warn(tx_ring->dev,
5990 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005991 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005992 }
5993 break;
5994 }
Auke Kok9a799d72007-09-15 14:07:45 -07005995
Alexander Duyck897ab152011-05-27 05:31:47 +00005996 switch (l4_hdr) {
5997 case IPPROTO_TCP:
5998 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5999 mss_l4len_idx = tcp_hdrlen(skb) <<
6000 IXGBE_ADVTXD_L4LEN_SHIFT;
6001 break;
6002 case IPPROTO_SCTP:
6003 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6004 mss_l4len_idx = sizeof(struct sctphdr) <<
6005 IXGBE_ADVTXD_L4LEN_SHIFT;
6006 break;
6007 case IPPROTO_UDP:
6008 mss_l4len_idx = sizeof(struct udphdr) <<
6009 IXGBE_ADVTXD_L4LEN_SHIFT;
6010 break;
6011 default:
6012 if (unlikely(net_ratelimit())) {
6013 dev_warn(tx_ring->dev,
6014 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006015 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006016 }
6017 break;
6018 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006019
6020 /* update TX checksum flag */
6021 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006022 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006023
Alexander Duyck244e27a2012-02-08 07:51:11 +00006024 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006025 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006026 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006027
6028 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6029 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006030}
6031
Alexander Duyckd3d00232011-07-15 02:31:25 +00006032static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6033{
6034 /* set type for advanced descriptor with frame checksum insertion */
6035 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
Alexander Duyckd3d00232011-07-15 02:31:25 +00006036 IXGBE_ADVTXD_DCMD_DEXT);
6037
6038 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006039 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006040 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6041
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006042 if (tx_flags & IXGBE_TX_FLAGS_TSTAMP)
6043 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006044
Alexander Duyckd3d00232011-07-15 02:31:25 +00006045 /* set segmentation enable bits for TSO/FSO */
6046#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006047 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006048#else
6049 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6050#endif
6051 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6052
Alexander Duyck62748b72012-07-20 08:09:01 +00006053 /* insert frame checksum */
6054 if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS))
6055 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS);
6056
Alexander Duyckd3d00232011-07-15 02:31:25 +00006057 return cmd_type;
6058}
6059
Alexander Duyck729739b2012-02-08 07:51:06 +00006060static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6061 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006062{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006063 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006064
6065 /* enable L4 checksum for TSO and TX checksum offload */
6066 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6067 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6068
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006069 /* enble IPv4 checksum for TSO */
6070 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6071 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006072
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006073 /* use index 1 context for TSO/FSO/FCOE */
6074#ifdef IXGBE_FCOE
6075 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6076#else
6077 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006078#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006079 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6080
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006081 /*
6082 * Check Context must be set if Tx switch is enabled, which it
6083 * always is for case where virtual functions are running
6084 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006085#ifdef IXGBE_FCOE
6086 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6087#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006088 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006089#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006090 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6091
Alexander Duyck729739b2012-02-08 07:51:06 +00006092 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006093}
6094
6095#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6096 IXGBE_TXD_CMD_RS)
6097
6098static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006099 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006100 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006101{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006102 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00006103 struct sk_buff *skb = first->skb;
6104 struct ixgbe_tx_buffer *tx_buffer;
6105 union ixgbe_adv_tx_desc *tx_desc;
6106 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006107 unsigned int data_len = skb->data_len;
6108 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00006109 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006110 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00006111 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006112 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006113
Alexander Duyck729739b2012-02-08 07:51:06 +00006114 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6115
6116 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6117 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6118
Alexander Duyckd3d00232011-07-15 02:31:25 +00006119#ifdef IXGBE_FCOE
6120 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006121 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006122 size -= sizeof(struct fcoe_crc_eof) - data_len;
6123 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006124 } else {
6125 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006126 }
Auke Kok9a799d72007-09-15 14:07:45 -07006127 }
6128
Alexander Duyckd3d00232011-07-15 02:31:25 +00006129#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006130 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6131 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006132 goto dma_error;
6133
Alexander Duyck729739b2012-02-08 07:51:06 +00006134 /* record length, and DMA address */
6135 dma_unmap_len_set(first, len, size);
6136 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006137
Alexander Duyck729739b2012-02-08 07:51:06 +00006138 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006139
6140 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006141 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006142 tx_desc->read.cmd_type_len =
6143 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006144
Alexander Duyckd3d00232011-07-15 02:31:25 +00006145 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006146 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006147 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006148 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006149 i = 0;
6150 }
Alexander Duyck729739b2012-02-08 07:51:06 +00006151
6152 dma += IXGBE_MAX_DATA_PER_TXD;
6153 size -= IXGBE_MAX_DATA_PER_TXD;
6154
6155 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6156 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006157 }
6158
Alexander Duyck729739b2012-02-08 07:51:06 +00006159 if (likely(!data_len))
6160 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006161
Alexander Duyckd3d00232011-07-15 02:31:25 +00006162 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006163
Alexander Duyck729739b2012-02-08 07:51:06 +00006164 i++;
6165 tx_desc++;
6166 if (i == tx_ring->count) {
6167 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6168 i = 0;
6169 }
Auke Kok9a799d72007-09-15 14:07:45 -07006170
Alexander Duyckd3d00232011-07-15 02:31:25 +00006171#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006172 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006173#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006174 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006175#endif
6176 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006177
Alexander Duyck729739b2012-02-08 07:51:06 +00006178 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6179 DMA_TO_DEVICE);
6180 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006181 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006182
Alexander Duyck729739b2012-02-08 07:51:06 +00006183 tx_buffer = &tx_ring->tx_buffer_info[i];
6184 dma_unmap_len_set(tx_buffer, len, size);
6185 dma_unmap_addr_set(tx_buffer, dma, dma);
6186
6187 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6188 tx_desc->read.olinfo_status = 0;
6189
6190 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07006191 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006192
Alexander Duyck729739b2012-02-08 07:51:06 +00006193 /* write last descriptor with RS and EOP bits */
6194 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6195 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006196
Alexander Duyck091a6242012-02-08 07:51:01 +00006197 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006198
Alexander Duyckd3d00232011-07-15 02:31:25 +00006199 /* set the timestamp */
6200 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006201
6202 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006203 * Force memory writes to complete before letting h/w know there
6204 * are new descriptors to fetch. (Only applicable for weak-ordered
6205 * memory model archs, such as IA-64).
6206 *
6207 * We also need this memory barrier to make certain all of the
6208 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006209 */
6210 wmb();
6211
Alexander Duyckd3d00232011-07-15 02:31:25 +00006212 /* set next_to_watch value indicating a packet is present */
6213 first->next_to_watch = tx_desc;
6214
Alexander Duyck729739b2012-02-08 07:51:06 +00006215 i++;
6216 if (i == tx_ring->count)
6217 i = 0;
6218
6219 tx_ring->next_to_use = i;
6220
Alexander Duyckd3d00232011-07-15 02:31:25 +00006221 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006222 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006223
6224 return;
6225dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006226 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006227
6228 /* clear dma mappings for failed tx_buffer_info map */
6229 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006230 tx_buffer = &tx_ring->tx_buffer_info[i];
6231 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6232 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006233 break;
6234 if (i == 0)
6235 i = tx_ring->count;
6236 i--;
6237 }
6238
Alexander Duyckd3d00232011-07-15 02:31:25 +00006239 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006240}
6241
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006242static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006243 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006244{
Alexander Duyck69830522011-01-06 14:29:58 +00006245 struct ixgbe_q_vector *q_vector = ring->q_vector;
6246 union ixgbe_atr_hash_dword input = { .dword = 0 };
6247 union ixgbe_atr_hash_dword common = { .dword = 0 };
6248 union {
6249 unsigned char *network;
6250 struct iphdr *ipv4;
6251 struct ipv6hdr *ipv6;
6252 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006253 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006254 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006255
Alexander Duyck69830522011-01-06 14:29:58 +00006256 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6257 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006258 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006259
Alexander Duyck69830522011-01-06 14:29:58 +00006260 /* do nothing if sampling is disabled */
6261 if (!ring->atr_sample_rate)
6262 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006263
Alexander Duyck69830522011-01-06 14:29:58 +00006264 ring->atr_count++;
6265
6266 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006267 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006268
6269 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006270 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006271 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006272 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006273 hdr.ipv4->protocol != IPPROTO_TCP))
6274 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006275
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006276 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006277
Alexander Duyck66f32a82011-06-29 05:43:22 +00006278 /* skip this packet since it is invalid or the socket is closing */
6279 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006280 return;
6281
6282 /* sample on all syn packets or once every atr sample count */
6283 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6284 return;
6285
6286 /* reset sample count */
6287 ring->atr_count = 0;
6288
Alexander Duyck244e27a2012-02-08 07:51:11 +00006289 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006290
6291 /*
6292 * src and dst are inverted, think how the receiver sees them
6293 *
6294 * The input is broken into two sections, a non-compressed section
6295 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6296 * is XORed together and stored in the compressed dword.
6297 */
6298 input.formatted.vlan_id = vlan_id;
6299
6300 /*
6301 * since src port and flex bytes occupy the same word XOR them together
6302 * and write the value to source port portion of compressed dword
6303 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006304 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006305 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6306 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006307 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006308 common.port.dst ^= th->source;
6309
Alexander Duyck244e27a2012-02-08 07:51:11 +00006310 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006311 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6312 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6313 } else {
6314 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6315 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6316 hdr.ipv6->saddr.s6_addr32[1] ^
6317 hdr.ipv6->saddr.s6_addr32[2] ^
6318 hdr.ipv6->saddr.s6_addr32[3] ^
6319 hdr.ipv6->daddr.s6_addr32[0] ^
6320 hdr.ipv6->daddr.s6_addr32[1] ^
6321 hdr.ipv6->daddr.s6_addr32[2] ^
6322 hdr.ipv6->daddr.s6_addr32[3];
6323 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006324
6325 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006326 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6327 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006328}
6329
Alexander Duyck63544e92011-05-27 05:31:42 +00006330static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006331{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006332 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006333 /* Herbert's original patch had:
6334 * smp_mb__after_netif_stop_queue();
6335 * but since that doesn't exist yet, just open code it. */
6336 smp_mb();
6337
6338 /* We need to check again in a case another CPU has just
6339 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006340 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006341 return -EBUSY;
6342
6343 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006344 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006345 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006346 return 0;
6347}
6348
Alexander Duyck82d4e462011-06-11 01:44:58 +00006349static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006350{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006351 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006352 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006353 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006354}
6355
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006356static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6357{
6358 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006359 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6360 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006361#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006362 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006363
John Fastabende5b64632011-03-08 03:44:52 +00006364 if (((protocol == htons(ETH_P_FCOE)) ||
6365 (protocol == htons(ETH_P_FIP))) &&
6366 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckc0876632012-05-10 00:01:46 +00006367 struct ixgbe_ring_feature *f;
6368
6369 f = &adapter->ring_feature[RING_F_FCOE];
6370
6371 while (txq >= f->indices)
6372 txq -= f->indices;
Alexander Duycke4b317e2012-05-05 05:30:53 +00006373 txq += adapter->ring_feature[RING_F_FCOE].offset;
Alexander Duyckc0876632012-05-10 00:01:46 +00006374
John Fastabende5b64632011-03-08 03:44:52 +00006375 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006376 }
6377#endif
6378
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006379 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6380 while (unlikely(txq >= dev->real_num_tx_queues))
6381 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006382 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006383 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006384
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006385 return skb_tx_hash(dev, skb);
6386}
6387
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006388netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006389 struct ixgbe_adapter *adapter,
6390 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006391{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006392 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006393 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006394 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006395#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6396 unsigned short f;
6397#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006398 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006399 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006400 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006401
Alexander Duycka535c302011-05-27 05:31:52 +00006402 /*
6403 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006404 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006405 * + 2 desc gap to keep tail from touching head,
6406 * + 1 desc for context descriptor,
6407 * otherwise try next time
6408 */
6409#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6410 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6411 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6412#else
6413 count += skb_shinfo(skb)->nr_frags;
6414#endif
6415 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6416 tx_ring->tx_stats.tx_busy++;
6417 return NETDEV_TX_BUSY;
6418 }
6419
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006420 /* record the location of the first descriptor for this packet */
6421 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6422 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006423 first->bytecount = skb->len;
6424 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006425
Alexander Duyck66f32a82011-06-29 05:43:22 +00006426 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006427 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006428 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6429 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6430 /* else if it is a SW VLAN check the next protocol and store the tag */
6431 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6432 struct vlan_hdr *vhdr, _vhdr;
6433 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6434 if (!vhdr)
6435 goto out_drop;
6436
6437 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006438 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6439 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006440 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006441 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006442
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006443 skb_tx_timestamp(skb);
6444
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006445 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6446 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6447 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
6448 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006449
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006450#ifdef CONFIG_PCI_IOV
6451 /*
6452 * Use the l2switch_enable flag - would be false if the DMA
6453 * Tx switch had been disabled.
6454 */
6455 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6456 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6457
6458#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006459 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006460 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006461 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6462 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006463 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006464 tx_flags |= (skb->priority & 0x7) <<
6465 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006466 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6467 struct vlan_ethhdr *vhdr;
6468 if (skb_header_cloned(skb) &&
6469 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6470 goto out_drop;
6471 vhdr = (struct vlan_ethhdr *)skb->data;
6472 vhdr->h_vlan_TCI = htons(tx_flags >>
6473 IXGBE_TX_FLAGS_VLAN_SHIFT);
6474 } else {
6475 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6476 }
6477 }
Alexander Duycka535c302011-05-27 05:31:52 +00006478
Alexander Duyck244e27a2012-02-08 07:51:11 +00006479 /* record initial flags and protocol */
6480 first->tx_flags = tx_flags;
6481 first->protocol = protocol;
6482
Yi Zoueacd73f2009-05-13 13:11:06 +00006483#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006484 /* setup tx offload for FCoE */
6485 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006486 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006487 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006488 if (tso < 0)
6489 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006490
Alexander Duyck66f32a82011-06-29 05:43:22 +00006491 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006492 }
Auke Kok9a799d72007-09-15 14:07:45 -07006493
Auke Kok9a799d72007-09-15 14:07:45 -07006494#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006495 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006496 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006497 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006498 else if (!tso)
6499 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006500
6501 /* add the ATR filter if ATR is on */
6502 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006503 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006504
6505#ifdef IXGBE_FCOE
6506xmit_fcoe:
6507#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006508 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006509
6510 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006511
6512 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006513
6514out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006515 dev_kfree_skb_any(first->skb);
6516 first->skb = NULL;
6517
Alexander Duyck897ab152011-05-27 05:31:47 +00006518 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006519}
6520
Alexander Duycka50c29d2012-02-08 07:50:40 +00006521static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6522 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006523{
6524 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006525 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006526
Alexander Duycka50c29d2012-02-08 07:50:40 +00006527 /*
6528 * The minimum packet size for olinfo paylen is 17 so pad the skb
6529 * in order to meet this minimum size requirement.
6530 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006531 if (unlikely(skb->len < 17)) {
6532 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006533 return NETDEV_TX_OK;
6534 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006535 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006536 }
6537
Auke Kok9a799d72007-09-15 14:07:45 -07006538 tx_ring = adapter->tx_ring[skb->queue_mapping];
6539 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6540}
6541
6542/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006543 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006544 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006545 * @p: pointer to an address structure
6546 *
Auke Kok9a799d72007-09-15 14:07:45 -07006547 * Returns 0 on success, negative on failure
6548 **/
6549static int ixgbe_set_mac(struct net_device *netdev, void *p)
6550{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006551 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6552 struct ixgbe_hw *hw = &adapter->hw;
6553 struct sockaddr *addr = p;
6554
6555 if (!is_valid_ether_addr(addr->sa_data))
6556 return -EADDRNOTAVAIL;
6557
6558 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6559 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6560
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006561 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006562
6563 return 0;
6564}
6565
Ben Hutchings6b73e102009-04-29 08:08:58 +00006566static int
6567ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6568{
6569 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6570 struct ixgbe_hw *hw = &adapter->hw;
6571 u16 value;
6572 int rc;
6573
6574 if (prtad != hw->phy.mdio.prtad)
6575 return -EINVAL;
6576 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6577 if (!rc)
6578 rc = value;
6579 return rc;
6580}
6581
6582static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6583 u16 addr, u16 value)
6584{
6585 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6586 struct ixgbe_hw *hw = &adapter->hw;
6587
6588 if (prtad != hw->phy.mdio.prtad)
6589 return -EINVAL;
6590 return hw->phy.ops.write_reg(hw, addr, devad, value);
6591}
6592
6593static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6594{
6595 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6596
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006597 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006598 case SIOCSHWTSTAMP:
6599 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006600 default:
6601 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6602 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006603}
6604
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006605/**
6606 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006607 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006608 * @netdev: network interface device structure
6609 *
6610 * Returns non-zero on failure
6611 **/
6612static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6613{
6614 int err = 0;
6615 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006616 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006617
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006618 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006619 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006620 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006621 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006622
6623 /* update SAN MAC vmdq pool selection */
6624 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006625 }
6626 return err;
6627}
6628
6629/**
6630 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006631 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006632 * @netdev: network interface device structure
6633 *
6634 * Returns non-zero on failure
6635 **/
6636static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6637{
6638 int err = 0;
6639 struct ixgbe_adapter *adapter = netdev_priv(dev);
6640 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6641
6642 if (is_valid_ether_addr(mac->san_addr)) {
6643 rtnl_lock();
6644 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6645 rtnl_unlock();
6646 }
6647 return err;
6648}
6649
Auke Kok9a799d72007-09-15 14:07:45 -07006650#ifdef CONFIG_NET_POLL_CONTROLLER
6651/*
6652 * Polling 'interrupt' - used by things like netconsole to send skbs
6653 * without having to re-enable interrupts. It's not called while
6654 * the interrupt routine is executing.
6655 */
6656static void ixgbe_netpoll(struct net_device *netdev)
6657{
6658 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006659 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006660
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006661 /* if interface is down do nothing */
6662 if (test_bit(__IXGBE_DOWN, &adapter->state))
6663 return;
6664
Auke Kok9a799d72007-09-15 14:07:45 -07006665 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006666 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006667 for (i = 0; i < adapter->num_q_vectors; i++)
6668 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006669 } else {
6670 ixgbe_intr(adapter->pdev->irq, netdev);
6671 }
Auke Kok9a799d72007-09-15 14:07:45 -07006672 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006673}
Auke Kok9a799d72007-09-15 14:07:45 -07006674
Alexander Duyck581330b2012-02-08 07:51:47 +00006675#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006676static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6677 struct rtnl_link_stats64 *stats)
6678{
6679 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6680 int i;
6681
Eric Dumazet1a515022010-11-16 19:26:42 -08006682 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006683 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006684 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006685 u64 bytes, packets;
6686 unsigned int start;
6687
Eric Dumazet1a515022010-11-16 19:26:42 -08006688 if (ring) {
6689 do {
6690 start = u64_stats_fetch_begin_bh(&ring->syncp);
6691 packets = ring->stats.packets;
6692 bytes = ring->stats.bytes;
6693 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6694 stats->rx_packets += packets;
6695 stats->rx_bytes += bytes;
6696 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006697 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006698
6699 for (i = 0; i < adapter->num_tx_queues; i++) {
6700 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6701 u64 bytes, packets;
6702 unsigned int start;
6703
6704 if (ring) {
6705 do {
6706 start = u64_stats_fetch_begin_bh(&ring->syncp);
6707 packets = ring->stats.packets;
6708 bytes = ring->stats.bytes;
6709 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6710 stats->tx_packets += packets;
6711 stats->tx_bytes += bytes;
6712 }
6713 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006714 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006715 /* following stats updated by ixgbe_watchdog_task() */
6716 stats->multicast = netdev->stats.multicast;
6717 stats->rx_errors = netdev->stats.rx_errors;
6718 stats->rx_length_errors = netdev->stats.rx_length_errors;
6719 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6720 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6721 return stats;
6722}
6723
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006724#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006725/**
6726 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6727 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006728 * @tc: number of traffic classes currently enabled
6729 *
6730 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6731 * 802.1Q priority maps to a packet buffer that exists.
6732 */
6733static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6734{
6735 struct ixgbe_hw *hw = &adapter->hw;
6736 u32 reg, rsave;
6737 int i;
6738
6739 /* 82598 have a static priority to TC mapping that can not
6740 * be changed so no validation is needed.
6741 */
6742 if (hw->mac.type == ixgbe_mac_82598EB)
6743 return;
6744
6745 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6746 rsave = reg;
6747
6748 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6749 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6750
6751 /* If up2tc is out of bounds default to zero */
6752 if (up2tc > tc)
6753 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6754 }
6755
6756 if (reg != rsave)
6757 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6758
6759 return;
6760}
6761
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006762/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006763 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6764 * @adapter: Pointer to adapter struct
6765 *
6766 * Populate the netdev user priority to tc map
6767 */
6768static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6769{
6770 struct net_device *dev = adapter->netdev;
6771 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6772 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6773 u8 prio;
6774
6775 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6776 u8 tc = 0;
6777
6778 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6779 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6780 else if (ets)
6781 tc = ets->prio_tc[prio];
6782
6783 netdev_set_prio_tc_map(dev, prio, tc);
6784 }
6785}
6786
6787/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006788 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006789 *
6790 * @netdev: net device to configure
6791 * @tc: number of traffic classes to enable
6792 */
6793int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6794{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006795 struct ixgbe_adapter *adapter = netdev_priv(dev);
6796 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006797
John Fastabend8b1c0b22011-05-03 02:26:48 +00006798 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006799 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006800 (hw->mac.type == ixgbe_mac_82598EB &&
6801 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006802 return -EINVAL;
6803
6804 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006805 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006806 * hardware is not flexible enough to do this dynamically.
6807 */
6808 if (netif_running(dev))
6809 ixgbe_close(dev);
6810 ixgbe_clear_interrupt_scheme(adapter);
6811
John Fastabende7589ea2011-07-18 22:38:36 +00006812 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006813 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006814 ixgbe_set_prio_tc_map(adapter);
6815
John Fastabende7589ea2011-07-18 22:38:36 +00006816 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006817
Alexander Duyck943561d2012-05-09 22:14:44 -07006818 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6819 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006820 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006821 }
John Fastabende7589ea2011-07-18 22:38:36 +00006822 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006823 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006824
Alexander Duyck943561d2012-05-09 22:14:44 -07006825 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6826 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006827
6828 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006829
6830 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6831 adapter->dcb_cfg.pfc_mode_enable = false;
6832 }
6833
John Fastabend8b1c0b22011-05-03 02:26:48 +00006834 ixgbe_init_interrupt_scheme(adapter);
6835 ixgbe_validate_rtr(adapter, tc);
6836 if (netif_running(dev))
6837 ixgbe_open(dev);
6838
6839 return 0;
6840}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006841
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006842#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006843void ixgbe_do_reset(struct net_device *netdev)
6844{
6845 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6846
6847 if (netif_running(netdev))
6848 ixgbe_reinit_locked(adapter);
6849 else
6850 ixgbe_reset(adapter);
6851}
6852
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006853static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006854 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006855{
6856 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6857
Don Skidmore082757a2011-07-21 05:55:00 +00006858 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006859 if (!(features & NETIF_F_RXCSUM))
6860 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006861
Alexander Duyck567d2de2012-02-11 07:18:57 +00006862 /* Turn off LRO if not RSC capable */
6863 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6864 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006865
Alexander Duyck567d2de2012-02-11 07:18:57 +00006866 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006867}
6868
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006869static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006870 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006871{
6872 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006873 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006874 bool need_reset = false;
6875
Don Skidmore082757a2011-07-21 05:55:00 +00006876 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006877 if (!(features & NETIF_F_LRO)) {
6878 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006879 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006880 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6881 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6882 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6883 if (adapter->rx_itr_setting == 1 ||
6884 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6885 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6886 need_reset = true;
6887 } else if ((changed ^ features) & NETIF_F_LRO) {
6888 e_info(probe, "rx-usecs set too low, "
6889 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006890 }
6891 }
6892
6893 /*
6894 * Check if Flow Director n-tuple support was enabled or disabled. If
6895 * the state changed, we need to reset.
6896 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006897 switch (features & NETIF_F_NTUPLE) {
6898 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00006899 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006900 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6901 need_reset = true;
6902
Alexander Duyck567d2de2012-02-11 07:18:57 +00006903 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6904 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00006905 break;
6906 default:
6907 /* turn off perfect filters, enable ATR and reset */
6908 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6909 need_reset = true;
6910
6911 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6912
6913 /* We cannot enable ATR if SR-IOV is enabled */
6914 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6915 break;
6916
6917 /* We cannot enable ATR if we have 2 or more traffic classes */
6918 if (netdev_get_num_tc(netdev) > 1)
6919 break;
6920
6921 /* We cannot enable ATR if RSS is disabled */
6922 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6923 break;
6924
6925 /* A sample rate of 0 indicates ATR disabled */
6926 if (!adapter->atr_sample_rate)
6927 break;
6928
6929 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6930 break;
Don Skidmore082757a2011-07-21 05:55:00 +00006931 }
6932
John Fastabend146d4cc2012-05-15 05:59:26 +00006933 if (features & NETIF_F_HW_VLAN_RX)
6934 ixgbe_vlan_strip_enable(adapter);
6935 else
6936 ixgbe_vlan_strip_disable(adapter);
6937
Ben Greear3f2d1c02012-03-08 08:28:41 +00006938 if (changed & NETIF_F_RXALL)
6939 need_reset = true;
6940
Alexander Duyck567d2de2012-02-11 07:18:57 +00006941 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006942 if (need_reset)
6943 ixgbe_do_reset(netdev);
6944
6945 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006946}
6947
stephen hemmingeredc7d572012-10-01 12:32:33 +00006948static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006949 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006950 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006951 u16 flags)
6952{
6953 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00006954 int err;
6955
6956 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6957 return -EOPNOTSUPP;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006958
John Fastabendb1ac1ef2012-11-01 05:00:44 +00006959 /* Hardware does not support aging addresses so if a
6960 * ndm_state is given only allow permanent addresses
6961 */
6962 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006963 pr_info("%s: FDB only supports static addresses\n",
6964 ixgbe_driver_name);
6965 return -EINVAL;
6966 }
6967
Ben Hutchings46acc462012-11-01 09:11:11 +00006968 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00006969 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6970
6971 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006972 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006973 else
John Fastabend95447462012-05-31 12:42:26 +00006974 err = -ENOMEM;
6975 } else if (is_multicast_ether_addr(addr)) {
6976 err = dev_mc_add_excl(dev, addr);
6977 } else {
6978 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006979 }
6980
6981 /* Only return duplicate errors if NLM_F_EXCL is set */
6982 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6983 err = 0;
6984
6985 return err;
6986}
6987
6988static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6989 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006990 const unsigned char *addr)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006991{
6992 struct ixgbe_adapter *adapter = netdev_priv(dev);
6993 int err = -EOPNOTSUPP;
6994
6995 if (ndm->ndm_state & NUD_PERMANENT) {
6996 pr_info("%s: FDB only supports static addresses\n",
6997 ixgbe_driver_name);
6998 return -EINVAL;
6999 }
7000
7001 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7002 if (is_unicast_ether_addr(addr))
7003 err = dev_uc_del(dev, addr);
7004 else if (is_multicast_ether_addr(addr))
7005 err = dev_mc_del(dev, addr);
7006 else
7007 err = -EINVAL;
7008 }
7009
7010 return err;
7011}
7012
7013static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7014 struct netlink_callback *cb,
7015 struct net_device *dev,
7016 int idx)
7017{
7018 struct ixgbe_adapter *adapter = netdev_priv(dev);
7019
7020 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7021 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7022
7023 return idx;
7024}
7025
John Fastabend815cccb2012-10-24 08:13:09 +00007026static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7027 struct nlmsghdr *nlh)
7028{
7029 struct ixgbe_adapter *adapter = netdev_priv(dev);
7030 struct nlattr *attr, *br_spec;
7031 int rem;
7032
7033 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7034 return -EOPNOTSUPP;
7035
7036 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7037
7038 nla_for_each_nested(attr, br_spec, rem) {
7039 __u16 mode;
7040 u32 reg = 0;
7041
7042 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7043 continue;
7044
7045 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007046 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007047 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007048 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7049 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007050 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007051 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7052 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007053 return -EINVAL;
7054
7055 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7056
7057 e_info(drv, "enabling bridge mode: %s\n",
7058 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7059 }
7060
7061 return 0;
7062}
7063
7064static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7065 struct net_device *dev)
7066{
7067 struct ixgbe_adapter *adapter = netdev_priv(dev);
7068 u16 mode;
7069
7070 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7071 return 0;
7072
Greg Rose9b735982012-11-08 02:41:35 +00007073 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007074 mode = BRIDGE_MODE_VEB;
7075 else
7076 mode = BRIDGE_MODE_VEPA;
7077
7078 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7079}
7080
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007081static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007082 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007083 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007084 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007085 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007086 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007087 .ndo_validate_addr = eth_validate_addr,
7088 .ndo_set_mac_address = ixgbe_set_mac,
7089 .ndo_change_mtu = ixgbe_change_mtu,
7090 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007091 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7092 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007093 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007094 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7095 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7096 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007097 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007098 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007099 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007100#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007101 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007102#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007103#ifdef CONFIG_NET_POLL_CONTROLLER
7104 .ndo_poll_controller = ixgbe_netpoll,
7105#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007106#ifdef IXGBE_FCOE
7107 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007108 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007109 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007110 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7111 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007112 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007113 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007114#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007115 .ndo_set_features = ixgbe_set_features,
7116 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007117 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7118 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7119 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
John Fastabend815cccb2012-10-24 08:13:09 +00007120 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7121 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007122};
7123
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007124/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007125 * ixgbe_wol_supported - Check whether device supports WoL
7126 * @hw: hw specific details
7127 * @device_id: the device ID
7128 * @subdev_id: the subsystem device ID
7129 *
7130 * This function is used by probe and ethtool to determine
7131 * which devices have WoL support
7132 *
7133 **/
7134int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7135 u16 subdevice_id)
7136{
7137 struct ixgbe_hw *hw = &adapter->hw;
7138 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7139 int is_wol_supported = 0;
7140
7141 switch (device_id) {
7142 case IXGBE_DEV_ID_82599_SFP:
7143 /* Only these subdevices could supports WOL */
7144 switch (subdevice_id) {
7145 case IXGBE_SUBDEV_ID_82599_560FLR:
7146 /* only support first port */
7147 if (hw->bus.func != 0)
7148 break;
7149 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007150 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007151 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007152 is_wol_supported = 1;
7153 break;
7154 }
7155 break;
7156 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7157 /* All except this subdevice support WOL */
7158 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7159 is_wol_supported = 1;
7160 break;
7161 case IXGBE_DEV_ID_82599_KX4:
7162 is_wol_supported = 1;
7163 break;
7164 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007165 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007166 /* check eeprom to see if enabled wol */
7167 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7168 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7169 (hw->bus.func == 0))) {
7170 is_wol_supported = 1;
7171 }
7172 break;
7173 }
7174
7175 return is_wol_supported;
7176}
7177
7178/**
Auke Kok9a799d72007-09-15 14:07:45 -07007179 * ixgbe_probe - Device Initialization Routine
7180 * @pdev: PCI device information struct
7181 * @ent: entry in ixgbe_pci_tbl
7182 *
7183 * Returns 0 on success, negative on failure
7184 *
7185 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7186 * The OS initialization, configuring of the adapter private structure,
7187 * and a hardware reset occur.
7188 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007189static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007190{
7191 struct net_device *netdev;
7192 struct ixgbe_adapter *adapter = NULL;
7193 struct ixgbe_hw *hw;
7194 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007195 static int cards_found;
7196 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007197 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007198 unsigned int indices = num_possible_cpus();
John Fastabend3f4a6f02012-06-05 05:58:52 +00007199 unsigned int dcb_max = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00007200#ifdef IXGBE_FCOE
7201 u16 device_caps;
7202#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007203 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007204
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007205 /* Catch broken hardware that put the wrong VF device ID in
7206 * the PCIe SR-IOV capability.
7207 */
7208 if (pdev->is_virtfn) {
7209 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7210 pci_name(pdev), pdev->vendor, pdev->device);
7211 return -EINVAL;
7212 }
7213
gouji-new9ce77662009-05-06 10:44:45 +00007214 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007215 if (err)
7216 return err;
7217
Nick Nunley1b507732010-04-27 13:10:27 +00007218 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7219 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007220 pci_using_dac = 1;
7221 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007222 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007223 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007224 err = dma_set_coherent_mask(&pdev->dev,
7225 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007226 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007227 dev_err(&pdev->dev,
7228 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007229 goto err_dma;
7230 }
7231 }
7232 pci_using_dac = 0;
7233 }
7234
gouji-new9ce77662009-05-06 10:44:45 +00007235 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007236 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007237 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007238 dev_err(&pdev->dev,
7239 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007240 goto err_pci_reg;
7241 }
7242
Frans Pop19d5afd2009-10-02 10:04:12 -07007243 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007244
Auke Kok9a799d72007-09-15 14:07:45 -07007245 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007246 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007247
John Fastabende901acd2011-04-26 07:26:08 +00007248#ifdef CONFIG_IXGBE_DCB
John Fastabend3f4a6f02012-06-05 05:58:52 +00007249 if (ii->mac == ixgbe_mac_82598EB)
7250 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7251 IXGBE_MAX_RSS_INDICES);
7252 else
7253 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7254 IXGBE_MAX_FDIR_INDICES);
John Fastabende901acd2011-04-26 07:26:08 +00007255#endif
7256
John Fastabendc85a2612010-02-25 23:15:21 +00007257 if (ii->mac == ixgbe_mac_82598EB)
7258 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7259 else
7260 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7261
John Fastabende901acd2011-04-26 07:26:08 +00007262#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007263 indices += min_t(unsigned int, num_possible_cpus(),
7264 IXGBE_MAX_FCOE_INDICES);
7265#endif
John Fastabend3f4a6f02012-06-05 05:58:52 +00007266 indices = max_t(unsigned int, dcb_max, indices);
John Fastabendc85a2612010-02-25 23:15:21 +00007267 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007268 if (!netdev) {
7269 err = -ENOMEM;
7270 goto err_alloc_etherdev;
7271 }
7272
Auke Kok9a799d72007-09-15 14:07:45 -07007273 SET_NETDEV_DEV(netdev, &pdev->dev);
7274
Auke Kok9a799d72007-09-15 14:07:45 -07007275 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007276 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007277
7278 adapter->netdev = netdev;
7279 adapter->pdev = pdev;
7280 hw = &adapter->hw;
7281 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007282 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007283
Jeff Kirsher05857982008-09-11 19:57:00 -07007284 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007285 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007286 if (!hw->hw_addr) {
7287 err = -EIO;
7288 goto err_ioremap;
7289 }
7290
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007291 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007292 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007293 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007294 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007295
Auke Kok9a799d72007-09-15 14:07:45 -07007296 adapter->bd_number = cards_found;
7297
Auke Kok9a799d72007-09-15 14:07:45 -07007298 /* Setup hw api */
7299 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007300 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007301
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007302 /* EEPROM */
7303 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7304 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7305 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7306 if (!(eec & (1 << 8)))
7307 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7308
7309 /* PHY */
7310 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007311 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007312 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7313 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7314 hw->phy.mdio.mmds = 0;
7315 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7316 hw->phy.mdio.dev = netdev;
7317 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7318 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007319
Don Skidmore8ca783a2009-05-26 20:40:47 -07007320 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007321
7322 /* setup the private structure */
7323 err = ixgbe_sw_init(adapter);
7324 if (err)
7325 goto err_sw_init;
7326
Don Skidmoree86bff02010-02-11 04:14:08 +00007327 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007328 switch (adapter->hw.mac.type) {
7329 case ixgbe_mac_82599EB:
7330 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007331 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007332 break;
7333 default:
7334 break;
7335 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007336
Don Skidmorebf069c92009-05-07 10:39:54 +00007337 /*
7338 * If there is a fan on this device and it has failed log the
7339 * failure.
7340 */
7341 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7342 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7343 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007344 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007345 }
7346
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007347 if (allow_unsupported_sfp)
7348 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7349
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007350 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007351 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007352 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007353 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007354 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7355 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007356 err = 0;
7357 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007358 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007359 "module type was detected.\n");
7360 e_dev_err("Reload the driver after installing a supported "
7361 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007362 goto err_sw_init;
7363 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007364 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007365 goto err_sw_init;
7366 }
7367
Alexander Duyck99d74482012-05-09 08:09:25 +00007368#ifdef CONFIG_PCI_IOV
7369 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007370
Alexander Duyck99d74482012-05-09 08:09:25 +00007371#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007372 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007373 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007374 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007375 NETIF_F_HW_VLAN_TX |
7376 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007377 NETIF_F_HW_VLAN_FILTER |
7378 NETIF_F_TSO |
7379 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007380 NETIF_F_RXHASH |
7381 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007382
Don Skidmore082757a2011-07-21 05:55:00 +00007383 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007384
Don Skidmore58be7662011-04-12 09:42:11 +00007385 switch (adapter->hw.mac.type) {
7386 case ixgbe_mac_82599EB:
7387 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007388 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007389 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7390 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007391 break;
7392 default:
7393 break;
7394 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007395
Ben Greear3f2d1c02012-03-08 08:28:41 +00007396 netdev->hw_features |= NETIF_F_RXALL;
7397
Jeff Kirsherad31c402008-06-05 04:05:30 -07007398 netdev->vlan_features |= NETIF_F_TSO;
7399 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007400 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007401 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007402 netdev->vlan_features |= NETIF_F_SG;
7403
Jiri Pirko01789342011-08-16 06:29:00 +00007404 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007405 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007406
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007407#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007408 netdev->dcbnl_ops = &dcbnl_ops;
7409#endif
7410
Yi Zoueacd73f2009-05-13 13:11:06 +00007411#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007412 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007413 if (hw->mac.ops.get_device_caps) {
7414 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007415 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7416 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007417 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007418
7419 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7420
Alexander Duycka58915c2012-05-25 06:38:18 +00007421 netdev->features |= NETIF_F_FSO |
7422 NETIF_F_FCOE_CRC;
7423
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007424 netdev->vlan_features |= NETIF_F_FSO |
7425 NETIF_F_FCOE_CRC |
7426 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007427 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007428#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007429 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007430 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007431 netdev->vlan_features |= NETIF_F_HIGHDMA;
7432 }
Auke Kok9a799d72007-09-15 14:07:45 -07007433
Don Skidmore082757a2011-07-21 05:55:00 +00007434 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7435 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007436 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007437 netdev->features |= NETIF_F_LRO;
7438
Auke Kok9a799d72007-09-15 14:07:45 -07007439 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007440 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007441 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007442 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007443 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007444 }
7445
7446 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7447 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7448
Joe Perchesf8ebc682012-10-24 17:19:02 +00007449 if (!is_valid_ether_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007450 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007451 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007452 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007453 }
7454
Alexander Duyck70864002011-04-27 09:13:56 +00007455 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007456 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007457
Alexander Duyck70864002011-04-27 09:13:56 +00007458 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7459 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007460
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007461 err = ixgbe_init_interrupt_scheme(adapter);
7462 if (err)
7463 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007464
Jacob Keller8e2813f2012-04-21 06:05:40 +00007465 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007466 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007467 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7468 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007469 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007470
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007471 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7472
Emil Tantilov15e52092011-09-29 05:01:29 +00007473 /* save off EEPROM version number */
7474 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7475 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7476
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007477 /* pick up the PCI bus settings for reporting later */
7478 hw->mac.ops.get_bus_info(hw);
7479
Auke Kok9a799d72007-09-15 14:07:45 -07007480 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007481 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007482 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7483 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007484 "Unknown"),
7485 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7486 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7487 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7488 "Unknown"),
7489 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007490
7491 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7492 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007493 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007494 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007495 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007496 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007497 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007498 else
Don Skidmore289700db2010-12-03 03:32:58 +00007499 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7500 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007501
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007502 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007503 e_dev_warn("PCI-Express bandwidth available for this card is "
7504 "not sufficient for optimal performance.\n");
7505 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7506 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007507 }
7508
Auke Kok9a799d72007-09-15 14:07:45 -07007509 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007510 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007511 if (err == IXGBE_ERR_EEPROM_VERSION) {
7512 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007513 e_dev_warn("This device is a pre-production adapter/LOM. "
7514 "Please be aware there may be issues associated "
7515 "with your hardware. If you are experiencing "
7516 "problems please contact your Intel or hardware "
7517 "representative who provided you with this "
7518 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007519 }
Auke Kok9a799d72007-09-15 14:07:45 -07007520 strcpy(netdev->name, "eth%d");
7521 err = register_netdev(netdev);
7522 if (err)
7523 goto err_register;
7524
Emil Tantilovec74a472012-09-20 03:33:56 +00007525 /* power down the optics for 82599 SFP+ fiber */
7526 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007527 hw->mac.ops.disable_tx_laser(hw);
7528
Jesse Brandeburg54386462009-04-17 20:44:27 +00007529 /* carrier off reporting is important to ethtool even BEFORE open */
7530 netif_carrier_off(netdev);
7531
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007532#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007533 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007534 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007535 ixgbe_setup_dca(adapter);
7536 }
7537#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007538 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007539 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007540 for (i = 0; i < adapter->num_vfs; i++)
7541 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7542 }
7543
Jacob Keller2466dd92011-09-08 03:50:54 +00007544 /* firmware requires driver version to be 0xFFFFFFFF
7545 * since os does not support feature
7546 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007547 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007548 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7549 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007550
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007551 /* add san mac addr to netdev */
7552 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007553
Neerav Parikhea818752012-01-04 20:23:40 +00007554 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007555 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007556
Don Skidmore12109822012-05-04 06:07:08 +00007557#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007558 if (ixgbe_sysfs_init(adapter))
7559 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007560#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007561
Catherine Sullivan00949162012-08-10 01:59:10 +00007562#ifdef CONFIG_DEBUG_FS
7563 ixgbe_dbg_adapter_init(adapter);
7564#endif /* CONFIG_DEBUG_FS */
7565
Auke Kok9a799d72007-09-15 14:07:45 -07007566 return 0;
7567
7568err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007569 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007570 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007571err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007572 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007573 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007574 iounmap(hw->hw_addr);
7575err_ioremap:
7576 free_netdev(netdev);
7577err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007578 pci_release_selected_regions(pdev,
7579 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007580err_pci_reg:
7581err_dma:
7582 pci_disable_device(pdev);
7583 return err;
7584}
7585
7586/**
7587 * ixgbe_remove - Device Removal Routine
7588 * @pdev: PCI device information struct
7589 *
7590 * ixgbe_remove is called by the PCI subsystem to alert the driver
7591 * that it should release a PCI device. The could be caused by a
7592 * Hot-Plug event, or because the driver is going to be removed from
7593 * memory.
7594 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007595static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007596{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007597 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7598 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007599
Catherine Sullivan00949162012-08-10 01:59:10 +00007600#ifdef CONFIG_DEBUG_FS
7601 ixgbe_dbg_adapter_exit(adapter);
7602#endif /*CONFIG_DEBUG_FS */
7603
Auke Kok9a799d72007-09-15 14:07:45 -07007604 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007605 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007606
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007607
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007608#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007609 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7610 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7611 dca_remove_requester(&pdev->dev);
7612 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7613 }
7614
7615#endif
Don Skidmore12109822012-05-04 06:07:08 +00007616#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007617 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007618#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007619
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007620 /* remove the added san mac */
7621 ixgbe_del_sanmac_netdev(netdev);
7622
Donald Skidmorec4900be2008-11-20 21:11:42 -08007623 if (netdev->reg_state == NETREG_REGISTERED)
7624 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007625
Alexander Duyck92971272012-05-23 02:58:40 +00007626 ixgbe_disable_sriov(adapter);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007627
Alexander Duyck7a921c92009-05-06 10:43:28 +00007628 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007629
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007630 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007631
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007632#ifdef CONFIG_DCB
7633 kfree(adapter->ixgbe_ieee_pfc);
7634 kfree(adapter->ixgbe_ieee_ets);
7635
7636#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007637 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007638 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007639 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007640
Emil Tantilov849c4542010-06-03 16:53:41 +00007641 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007642
Auke Kok9a799d72007-09-15 14:07:45 -07007643 free_netdev(netdev);
7644
Frans Pop19d5afd2009-10-02 10:04:12 -07007645 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007646
Auke Kok9a799d72007-09-15 14:07:45 -07007647 pci_disable_device(pdev);
7648}
7649
7650/**
7651 * ixgbe_io_error_detected - called when PCI error is detected
7652 * @pdev: Pointer to PCI device
7653 * @state: The current pci connection state
7654 *
7655 * This function is called after a PCI bus error affecting
7656 * this device has been detected.
7657 */
7658static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007659 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007660{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007661 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7662 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007663
Greg Rose83c61fa2011-09-07 05:59:35 +00007664#ifdef CONFIG_PCI_IOV
7665 struct pci_dev *bdev, *vfdev;
7666 u32 dw0, dw1, dw2, dw3;
7667 int vf, pos;
7668 u16 req_id, pf_func;
7669
7670 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7671 adapter->num_vfs == 0)
7672 goto skip_bad_vf_detection;
7673
7674 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007675 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007676 bdev = bdev->bus->self;
7677
7678 if (!bdev)
7679 goto skip_bad_vf_detection;
7680
7681 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7682 if (!pos)
7683 goto skip_bad_vf_detection;
7684
7685 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7686 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7687 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7688 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7689
7690 req_id = dw1 >> 16;
7691 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7692 if (!(req_id & 0x0080))
7693 goto skip_bad_vf_detection;
7694
7695 pf_func = req_id & 0x01;
7696 if ((pf_func & 1) == (pdev->devfn & 1)) {
7697 unsigned int device_id;
7698
7699 vf = (req_id & 0x7F) >> 1;
7700 e_dev_err("VF %d has caused a PCIe error\n", vf);
7701 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7702 "%8.8x\tdw3: %8.8x\n",
7703 dw0, dw1, dw2, dw3);
7704 switch (adapter->hw.mac.type) {
7705 case ixgbe_mac_82599EB:
7706 device_id = IXGBE_82599_VF_DEVICE_ID;
7707 break;
7708 case ixgbe_mac_X540:
7709 device_id = IXGBE_X540_VF_DEVICE_ID;
7710 break;
7711 default:
7712 device_id = 0;
7713 break;
7714 }
7715
7716 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007717 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007718 while (vfdev) {
7719 if (vfdev->devfn == (req_id & 0xFF))
7720 break;
Jon Mason36e90312012-07-19 21:02:09 +00007721 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007722 device_id, vfdev);
7723 }
7724 /*
7725 * There's a slim chance the VF could have been hot plugged,
7726 * so if it is no longer present we don't need to issue the
7727 * VFLR. Just clean up the AER in that case.
7728 */
7729 if (vfdev) {
7730 e_dev_err("Issuing VFLR to VF %d\n", vf);
7731 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7732 }
7733
7734 pci_cleanup_aer_uncorrect_error_status(pdev);
7735 }
7736
7737 /*
7738 * Even though the error may have occurred on the other port
7739 * we still need to increment the vf error reference count for
7740 * both ports because the I/O resume function will be called
7741 * for both of them.
7742 */
7743 adapter->vferr_refcount++;
7744
7745 return PCI_ERS_RESULT_RECOVERED;
7746
7747skip_bad_vf_detection:
7748#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007749 netif_device_detach(netdev);
7750
Breno Leitao3044b8d2009-05-06 10:44:26 +00007751 if (state == pci_channel_io_perm_failure)
7752 return PCI_ERS_RESULT_DISCONNECT;
7753
Auke Kok9a799d72007-09-15 14:07:45 -07007754 if (netif_running(netdev))
7755 ixgbe_down(adapter);
7756 pci_disable_device(pdev);
7757
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007758 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007759 return PCI_ERS_RESULT_NEED_RESET;
7760}
7761
7762/**
7763 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7764 * @pdev: Pointer to PCI device
7765 *
7766 * Restart the card from scratch, as if from a cold-boot.
7767 */
7768static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7769{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007770 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007771 pci_ers_result_t result;
7772 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007773
gouji-new9ce77662009-05-06 10:44:45 +00007774 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007775 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007776 result = PCI_ERS_RESULT_DISCONNECT;
7777 } else {
7778 pci_set_master(pdev);
7779 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007780 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007781
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007782 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007783
7784 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007785 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007786 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007787 }
Auke Kok9a799d72007-09-15 14:07:45 -07007788
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007789 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7790 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007791 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7792 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007793 /* non-fatal, continue */
7794 }
Auke Kok9a799d72007-09-15 14:07:45 -07007795
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007796 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007797}
7798
7799/**
7800 * ixgbe_io_resume - called when traffic can start flowing again.
7801 * @pdev: Pointer to PCI device
7802 *
7803 * This callback is called when the error recovery driver tells us that
7804 * its OK to resume normal operation.
7805 */
7806static void ixgbe_io_resume(struct pci_dev *pdev)
7807{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007808 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7809 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007810
Greg Rose83c61fa2011-09-07 05:59:35 +00007811#ifdef CONFIG_PCI_IOV
7812 if (adapter->vferr_refcount) {
7813 e_info(drv, "Resuming after VF err\n");
7814 adapter->vferr_refcount--;
7815 return;
7816 }
7817
7818#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007819 if (netif_running(netdev))
7820 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007821
7822 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007823}
7824
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007825static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007826 .error_detected = ixgbe_io_error_detected,
7827 .slot_reset = ixgbe_io_slot_reset,
7828 .resume = ixgbe_io_resume,
7829};
7830
7831static struct pci_driver ixgbe_driver = {
7832 .name = ixgbe_driver_name,
7833 .id_table = ixgbe_pci_tbl,
7834 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007835 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07007836#ifdef CONFIG_PM
7837 .suspend = ixgbe_suspend,
7838 .resume = ixgbe_resume,
7839#endif
7840 .shutdown = ixgbe_shutdown,
7841 .err_handler = &ixgbe_err_handler
7842};
7843
7844/**
7845 * ixgbe_init_module - Driver Registration Routine
7846 *
7847 * ixgbe_init_module is the first routine called when the driver is
7848 * loaded. All it does is register with the PCI subsystem.
7849 **/
7850static int __init ixgbe_init_module(void)
7851{
7852 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007853 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007854 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007855
Catherine Sullivan00949162012-08-10 01:59:10 +00007856#ifdef CONFIG_DEBUG_FS
7857 ixgbe_dbg_init();
7858#endif /* CONFIG_DEBUG_FS */
7859
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007860#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007861 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007862#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007863
Auke Kok9a799d72007-09-15 14:07:45 -07007864 ret = pci_register_driver(&ixgbe_driver);
7865 return ret;
7866}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007867
Auke Kok9a799d72007-09-15 14:07:45 -07007868module_init(ixgbe_init_module);
7869
7870/**
7871 * ixgbe_exit_module - Driver Exit Cleanup Routine
7872 *
7873 * ixgbe_exit_module is called just before the driver is removed
7874 * from memory.
7875 **/
7876static void __exit ixgbe_exit_module(void)
7877{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007878#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007879 dca_unregister_notify(&dca_notifier);
7880#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007881 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00007882
7883#ifdef CONFIG_DEBUG_FS
7884 ixgbe_dbg_exit();
7885#endif /* CONFIG_DEBUG_FS */
7886
Eric Dumazet1a515022010-11-16 19:26:42 -08007887 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007888}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007889
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007890#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007891static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007892 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007893{
7894 int ret_val;
7895
7896 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007897 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007898
7899 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7900}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007901
Alexander Duyckb4533682009-03-31 21:32:42 +00007902#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007903
Auke Kok9a799d72007-09-15 14:07:45 -07007904module_exit(ixgbe_exit_module);
7905
7906/* ixgbe_main.c */