blob: 16c9858f7dcf7185cb6aa50365c4b659ec570391 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000047#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000049#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070050
51#include "ixgbe.h"
52#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000053#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000054#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070055
56char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070057static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000058 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000059#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000060char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000062#else
63static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
65#endif
Don 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 Skidmore434c5e32013-01-08 05:02:28 +000069 "Copyright (c) 1999-2013 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070070
71static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070072 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000073 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e2010-11-16 19:27:16 -080074 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070075};
76
77/* ixgbe_pci_tbl - PCI Device ID Table
78 *
79 * Wildcard entries (PCI_ANY_ID) should come last
80 * Last entry must be all 0s
81 *
82 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
83 * Class, Class Mask, private data (not used) }
84 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000085static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700115 /* required last entry */
116 {0, }
117};
118MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
119
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400120#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800121static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000122 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800123static struct notifier_block dca_notifier = {
124 .notifier_call = ixgbe_notify_dca,
125 .next = NULL,
126 .priority = 0
127};
128#endif
129
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000130#ifdef CONFIG_PCI_IOV
131static unsigned int max_vfs;
132module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000133MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000134 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000135#endif /* CONFIG_PCI_IOV */
136
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000137static unsigned int allow_unsupported_sfp;
138module_param(allow_unsupported_sfp, uint, 0);
139MODULE_PARM_DESC(allow_unsupported_sfp,
140 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
141
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000142#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
143static int debug = -1;
144module_param(debug, int, 0);
145MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
146
Auke Kok9a799d72007-09-15 14:07:45 -0700147MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
148MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
149MODULE_LICENSE("GPL");
150MODULE_VERSION(DRV_VERSION);
151
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;
Jacob Keller12ff3f32012-12-01 07:57:17 +0000806 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000807 ixgbe_service_event_schedule(adapter);
808 }
809}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700810
Auke Kok9a799d72007-09-15 14:07:45 -0700811/**
812 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000813 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700814 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700815 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000816static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000817 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700818{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000819 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000820 struct ixgbe_tx_buffer *tx_buffer;
821 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700822 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000823 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000824 unsigned int i = tx_ring->next_to_clean;
825
826 if (test_bit(__IXGBE_DOWN, &adapter->state))
827 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700828
Alexander Duyckd3d00232011-07-15 02:31:25 +0000829 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000830 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000831 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800832
Alexander Duyck729739b2012-02-08 07:51:06 +0000833 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000834 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700835
Alexander Duyckd3d00232011-07-15 02:31:25 +0000836 /* if next_to_watch is not set then there is no work pending */
837 if (!eop_desc)
838 break;
839
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000840 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +0000841 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000842
Alexander Duyckd3d00232011-07-15 02:31:25 +0000843 /* if DD is not set pending work has not been completed */
844 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
845 break;
846
Alexander Duyckd3d00232011-07-15 02:31:25 +0000847 /* clear next_to_watch to prevent false hangs */
848 tx_buffer->next_to_watch = NULL;
849
Alexander Duyck091a6242012-02-08 07:51:01 +0000850 /* update the statistics for this packet */
851 total_bytes += tx_buffer->bytecount;
852 total_packets += tx_buffer->gso_segs;
853
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000854 /* free the skb */
855 dev_kfree_skb_any(tx_buffer->skb);
856
Alexander Duyck729739b2012-02-08 07:51:06 +0000857 /* unmap skb header data */
858 dma_unmap_single(tx_ring->dev,
859 dma_unmap_addr(tx_buffer, dma),
860 dma_unmap_len(tx_buffer, len),
861 DMA_TO_DEVICE);
862
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000863 /* clear tx_buffer data */
864 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000865 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000866
Alexander Duyck729739b2012-02-08 07:51:06 +0000867 /* unmap remaining buffers */
868 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000869 tx_buffer++;
870 tx_desc++;
871 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000872 if (unlikely(!i)) {
873 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000874 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000875 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000876 }
877
Alexander Duyck729739b2012-02-08 07:51:06 +0000878 /* unmap any remaining paged data */
879 if (dma_unmap_len(tx_buffer, len)) {
880 dma_unmap_page(tx_ring->dev,
881 dma_unmap_addr(tx_buffer, dma),
882 dma_unmap_len(tx_buffer, len),
883 DMA_TO_DEVICE);
884 dma_unmap_len_set(tx_buffer, len, 0);
885 }
886 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800887
Alexander Duyck729739b2012-02-08 07:51:06 +0000888 /* move us one more past the eop_desc for start of next pkt */
889 tx_buffer++;
890 tx_desc++;
891 i++;
892 if (unlikely(!i)) {
893 i -= tx_ring->count;
894 tx_buffer = tx_ring->tx_buffer_info;
895 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
896 }
897
898 /* issue prefetch for next Tx descriptor */
899 prefetch(tx_desc);
900
901 /* update budget accounting */
902 budget--;
903 } while (likely(budget));
904
905 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700906 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000907 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800908 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000909 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000910 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000911 q_vector->tx.total_bytes += total_bytes;
912 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800913
John Fastabendc84d3242010-11-16 19:27:12 -0800914 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800915 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800916 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800917 e_err(drv, "Detected Tx Unit Hang\n"
918 " Tx Queue <%d>\n"
919 " TDH, TDT <%x>, <%x>\n"
920 " next_to_use <%x>\n"
921 " next_to_clean <%x>\n"
922 "tx_buffer_info[next_to_clean]\n"
923 " time_stamp <%lx>\n"
924 " jiffies <%lx>\n",
925 tx_ring->queue_index,
926 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
927 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000928 tx_ring->next_to_use, i,
929 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800930
931 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
932
933 e_info(probe,
934 "tx hang %d detected on queue %d, resetting adapter\n",
935 adapter->tx_timeout_count + 1, tx_ring->queue_index);
936
937 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000938 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800939
940 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000941 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800942 }
Auke Kok9a799d72007-09-15 14:07:45 -0700943
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000944 netdev_tx_completed_queue(txring_txq(tx_ring),
945 total_packets, total_bytes);
946
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800947#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000948 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000949 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800950 /* Make sure that anybody stopping the queue after this
951 * sees the new next_to_clean.
952 */
953 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000954 if (__netif_subqueue_stopped(tx_ring->netdev,
955 tx_ring->queue_index)
956 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
957 netif_wake_subqueue(tx_ring->netdev,
958 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800959 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800960 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800961 }
Auke Kok9a799d72007-09-15 14:07:45 -0700962
Alexander Duyck59224552011-08-31 00:01:06 +0000963 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700964}
965
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400966#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800967static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968 struct ixgbe_ring *tx_ring,
969 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800970{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000971 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000972 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
973 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800974
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800975 switch (hw->mac.type) {
976 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000977 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800978 break;
979 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800980 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000981 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
982 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
983 break;
984 default:
985 /* for unknown hardware do not write register */
986 return;
987 }
988
989 /*
990 * We can enable relaxed ordering for reads, but not writes when
991 * DCA is enabled. This is due to a known issue in some chipsets
992 * which will cause the DCA tag to be cleared.
993 */
994 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
995 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
996 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
997
998 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
999}
1000
1001static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1002 struct ixgbe_ring *rx_ring,
1003 int cpu)
1004{
1005 struct ixgbe_hw *hw = &adapter->hw;
1006 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1007 u8 reg_idx = rx_ring->reg_idx;
1008
1009
1010 switch (hw->mac.type) {
1011 case ixgbe_mac_82599EB:
1012 case ixgbe_mac_X540:
1013 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001014 break;
1015 default:
1016 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001017 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001018
1019 /*
1020 * We can enable relaxed ordering for reads, but not writes when
1021 * DCA is enabled. This is due to a known issue in some chipsets
1022 * which will cause the DCA tag to be cleared.
1023 */
1024 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001025 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1026
1027 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001028}
1029
1030static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1031{
1032 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001033 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001034 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001035
1036 if (q_vector->cpu == cpu)
1037 goto out_no_update;
1038
Alexander Duycka5579282012-02-08 07:50:04 +00001039 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001040 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001041
Alexander Duycka5579282012-02-08 07:50:04 +00001042 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001043 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001044
1045 q_vector->cpu = cpu;
1046out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001047 put_cpu();
1048}
1049
1050static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1051{
1052 int i;
1053
1054 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1055 return;
1056
Alexander Duycke35ec122009-05-21 13:07:12 +00001057 /* always use CB2 mode, difference is masked in the CB driver */
1058 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1059
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001060 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001061 adapter->q_vector[i]->cpu = -1;
1062 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001063 }
1064}
1065
1066static int __ixgbe_notify_dca(struct device *dev, void *data)
1067{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001068 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001069 unsigned long event = *(unsigned long *)data;
1070
Don Skidmore2a72c312011-07-20 02:27:05 +00001071 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001072 return 0;
1073
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001074 switch (event) {
1075 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001076 /* if we're already enabled, don't do it again */
1077 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1078 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001079 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001080 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001081 ixgbe_setup_dca(adapter);
1082 break;
1083 }
1084 /* Fall Through since DCA is disabled. */
1085 case DCA_PROVIDER_REMOVE:
1086 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1087 dca_remove_requester(dev);
1088 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1089 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1090 }
1091 break;
1092 }
1093
Denis V. Lunev652f0932008-03-27 14:39:17 +03001094 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001095}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001096
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001097#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001098static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1099 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001100 struct sk_buff *skb)
1101{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001102 if (ring->netdev->features & NETIF_F_RXHASH)
1103 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001104}
1105
Alexander Duyckf8003262012-03-03 02:35:52 +00001106#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001107/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001108 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001109 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001110 * @rx_desc: advanced rx descriptor
1111 *
1112 * Returns : true if it is FCoE pkt
1113 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001114static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001115 union ixgbe_adv_rx_desc *rx_desc)
1116{
1117 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1118
Alexander Duyck57efd442012-06-25 21:54:46 +00001119 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001120 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1121 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1122 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1123}
1124
Alexander Duyckf8003262012-03-03 02:35:52 +00001125#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001126/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001127 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001128 * @ring: structure containing ring specific data
1129 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001130 * @skb: skb currently being received and modified
1131 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001132static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001133 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001134 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001135{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001136 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001137
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001138 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001139 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001140 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001141
1142 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001143 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1144 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001145 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001146 return;
1147 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001148
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001149 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001150 return;
1151
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001152 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001153 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001154
1155 /*
1156 * 82599 errata, UDP frames with a 0 checksum can be marked as
1157 * checksum errors.
1158 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001159 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1160 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001161 return;
1162
Alexander Duyck8a0da212012-01-31 02:59:49 +00001163 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001164 return;
1165 }
1166
Auke Kok9a799d72007-09-15 14:07:45 -07001167 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001168 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001169}
1170
Alexander Duyck84ea2592010-11-16 19:26:49 -08001171static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001172{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001173 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001174
1175 /* update next to alloc since we have filled the ring */
1176 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001177 /*
1178 * Force memory writes to complete before letting h/w
1179 * know there are new descriptors to fetch. (Only
1180 * applicable for weak-ordered memory model archs,
1181 * such as IA-64).
1182 */
1183 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001184 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001185}
1186
Alexander Duyckf990b792012-01-31 02:59:34 +00001187static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1188 struct ixgbe_rx_buffer *bi)
1189{
1190 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001191 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001192
Alexander Duyckf8003262012-03-03 02:35:52 +00001193 /* since we are recycling buffers we should seldom need to alloc */
1194 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001195 return true;
1196
Alexander Duyckf8003262012-03-03 02:35:52 +00001197 /* alloc new page for storage */
1198 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001199 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1200 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001201 if (unlikely(!page)) {
1202 rx_ring->rx_stats.alloc_rx_page_failed++;
1203 return false;
1204 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001205 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001206 }
1207
Alexander Duyckf8003262012-03-03 02:35:52 +00001208 /* map page for use */
1209 dma = dma_map_page(rx_ring->dev, page, 0,
1210 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001211
Alexander Duyckf8003262012-03-03 02:35:52 +00001212 /*
1213 * if mapping failed free memory back to system since
1214 * there isn't much point in holding memory we can't use
1215 */
1216 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001217 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001218 bi->page = NULL;
1219
Alexander Duyckf990b792012-01-31 02:59:34 +00001220 rx_ring->rx_stats.alloc_rx_page_failed++;
1221 return false;
1222 }
1223
Alexander Duyckf8003262012-03-03 02:35:52 +00001224 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001225 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001226
Alexander Duyckf990b792012-01-31 02:59:34 +00001227 return true;
1228}
1229
Auke Kok9a799d72007-09-15 14:07:45 -07001230/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001231 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001232 * @rx_ring: ring to place buffers on
1233 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001234 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001235void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001236{
Auke Kok9a799d72007-09-15 14:07:45 -07001237 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001238 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001239 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001240
Alexander Duyckf8003262012-03-03 02:35:52 +00001241 /* nothing to do */
1242 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001243 return;
1244
Alexander Duycke4f74022012-01-31 02:59:44 +00001245 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001246 bi = &rx_ring->rx_buffer_info[i];
1247 i -= rx_ring->count;
1248
Alexander Duyckf8003262012-03-03 02:35:52 +00001249 do {
1250 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001251 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001252
Alexander Duyckf8003262012-03-03 02:35:52 +00001253 /*
1254 * Refresh the desc even if buffer_addrs didn't change
1255 * because each write-back erases this info.
1256 */
1257 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001258
Alexander Duyckf990b792012-01-31 02:59:34 +00001259 rx_desc++;
1260 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001261 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001262 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001263 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001264 bi = rx_ring->rx_buffer_info;
1265 i -= rx_ring->count;
1266 }
1267
1268 /* clear the hdr_addr for the next_to_use descriptor */
1269 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001270
1271 cleaned_count--;
1272 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001273
Alexander Duyckf990b792012-01-31 02:59:34 +00001274 i += rx_ring->count;
1275
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001276 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001277 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001278}
1279
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001280/**
1281 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1282 * @data: pointer to the start of the headers
1283 * @max_len: total length of section to find headers in
1284 *
1285 * This function is meant to determine the length of headers that will
1286 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1287 * motivation of doing this is to only perform one pull for IPv4 TCP
1288 * packets so that we can do basic things like calculating the gso_size
1289 * based on the average data per packet.
1290 **/
1291static unsigned int ixgbe_get_headlen(unsigned char *data,
1292 unsigned int max_len)
1293{
1294 union {
1295 unsigned char *network;
1296 /* l2 headers */
1297 struct ethhdr *eth;
1298 struct vlan_hdr *vlan;
1299 /* l3 headers */
1300 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001301 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001302 } hdr;
1303 __be16 protocol;
1304 u8 nexthdr = 0; /* default to not TCP */
1305 u8 hlen;
1306
1307 /* this should never happen, but better safe than sorry */
1308 if (max_len < ETH_HLEN)
1309 return max_len;
1310
1311 /* initialize network frame pointer */
1312 hdr.network = data;
1313
1314 /* set first protocol and move network header forward */
1315 protocol = hdr.eth->h_proto;
1316 hdr.network += ETH_HLEN;
1317
1318 /* handle any vlan tag if present */
1319 if (protocol == __constant_htons(ETH_P_8021Q)) {
1320 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1321 return max_len;
1322
1323 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1324 hdr.network += VLAN_HLEN;
1325 }
1326
1327 /* handle L3 protocols */
1328 if (protocol == __constant_htons(ETH_P_IP)) {
1329 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1330 return max_len;
1331
1332 /* access ihl as a u8 to avoid unaligned access on ia64 */
1333 hlen = (hdr.network[0] & 0x0F) << 2;
1334
1335 /* verify hlen meets minimum size requirements */
1336 if (hlen < sizeof(struct iphdr))
1337 return hdr.network - data;
1338
Alexander Duycked83da12012-11-13 01:13:33 +00001339 /* record next protocol if header is present */
1340 if (!hdr.ipv4->frag_off)
1341 nexthdr = hdr.ipv4->protocol;
Alexander Duycka048b402012-05-24 08:26:29 +00001342 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1343 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1344 return max_len;
1345
1346 /* record next protocol */
1347 nexthdr = hdr.ipv6->nexthdr;
Alexander Duycked83da12012-11-13 01:13:33 +00001348 hlen = sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001349#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001350 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1351 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1352 return max_len;
Alexander Duycked83da12012-11-13 01:13:33 +00001353 hlen = FCOE_HEADER_LEN;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001354#endif
1355 } else {
1356 return hdr.network - data;
1357 }
1358
Alexander Duycked83da12012-11-13 01:13:33 +00001359 /* relocate pointer to start of L4 header */
1360 hdr.network += hlen;
1361
Alexander Duycka048b402012-05-24 08:26:29 +00001362 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001363 if (nexthdr == IPPROTO_TCP) {
1364 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1365 return max_len;
1366
1367 /* access doff as a u8 to avoid unaligned access on ia64 */
1368 hlen = (hdr.network[12] & 0xF0) >> 2;
1369
1370 /* verify hlen meets minimum size requirements */
1371 if (hlen < sizeof(struct tcphdr))
1372 return hdr.network - data;
1373
1374 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001375 } else if (nexthdr == IPPROTO_UDP) {
1376 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1377 return max_len;
1378
1379 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001380 }
1381
1382 /*
1383 * If everything has gone correctly hdr.network should be the
1384 * data section of the packet and will be the end of the header.
1385 * If not then it probably represents the end of the last recognized
1386 * header.
1387 */
1388 if ((hdr.network - data) < max_len)
1389 return hdr.network - data;
1390 else
1391 return max_len;
1392}
1393
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001394static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1395 struct sk_buff *skb)
1396{
Alexander Duyckf8003262012-03-03 02:35:52 +00001397 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001398
1399 /* set gso_size to avoid messing up TCP MSS */
1400 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1401 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001402 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001403}
1404
1405static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1406 struct sk_buff *skb)
1407{
1408 /* if append_cnt is 0 then frame is not RSC */
1409 if (!IXGBE_CB(skb)->append_cnt)
1410 return;
1411
1412 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1413 rx_ring->rx_stats.rsc_flush++;
1414
1415 ixgbe_set_rsc_gso_size(rx_ring, skb);
1416
1417 /* gso_size is computed using append_cnt so always clear it last */
1418 IXGBE_CB(skb)->append_cnt = 0;
1419}
1420
Alexander Duyck8a0da212012-01-31 02:59:49 +00001421/**
1422 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1423 * @rx_ring: rx descriptor ring packet is being transacted on
1424 * @rx_desc: pointer to the EOP Rx descriptor
1425 * @skb: pointer to current skb being populated
1426 *
1427 * This function checks the ring, descriptor, and packet information in
1428 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1429 * other fields within the skb.
1430 **/
1431static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1432 union ixgbe_adv_rx_desc *rx_desc,
1433 struct sk_buff *skb)
1434{
John Fastabend43e95f12012-05-15 06:12:17 +00001435 struct net_device *dev = rx_ring->netdev;
1436
Alexander Duyck8a0da212012-01-31 02:59:49 +00001437 ixgbe_update_rsc_stats(rx_ring, skb);
1438
1439 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1440
1441 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1442
Jacob Keller6cb562d2012-12-05 07:24:41 +00001443 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001444
John Fastabend43e95f12012-05-15 06:12:17 +00001445 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1446 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001447 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1448 __vlan_hwaccel_put_tag(skb, vid);
1449 }
1450
1451 skb_record_rx_queue(skb, rx_ring->queue_index);
1452
John Fastabend43e95f12012-05-15 06:12:17 +00001453 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001454}
1455
1456static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1457 struct sk_buff *skb)
1458{
1459 struct ixgbe_adapter *adapter = q_vector->adapter;
1460
1461 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1462 napi_gro_receive(&q_vector->napi, skb);
1463 else
1464 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001465}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001466
Alexander Duyckf8003262012-03-03 02:35:52 +00001467/**
1468 * ixgbe_is_non_eop - process handling of non-EOP buffers
1469 * @rx_ring: Rx ring being processed
1470 * @rx_desc: Rx descriptor for current buffer
1471 * @skb: Current socket buffer containing buffer in progress
1472 *
1473 * This function updates next to clean. If the buffer is an EOP buffer
1474 * this function exits returning false, otherwise it will place the
1475 * sk_buff in the next buffer to be chained and return true indicating
1476 * that this is in fact a non-EOP buffer.
1477 **/
1478static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1479 union ixgbe_adv_rx_desc *rx_desc,
1480 struct sk_buff *skb)
1481{
1482 u32 ntc = rx_ring->next_to_clean + 1;
1483
1484 /* fetch, update, and store next to clean */
1485 ntc = (ntc < rx_ring->count) ? ntc : 0;
1486 rx_ring->next_to_clean = ntc;
1487
1488 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1489
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001490 /* update RSC append count if present */
1491 if (ring_is_rsc_enabled(rx_ring)) {
1492 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1493 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1494
1495 if (unlikely(rsc_enabled)) {
1496 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1497
1498 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1499 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1500
1501 /* update ntc based on RSC value */
1502 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1503 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1504 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1505 }
1506 }
1507
1508 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001509 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1510 return false;
1511
Alexander Duyckf8003262012-03-03 02:35:52 +00001512 /* place skb in next buffer to be received */
1513 rx_ring->rx_buffer_info[ntc].skb = skb;
1514 rx_ring->rx_stats.non_eop_descs++;
1515
1516 return true;
1517}
1518
1519/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001520 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1521 * @rx_ring: rx descriptor ring packet is being transacted on
1522 * @skb: pointer to current skb being adjusted
1523 *
1524 * This function is an ixgbe specific version of __pskb_pull_tail. The
1525 * main difference between this version and the original function is that
1526 * this function can make several assumptions about the state of things
1527 * that allow for significant optimizations versus the standard function.
1528 * As a result we can do things like drop a frag and maintain an accurate
1529 * truesize for the skb.
1530 */
1531static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1532 struct sk_buff *skb)
1533{
1534 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1535 unsigned char *va;
1536 unsigned int pull_len;
1537
1538 /*
1539 * it is valid to use page_address instead of kmap since we are
1540 * working with pages allocated out of the lomem pool per
1541 * alloc_page(GFP_ATOMIC)
1542 */
1543 va = skb_frag_address(frag);
1544
1545 /*
1546 * we need the header to contain the greater of either ETH_HLEN or
1547 * 60 bytes if the skb->len is less than 60 for skb_pad.
1548 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001549 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001550
1551 /* align pull length to size of long to optimize memcpy performance */
1552 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1553
1554 /* update all of the pointers */
1555 skb_frag_size_sub(frag, pull_len);
1556 frag->page_offset += pull_len;
1557 skb->data_len -= pull_len;
1558 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001559}
1560
1561/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001562 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1563 * @rx_ring: rx descriptor ring packet is being transacted on
1564 * @skb: pointer to current skb being updated
1565 *
1566 * This function provides a basic DMA sync up for the first fragment of an
1567 * skb. The reason for doing this is that the first fragment cannot be
1568 * unmapped until we have reached the end of packet descriptor for a buffer
1569 * chain.
1570 */
1571static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1572 struct sk_buff *skb)
1573{
1574 /* if the page was released unmap it, else just sync our portion */
1575 if (unlikely(IXGBE_CB(skb)->page_released)) {
1576 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1577 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1578 IXGBE_CB(skb)->page_released = false;
1579 } else {
1580 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1581
1582 dma_sync_single_range_for_cpu(rx_ring->dev,
1583 IXGBE_CB(skb)->dma,
1584 frag->page_offset,
1585 ixgbe_rx_bufsz(rx_ring),
1586 DMA_FROM_DEVICE);
1587 }
1588 IXGBE_CB(skb)->dma = 0;
1589}
1590
1591/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001592 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1593 * @rx_ring: rx descriptor ring packet is being transacted on
1594 * @rx_desc: pointer to the EOP Rx descriptor
1595 * @skb: pointer to current skb being fixed
1596 *
1597 * Check for corrupted packet headers caused by senders on the local L2
1598 * embedded NIC switch not setting up their Tx Descriptors right. These
1599 * should be very rare.
1600 *
1601 * Also address the case where we are pulling data in on pages only
1602 * and as such no data is present in the skb header.
1603 *
1604 * In addition if skb is not at least 60 bytes we need to pad it so that
1605 * it is large enough to qualify as a valid Ethernet frame.
1606 *
1607 * Returns true if an error was encountered and skb was freed.
1608 **/
1609static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1610 union ixgbe_adv_rx_desc *rx_desc,
1611 struct sk_buff *skb)
1612{
Alexander Duyckf8003262012-03-03 02:35:52 +00001613 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001614
1615 /* verify that the packet does not have any known errors */
1616 if (unlikely(ixgbe_test_staterr(rx_desc,
1617 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1618 !(netdev->features & NETIF_F_RXALL))) {
1619 dev_kfree_skb_any(skb);
1620 return true;
1621 }
1622
Alexander Duyck19861ce2012-07-20 08:08:33 +00001623 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001624 if (skb_is_nonlinear(skb))
1625 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001626
Alexander Duyck57efd442012-06-25 21:54:46 +00001627#ifdef IXGBE_FCOE
1628 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1629 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1630 return false;
1631
1632#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001633 /* if skb_pad returns an error the skb was freed */
1634 if (unlikely(skb->len < 60)) {
1635 int pad_len = 60 - skb->len;
1636
1637 if (skb_pad(skb, pad_len))
1638 return true;
1639 __skb_put(skb, pad_len);
1640 }
1641
1642 return false;
1643}
1644
1645/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001646 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1647 * @rx_ring: rx descriptor ring to store buffers on
1648 * @old_buff: donor buffer to have page reused
1649 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001650 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001651 **/
1652static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1653 struct ixgbe_rx_buffer *old_buff)
1654{
1655 struct ixgbe_rx_buffer *new_buff;
1656 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001657
1658 new_buff = &rx_ring->rx_buffer_info[nta];
1659
1660 /* update, and store next to alloc */
1661 nta++;
1662 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1663
1664 /* transfer page from old buffer to new buffer */
1665 new_buff->page = old_buff->page;
1666 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001667 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001668
1669 /* sync the buffer for use by the device */
1670 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001671 new_buff->page_offset,
1672 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001673 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001674}
1675
1676/**
1677 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1678 * @rx_ring: rx descriptor ring to transact packets on
1679 * @rx_buffer: buffer containing page to add
1680 * @rx_desc: descriptor containing length of buffer written by hardware
1681 * @skb: sk_buff to place the data into
1682 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001683 * This function will add the data contained in rx_buffer->page to the skb.
1684 * This is done either through a direct copy if the data in the buffer is
1685 * less than the skb header size, otherwise it will just attach the page as
1686 * a frag to the skb.
1687 *
1688 * The function will then update the page offset if necessary and return
1689 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001690 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001691static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001692 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001693 union ixgbe_adv_rx_desc *rx_desc,
1694 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001695{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001696 struct page *page = rx_buffer->page;
1697 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001698#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001699 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001700#else
1701 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1702 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1703 ixgbe_rx_bufsz(rx_ring);
1704#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001705
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001706 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1707 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1708
1709 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1710
1711 /* we can reuse buffer as-is, just make sure it is local */
1712 if (likely(page_to_nid(page) == numa_node_id()))
1713 return true;
1714
1715 /* this page cannot be reused so discard it */
1716 put_page(page);
1717 return false;
1718 }
1719
Alexander Duyck0549ae22012-07-20 08:08:18 +00001720 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1721 rx_buffer->page_offset, size, truesize);
1722
Alexander Duyck09816fb2012-07-20 08:08:23 +00001723 /* avoid re-using remote pages */
1724 if (unlikely(page_to_nid(page) != numa_node_id()))
1725 return false;
1726
1727#if (PAGE_SIZE < 8192)
1728 /* if we are only owner of page we can reuse it */
1729 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001730 return false;
1731
1732 /* flip page offset to other buffer */
1733 rx_buffer->page_offset ^= truesize;
1734
Alexander Duyck09816fb2012-07-20 08:08:23 +00001735 /*
1736 * since we are the only owner of the page and we need to
1737 * increment it, just set the value to 2 in order to avoid
1738 * an unecessary locked operation
1739 */
1740 atomic_set(&page->_count, 2);
1741#else
1742 /* move offset up to the next cache line */
1743 rx_buffer->page_offset += truesize;
1744
1745 if (rx_buffer->page_offset > last_offset)
1746 return false;
1747
Alexander Duyck0549ae22012-07-20 08:08:18 +00001748 /* bump ref count on page before it is given to the stack */
1749 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001750#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001751
1752 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001753}
1754
Alexander Duyck18806c92012-07-20 08:08:44 +00001755static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1756 union ixgbe_adv_rx_desc *rx_desc)
1757{
1758 struct ixgbe_rx_buffer *rx_buffer;
1759 struct sk_buff *skb;
1760 struct page *page;
1761
1762 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1763 page = rx_buffer->page;
1764 prefetchw(page);
1765
1766 skb = rx_buffer->skb;
1767
1768 if (likely(!skb)) {
1769 void *page_addr = page_address(page) +
1770 rx_buffer->page_offset;
1771
1772 /* prefetch first cache line of first page */
1773 prefetch(page_addr);
1774#if L1_CACHE_BYTES < 128
1775 prefetch(page_addr + L1_CACHE_BYTES);
1776#endif
1777
1778 /* allocate a skb to store the frags */
1779 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1780 IXGBE_RX_HDR_SIZE);
1781 if (unlikely(!skb)) {
1782 rx_ring->rx_stats.alloc_rx_buff_failed++;
1783 return NULL;
1784 }
1785
1786 /*
1787 * we will be copying header into skb->data in
1788 * pskb_may_pull so it is in our interest to prefetch
1789 * it now to avoid a possible cache miss
1790 */
1791 prefetchw(skb->data);
1792
1793 /*
1794 * Delay unmapping of the first packet. It carries the
1795 * header information, HW may still access the header
1796 * after the writeback. Only unmap it when EOP is
1797 * reached
1798 */
1799 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1800 goto dma_sync;
1801
1802 IXGBE_CB(skb)->dma = rx_buffer->dma;
1803 } else {
1804 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1805 ixgbe_dma_sync_frag(rx_ring, skb);
1806
1807dma_sync:
1808 /* we are reusing so sync this buffer for CPU use */
1809 dma_sync_single_range_for_cpu(rx_ring->dev,
1810 rx_buffer->dma,
1811 rx_buffer->page_offset,
1812 ixgbe_rx_bufsz(rx_ring),
1813 DMA_FROM_DEVICE);
1814 }
1815
1816 /* pull page into skb */
1817 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1818 /* hand second half of page back to the ring */
1819 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1820 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1821 /* the page has been released from the ring */
1822 IXGBE_CB(skb)->page_released = true;
1823 } else {
1824 /* we are not reusing the buffer so unmap it */
1825 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1826 ixgbe_rx_pg_size(rx_ring),
1827 DMA_FROM_DEVICE);
1828 }
1829
1830 /* clear contents of buffer_info */
1831 rx_buffer->skb = NULL;
1832 rx_buffer->dma = 0;
1833 rx_buffer->page = NULL;
1834
1835 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001836}
1837
1838/**
1839 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1840 * @q_vector: structure containing interrupt and ring information
1841 * @rx_ring: rx descriptor ring to transact packets on
1842 * @budget: Total limit on number of packets to process
1843 *
1844 * This function provides a "bounce buffer" approach to Rx interrupt
1845 * processing. The advantage to this is that on systems that have
1846 * expensive overhead for IOMMU access this provides a means of avoiding
1847 * it by maintaining the mapping of the page to the syste.
1848 *
1849 * Returns true if all work is completed without reaching budget
1850 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001851static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001852 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001853 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001854{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001855 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001856#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001857 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001858 int ddp_bytes;
1859 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001860#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001861 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001862
Alexander Duyckf8003262012-03-03 02:35:52 +00001863 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001864 union ixgbe_adv_rx_desc *rx_desc;
1865 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001866
Alexander Duyckf8003262012-03-03 02:35:52 +00001867 /* return some buffers to hardware, one at a time is too slow */
1868 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1869 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1870 cleaned_count = 0;
1871 }
Auke Kok9a799d72007-09-15 14:07:45 -07001872
Alexander Duyck18806c92012-07-20 08:08:44 +00001873 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001874
Alexander Duyckf8003262012-03-03 02:35:52 +00001875 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1876 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001877
Alexander Duyckf8003262012-03-03 02:35:52 +00001878 /*
1879 * This memory barrier is needed to keep us from reading
1880 * any other fields out of the rx_desc until we know the
1881 * RXD_STAT_DD bit is set
1882 */
1883 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001884
Alexander Duyck18806c92012-07-20 08:08:44 +00001885 /* retrieve a buffer from the ring */
1886 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001887
Alexander Duyck18806c92012-07-20 08:08:44 +00001888 /* exit if we failed to retrieve a buffer */
1889 if (!skb)
1890 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001891
Auke Kok9a799d72007-09-15 14:07:45 -07001892 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001893
Alexander Duyckf8003262012-03-03 02:35:52 +00001894 /* place incomplete frames back on ring for completion */
1895 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1896 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001897
Alexander Duyckf8003262012-03-03 02:35:52 +00001898 /* verify the packet layout is correct */
1899 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1900 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001901
1902 /* probably a little skewed due to removing CRC */
1903 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001904
Alexander Duyck8a0da212012-01-31 02:59:49 +00001905 /* populate checksum, timestamp, VLAN, and protocol */
1906 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1907
Yi Zou332d4a72009-05-13 13:11:53 +00001908#ifdef IXGBE_FCOE
1909 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001910 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001911 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001912 /* include DDPed FCoE data */
1913 if (ddp_bytes > 0) {
1914 if (!mss) {
1915 mss = rx_ring->netdev->mtu -
1916 sizeof(struct fcoe_hdr) -
1917 sizeof(struct fc_frame_header) -
1918 sizeof(struct fcoe_crc_eof);
1919 if (mss > 512)
1920 mss &= ~511;
1921 }
1922 total_rx_bytes += ddp_bytes;
1923 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1924 mss);
1925 }
David S. Miller823dcd22011-08-20 10:39:12 -07001926 if (!ddp_bytes) {
1927 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001928 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001929 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001930 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001931
Yi Zou332d4a72009-05-13 13:11:53 +00001932#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001933 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001934
Alexander Duyckf8003262012-03-03 02:35:52 +00001935 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001936 total_rx_packets++;
1937 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001938
Alexander Duyckc267fc12010-11-16 19:27:00 -08001939 u64_stats_update_begin(&rx_ring->syncp);
1940 rx_ring->stats.packets += total_rx_packets;
1941 rx_ring->stats.bytes += total_rx_bytes;
1942 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001943 q_vector->rx.total_packets += total_rx_packets;
1944 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001945
Alexander Duyckf8003262012-03-03 02:35:52 +00001946 if (cleaned_count)
1947 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1948
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001949 return (total_rx_packets < budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001950}
1951
Auke Kok9a799d72007-09-15 14:07:45 -07001952/**
1953 * ixgbe_configure_msix - Configure MSI-X hardware
1954 * @adapter: board private structure
1955 *
1956 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1957 * interrupts.
1958 **/
1959static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1960{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001961 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001962 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001963 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001964
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001965 /* Populate MSIX to EITR Select */
1966 if (adapter->num_vfs > 32) {
1967 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1968 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1969 }
1970
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001971 /*
1972 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001973 * corresponding register.
1974 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001975 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001976 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001977 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001978
Alexander Duycka5579282012-02-08 07:50:04 +00001979 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001980 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001981
Alexander Duycka5579282012-02-08 07:50:04 +00001982 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001983 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001984
Alexander Duyckfe49f042009-06-04 16:00:09 +00001985 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001986 }
1987
Alexander Duyckbd508172010-11-16 19:27:03 -08001988 switch (adapter->hw.mac.type) {
1989 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001990 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001991 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001992 break;
1993 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001994 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001995 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001996 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001997 default:
1998 break;
1999 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002000 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002001
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002002 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002003 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002004 mask &= ~(IXGBE_EIMS_OTHER |
2005 IXGBE_EIMS_MAILBOX |
2006 IXGBE_EIMS_LSC);
2007
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002008 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002009}
2010
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002011enum latency_range {
2012 lowest_latency = 0,
2013 low_latency = 1,
2014 bulk_latency = 2,
2015 latency_invalid = 255
2016};
2017
2018/**
2019 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002020 * @q_vector: structure containing interrupt and ring information
2021 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002022 *
2023 * Stores a new ITR value based on packets and byte
2024 * counts during the last interrupt. The advantage of per interrupt
2025 * computation is faster updates and more accurate ITR for the current
2026 * traffic pattern. Constants in this function were computed
2027 * based on theoretical maximum wire speed and thresholds were set based
2028 * on testing data as well as attempting to minimize response time
2029 * while increasing bulk throughput.
2030 * this functionality is controlled by the InterruptThrottleRate module
2031 * parameter (see ixgbe_param.c)
2032 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002033static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2034 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002035{
Alexander Duyckbd198052011-06-11 01:45:08 +00002036 int bytes = ring_container->total_bytes;
2037 int packets = ring_container->total_packets;
2038 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002039 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002040 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002041
2042 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002043 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002044
2045 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002046 * 0-10MB/s lowest (100000 ints/s)
2047 * 10-20MB/s low (20000 ints/s)
2048 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002049 */
2050 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002051 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002052 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2053
2054 switch (itr_setting) {
2055 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002056 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002057 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002058 break;
2059 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002060 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002061 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002062 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002063 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002064 break;
2065 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002066 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002067 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002068 break;
2069 }
2070
Alexander Duyckbd198052011-06-11 01:45:08 +00002071 /* clear work counters since we have the values we need */
2072 ring_container->total_bytes = 0;
2073 ring_container->total_packets = 0;
2074
2075 /* write updated itr to ring container */
2076 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002077}
2078
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002079/**
2080 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002081 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002082 *
2083 * This function is made to be called by ethtool and by the driver
2084 * when it needs to update EITR registers at runtime. Hardware
2085 * specific quirks/differences are taken care of here.
2086 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002087void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002088{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002089 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002090 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002091 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002092 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002093
Alexander Duyckbd508172010-11-16 19:27:03 -08002094 switch (adapter->hw.mac.type) {
2095 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002096 /* must write high and low 16 bits to reset counter */
2097 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002098 break;
2099 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002100 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002101 /*
2102 * set the WDIS bit to not clear the timer bits and cause an
2103 * immediate assertion of the interrupt
2104 */
2105 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002106 break;
2107 default:
2108 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002109 }
2110 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2111}
2112
Alexander Duyckbd198052011-06-11 01:45:08 +00002113static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002114{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002115 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002116 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002117
Alexander Duyckbd198052011-06-11 01:45:08 +00002118 ixgbe_update_itr(q_vector, &q_vector->tx);
2119 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002120
Alexander Duyck08c88332011-06-11 01:45:03 +00002121 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002122
2123 switch (current_itr) {
2124 /* counts and packets in update_itr are dependent on these numbers */
2125 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002126 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002127 break;
2128 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002129 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002130 break;
2131 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002132 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002133 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002134 default:
2135 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002136 }
2137
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002138 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002139 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002140 new_itr = (10 * new_itr * q_vector->itr) /
2141 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002142
Alexander Duyckbd198052011-06-11 01:45:08 +00002143 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002144 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002145
2146 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002147 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002148}
2149
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002150/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002151 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002152 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002153 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002154static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002155{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002156 struct ixgbe_hw *hw = &adapter->hw;
2157 u32 eicr = adapter->interrupt_event;
2158
Alexander Duyckf0f97782011-04-22 04:08:09 +00002159 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002160 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002161
Alexander Duyckf0f97782011-04-22 04:08:09 +00002162 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2163 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2164 return;
2165
2166 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2167
Joe Perches7ca647b2010-09-07 21:35:40 +00002168 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002169 case IXGBE_DEV_ID_82599_T3_LOM:
2170 /*
2171 * Since the warning interrupt is for both ports
2172 * we don't have to check if:
2173 * - This interrupt wasn't for our port.
2174 * - We may have missed the interrupt so always have to
2175 * check if we got a LSC
2176 */
2177 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2178 !(eicr & IXGBE_EICR_LSC))
2179 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002180
Alexander Duyckf0f97782011-04-22 04:08:09 +00002181 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002182 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002183 bool link_up = false;
2184
Josh Hay3d292262012-12-15 03:28:19 +00002185 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002186
Alexander Duyckf0f97782011-04-22 04:08:09 +00002187 if (link_up)
2188 return;
2189 }
2190
2191 /* Check if this is not due to overtemp */
2192 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2193 return;
2194
2195 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002196 default:
2197 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2198 return;
2199 break;
2200 }
2201 e_crit(drv,
2202 "Network adapter has been stopped because it has over heated. "
2203 "Restart the computer. If the problem persists, "
2204 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002205
2206 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002207}
2208
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002209static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2210{
2211 struct ixgbe_hw *hw = &adapter->hw;
2212
2213 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2214 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002215 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002216 /* write to clear the interrupt */
2217 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2218 }
2219}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002220
Jacob Keller4f51bf72011-08-20 04:49:45 +00002221static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2222{
2223 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2224 return;
2225
2226 switch (adapter->hw.mac.type) {
2227 case ixgbe_mac_82599EB:
2228 /*
2229 * Need to check link state so complete overtemp check
2230 * on service task
2231 */
2232 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2233 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2234 adapter->interrupt_event = eicr;
2235 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2236 ixgbe_service_event_schedule(adapter);
2237 return;
2238 }
2239 return;
2240 case ixgbe_mac_X540:
2241 if (!(eicr & IXGBE_EICR_TS))
2242 return;
2243 break;
2244 default:
2245 return;
2246 }
2247
2248 e_crit(drv,
2249 "Network adapter has been stopped because it has over heated. "
2250 "Restart the computer. If the problem persists, "
2251 "power off the system and replace the adapter\n");
2252}
2253
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002254static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2255{
2256 struct ixgbe_hw *hw = &adapter->hw;
2257
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002258 if (eicr & IXGBE_EICR_GPI_SDP2) {
2259 /* Clear the interrupt */
2260 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002261 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2262 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2263 ixgbe_service_event_schedule(adapter);
2264 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002265 }
2266
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002267 if (eicr & IXGBE_EICR_GPI_SDP1) {
2268 /* Clear the interrupt */
2269 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002270 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2271 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2272 ixgbe_service_event_schedule(adapter);
2273 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002274 }
2275}
2276
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002277static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2278{
2279 struct ixgbe_hw *hw = &adapter->hw;
2280
2281 adapter->lsc_int++;
2282 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2283 adapter->link_check_timeout = jiffies;
2284 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2285 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002286 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002287 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002288 }
2289}
2290
Alexander Duyckfe49f042009-06-04 16:00:09 +00002291static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2292 u64 qmask)
2293{
2294 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002295 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002296
Alexander Duyckbd508172010-11-16 19:27:03 -08002297 switch (hw->mac.type) {
2298 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002299 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002300 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2301 break;
2302 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002303 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002304 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002305 if (mask)
2306 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002307 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002308 if (mask)
2309 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2310 break;
2311 default:
2312 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002313 }
2314 /* skip the flush */
2315}
2316
2317static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002318 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002319{
2320 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002321 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002322
Alexander Duyckbd508172010-11-16 19:27:03 -08002323 switch (hw->mac.type) {
2324 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002325 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002326 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2327 break;
2328 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002329 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002330 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002331 if (mask)
2332 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002333 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002334 if (mask)
2335 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2336 break;
2337 default:
2338 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002339 }
2340 /* skip the flush */
2341}
2342
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002343/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002344 * ixgbe_irq_enable - Enable default interrupt generation settings
2345 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002347static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2348 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002349{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002350 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002351
Alexander Duyck2c4af692011-07-15 07:29:55 +00002352 /* don't reenable LSC while waiting for link */
2353 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2354 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002355
Alexander Duyck2c4af692011-07-15 07:29:55 +00002356 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002357 switch (adapter->hw.mac.type) {
2358 case ixgbe_mac_82599EB:
2359 mask |= IXGBE_EIMS_GPI_SDP0;
2360 break;
2361 case ixgbe_mac_X540:
2362 mask |= IXGBE_EIMS_TS;
2363 break;
2364 default:
2365 break;
2366 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002367 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2368 mask |= IXGBE_EIMS_GPI_SDP1;
2369 switch (adapter->hw.mac.type) {
2370 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002371 mask |= IXGBE_EIMS_GPI_SDP1;
2372 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002373 case ixgbe_mac_X540:
2374 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002375 mask |= IXGBE_EIMS_MAILBOX;
2376 break;
2377 default:
2378 break;
2379 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002380
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002381 if (adapter->hw.mac.type == ixgbe_mac_X540)
2382 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002383
Alexander Duyck2c4af692011-07-15 07:29:55 +00002384 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2385 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2386 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002387
Alexander Duyck2c4af692011-07-15 07:29:55 +00002388 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2389 if (queues)
2390 ixgbe_irq_enable_queues(adapter, ~0);
2391 if (flush)
2392 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002393}
2394
Alexander Duyck2c4af692011-07-15 07:29:55 +00002395static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002396{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002397 struct ixgbe_adapter *adapter = data;
2398 struct ixgbe_hw *hw = &adapter->hw;
2399 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002400
Alexander Duyck2c4af692011-07-15 07:29:55 +00002401 /*
2402 * Workaround for Silicon errata. Use clear-by-write instead
2403 * of clear-by-read. Reading with EICS will return the
2404 * interrupt causes without clearing, which later be done
2405 * with the write to EICR.
2406 */
2407 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2408 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002409
Alexander Duyck2c4af692011-07-15 07:29:55 +00002410 if (eicr & IXGBE_EICR_LSC)
2411 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002412
Alexander Duyck2c4af692011-07-15 07:29:55 +00002413 if (eicr & IXGBE_EICR_MAILBOX)
2414 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002415
Alexander Duyck2c4af692011-07-15 07:29:55 +00002416 switch (hw->mac.type) {
2417 case ixgbe_mac_82599EB:
2418 case ixgbe_mac_X540:
2419 if (eicr & IXGBE_EICR_ECC)
2420 e_info(link, "Received unrecoverable ECC Err, please "
2421 "reboot\n");
2422 /* Handle Flow Director Full threshold interrupt */
2423 if (eicr & IXGBE_EICR_FLOW_DIR) {
2424 int reinit_count = 0;
2425 int i;
2426 for (i = 0; i < adapter->num_tx_queues; i++) {
2427 struct ixgbe_ring *ring = adapter->tx_ring[i];
2428 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2429 &ring->state))
2430 reinit_count++;
2431 }
2432 if (reinit_count) {
2433 /* no more flow director interrupts until after init */
2434 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2435 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2436 ixgbe_service_event_schedule(adapter);
2437 }
2438 }
2439 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002440 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002441 break;
2442 default:
2443 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002444 }
2445
Alexander Duyck2c4af692011-07-15 07:29:55 +00002446 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002447
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002448 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2449 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002450
Alexander Duyck2c4af692011-07-15 07:29:55 +00002451 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002452 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002453 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002454
Alexander Duyck2c4af692011-07-15 07:29:55 +00002455 return IRQ_HANDLED;
2456}
2457
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002458static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002459{
2460 struct ixgbe_q_vector *q_vector = data;
2461
Auke Kok9a799d72007-09-15 14:07:45 -07002462 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002463
2464 if (q_vector->rx.ring || q_vector->tx.ring)
2465 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002466
2467 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002468}
2469
Auke Kok9a799d72007-09-15 14:07:45 -07002470/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002471 * ixgbe_poll - NAPI Rx polling callback
2472 * @napi: structure for representing this polling device
2473 * @budget: how many packets driver is allowed to clean
2474 *
2475 * This function is used for legacy and MSI, NAPI mode
2476 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002477int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002478{
2479 struct ixgbe_q_vector *q_vector =
2480 container_of(napi, struct ixgbe_q_vector, napi);
2481 struct ixgbe_adapter *adapter = q_vector->adapter;
2482 struct ixgbe_ring *ring;
2483 int per_ring_budget;
2484 bool clean_complete = true;
2485
2486#ifdef CONFIG_IXGBE_DCA
2487 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2488 ixgbe_update_dca(q_vector);
2489#endif
2490
2491 ixgbe_for_each_ring(ring, q_vector->tx)
2492 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2493
2494 /* attempt to distribute budget to each queue fairly, but don't allow
2495 * the budget to go below 1 because we'll exit polling */
2496 if (q_vector->rx.count > 1)
2497 per_ring_budget = max(budget/q_vector->rx.count, 1);
2498 else
2499 per_ring_budget = budget;
2500
2501 ixgbe_for_each_ring(ring, q_vector->rx)
2502 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2503 per_ring_budget);
2504
2505 /* If all work not completed, return budget and keep polling */
2506 if (!clean_complete)
2507 return budget;
2508
2509 /* all work done, exit the polling mode */
2510 napi_complete(napi);
2511 if (adapter->rx_itr_setting & 1)
2512 ixgbe_set_itr(q_vector);
2513 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2514 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2515
2516 return 0;
2517}
2518
2519/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2521 * @adapter: board private structure
2522 *
2523 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2524 * interrupts from the kernel.
2525 **/
2526static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2527{
2528 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002529 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002530 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002531
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002532 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002533 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002534 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002535
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002536 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002537 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002538 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002539 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002540 } else if (q_vector->rx.ring) {
2541 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2542 "%s-%s-%d", netdev->name, "rx", ri++);
2543 } else if (q_vector->tx.ring) {
2544 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2545 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002546 } else {
2547 /* skip this unused q_vector */
2548 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002549 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002550 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2551 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002552 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002553 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002554 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002555 goto free_queue_irqs;
2556 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002557 /* If Flow Director is enabled, set interrupt affinity */
2558 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2559 /* assign the mask for this irq */
2560 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002561 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002562 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002563 }
2564
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002566 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002568 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002569 goto free_queue_irqs;
2570 }
2571
2572 return 0;
2573
2574free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002575 while (vector) {
2576 vector--;
2577 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2578 NULL);
2579 free_irq(adapter->msix_entries[vector].vector,
2580 adapter->q_vector[vector]);
2581 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002582 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2583 pci_disable_msix(adapter->pdev);
2584 kfree(adapter->msix_entries);
2585 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002586 return err;
2587}
2588
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002589/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002590 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002591 * @irq: interrupt number
2592 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002593 **/
2594static irqreturn_t ixgbe_intr(int irq, void *data)
2595{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002596 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002597 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002598 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002599 u32 eicr;
2600
Don Skidmore54037502009-02-21 15:42:56 -08002601 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002602 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002603 * before the read of EICR.
2604 */
2605 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2606
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002607 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002608 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002610 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002611 /*
2612 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002613 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002614 * have disabled interrupts due to EIAM
2615 * finish the workaround of silicon errata on 82598. Unmask
2616 * the interrupt that we masked before the EICR read.
2617 */
2618 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2619 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002620 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002621 }
Auke Kok9a799d72007-09-15 14:07:45 -07002622
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002623 if (eicr & IXGBE_EICR_LSC)
2624 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002625
Alexander Duyckbd508172010-11-16 19:27:03 -08002626 switch (hw->mac.type) {
2627 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002628 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002629 /* Fall through */
2630 case ixgbe_mac_X540:
2631 if (eicr & IXGBE_EICR_ECC)
2632 e_info(link, "Received unrecoverable ECC err, please "
2633 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002634 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002635 break;
2636 default:
2637 break;
2638 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002639
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002640 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002641 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2642 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002643
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002644 /* would disable interrupts here but EIAM disabled it */
2645 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002646
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002647 /*
2648 * re-enable link(maybe) and non-queue interrupts, no flush.
2649 * ixgbe_poll will re-enable the queue interrupts
2650 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002651 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2652 ixgbe_irq_enable(adapter, false, false);
2653
Auke Kok9a799d72007-09-15 14:07:45 -07002654 return IRQ_HANDLED;
2655}
2656
2657/**
2658 * ixgbe_request_irq - initialize interrupts
2659 * @adapter: board private structure
2660 *
2661 * Attempts to configure interrupts using the best available
2662 * capabilities of the hardware and kernel.
2663 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002664static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002665{
2666 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002667 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002668
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002669 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002670 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002671 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002672 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002673 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002674 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002675 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002676 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002677
Alexander Duyckde88eee2012-02-08 07:49:59 +00002678 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002679 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002680
Auke Kok9a799d72007-09-15 14:07:45 -07002681 return err;
2682}
2683
2684static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2685{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002686 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002687
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002688 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002689 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002690 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002691 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002692
2693 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2694 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2695 struct msix_entry *entry = &adapter->msix_entries[vector];
2696
2697 /* free only the irqs that were actually requested */
2698 if (!q_vector->rx.ring && !q_vector->tx.ring)
2699 continue;
2700
2701 /* clear the affinity_mask in the IRQ descriptor */
2702 irq_set_affinity_hint(entry->vector, NULL);
2703
2704 free_irq(entry->vector, q_vector);
2705 }
2706
2707 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002708}
2709
2710/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002711 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2712 * @adapter: board private structure
2713 **/
2714static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2715{
Alexander Duyckbd508172010-11-16 19:27:03 -08002716 switch (adapter->hw.mac.type) {
2717 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002718 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002719 break;
2720 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002721 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002722 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2723 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002724 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002725 break;
2726 default:
2727 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002728 }
2729 IXGBE_WRITE_FLUSH(&adapter->hw);
2730 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002731 int vector;
2732
2733 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2734 synchronize_irq(adapter->msix_entries[vector].vector);
2735
2736 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002737 } else {
2738 synchronize_irq(adapter->pdev->irq);
2739 }
2740}
2741
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002742/**
Auke Kok9a799d72007-09-15 14:07:45 -07002743 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2744 *
2745 **/
2746static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2747{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002748 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002749
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002750 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002751
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002752 ixgbe_set_ivar(adapter, 0, 0, 0);
2753 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002754
Emil Tantilov396e7992010-07-01 20:05:12 +00002755 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002756}
2757
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002758/**
2759 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2760 * @adapter: board private structure
2761 * @ring: structure containing ring specific data
2762 *
2763 * Configure the Tx descriptor ring after a reset.
2764 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002765void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2766 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002767{
2768 struct ixgbe_hw *hw = &adapter->hw;
2769 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002770 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002771 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002772 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002773
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002774 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002775 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002776 IXGBE_WRITE_FLUSH(hw);
2777
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002778 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002779 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002780 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2781 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2782 ring->count * sizeof(union ixgbe_adv_tx_desc));
2783 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2784 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002785 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002786
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002787 /*
2788 * set WTHRESH to encourage burst writeback, it should not be set
2789 * higher than 1 when ITR is 0 as it could cause false TX hangs
2790 *
2791 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2792 * to or less than the number of on chip descriptors, which is
2793 * currently 40.
2794 */
Alexander Duycke954b372012-02-08 07:49:38 +00002795 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002796 txdctl |= (1 << 16); /* WTHRESH = 1 */
2797 else
2798 txdctl |= (8 << 16); /* WTHRESH = 8 */
2799
Alexander Duycke954b372012-02-08 07:49:38 +00002800 /*
2801 * Setting PTHRESH to 32 both improves performance
2802 * and avoids a TX hang with DFP enabled
2803 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002804 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2805 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002806
2807 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002808 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002809 ring->atr_sample_rate = adapter->atr_sample_rate;
2810 ring->atr_count = 0;
2811 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2812 } else {
2813 ring->atr_sample_rate = 0;
2814 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002815
Alexander Duyckfd786b72013-01-12 06:33:31 +00002816 /* initialize XPS */
2817 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
2818 struct ixgbe_q_vector *q_vector = ring->q_vector;
2819
2820 if (q_vector)
2821 netif_set_xps_queue(adapter->netdev,
2822 &q_vector->affinity_mask,
2823 ring->queue_index);
2824 }
2825
John Fastabendc84d3242010-11-16 19:27:12 -08002826 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2827
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002828 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002829 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2830
2831 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2832 if (hw->mac.type == ixgbe_mac_82598EB &&
2833 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2834 return;
2835
2836 /* poll to verify queue is enabled */
2837 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002838 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002839 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2840 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2841 if (!wait_loop)
2842 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002843}
2844
Alexander Duyck120ff942010-08-19 13:34:50 +00002845static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2846{
2847 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002848 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002849 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002850
2851 if (hw->mac.type == ixgbe_mac_82598EB)
2852 return;
2853
2854 /* disable the arbiter while setting MTQC */
2855 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2856 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2857 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2858
2859 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002860 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2861 mtqc = IXGBE_MTQC_VT_ENA;
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 if (adapter->ring_feature[RING_F_RSS].indices == 4)
2867 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002868 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002869 mtqc |= IXGBE_MTQC_64VF;
2870 } else {
2871 if (tcs > 4)
2872 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2873 else if (tcs > 1)
2874 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2875 else
2876 mtqc = IXGBE_MTQC_64Q_1PB;
2877 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002878
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002879 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002880
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002881 /* Enable Security TX Buffer IFG for multiple pb */
2882 if (tcs) {
2883 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2884 sectx |= IXGBE_SECTX_DCB;
2885 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002886 }
2887
2888 /* re-enable the arbiter */
2889 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2890 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2891}
2892
Auke Kok9a799d72007-09-15 14:07:45 -07002893/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002894 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002895 * @adapter: board private structure
2896 *
2897 * Configure the Tx unit of the MAC after a reset.
2898 **/
2899static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2900{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002901 struct ixgbe_hw *hw = &adapter->hw;
2902 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002903 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002904
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002905 ixgbe_setup_mtqc(adapter);
2906
2907 if (hw->mac.type != ixgbe_mac_82598EB) {
2908 /* DMATXCTL.EN must be before Tx queues are enabled */
2909 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2910 dmatxctl |= IXGBE_DMATXCTL_TE;
2911 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2912 }
2913
Auke Kok9a799d72007-09-15 14:07:45 -07002914 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002915 for (i = 0; i < adapter->num_tx_queues; i++)
2916 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002917}
2918
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002919static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2920 struct ixgbe_ring *ring)
2921{
2922 struct ixgbe_hw *hw = &adapter->hw;
2923 u8 reg_idx = ring->reg_idx;
2924 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2925
2926 srrctl |= IXGBE_SRRCTL_DROP_EN;
2927
2928 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2929}
2930
2931static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2932 struct ixgbe_ring *ring)
2933{
2934 struct ixgbe_hw *hw = &adapter->hw;
2935 u8 reg_idx = ring->reg_idx;
2936 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2937
2938 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2939
2940 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2941}
2942
2943#ifdef CONFIG_IXGBE_DCB
2944void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2945#else
2946static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2947#endif
2948{
2949 int i;
2950 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2951
2952 if (adapter->ixgbe_ieee_pfc)
2953 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2954
2955 /*
2956 * We should set the drop enable bit if:
2957 * SR-IOV is enabled
2958 * or
2959 * Number of Rx queues > 1 and flow control is disabled
2960 *
2961 * This allows us to avoid head of line blocking for security
2962 * and performance reasons.
2963 */
2964 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2965 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2966 for (i = 0; i < adapter->num_rx_queues; i++)
2967 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2968 } else {
2969 for (i = 0; i < adapter->num_rx_queues; i++)
2970 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2971 }
2972}
2973
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002974#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002975
Yi Zoua6616b42009-08-06 13:05:23 +00002976static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002977 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002978{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002979 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002980 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002981 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002982
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002983 if (hw->mac.type == ixgbe_mac_82598EB) {
2984 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2985
2986 /*
2987 * if VMDq is not active we must program one srrctl register
2988 * per RSS queue since we have enabled RDRXCTL.MVMEN
2989 */
2990 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002991 }
2992
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002993 /* configure header buffer length, needed for RSC */
2994 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002995
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002996 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00002997 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002998
2999 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003000 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003001
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003002 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003003}
3004
Alexander Duyck05abb122010-08-19 13:35:41 +00003005static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003006{
Alexander Duyck05abb122010-08-19 13:35:41 +00003007 struct ixgbe_hw *hw = &adapter->hw;
3008 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003009 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3010 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003011 u32 mrqc = 0, reta = 0;
3012 u32 rxcsum;
3013 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003014 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003015
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003016 /*
3017 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3018 * make full use of any rings they may have. We will use the
3019 * PSRTYPE register to control how many rings we use within the PF.
3020 */
3021 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3022 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003023
Alexander Duyck05abb122010-08-19 13:35:41 +00003024 /* Fill out hash function seeds */
3025 for (i = 0; i < 10; i++)
3026 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003027
Alexander Duyck05abb122010-08-19 13:35:41 +00003028 /* Fill out redirection table */
3029 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003030 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003031 j = 0;
3032 /* reta = 4-byte sliding window of
3033 * 0x00..(indices-1)(indices-1)00..etc. */
3034 reta = (reta << 8) | (j * 0x11);
3035 if ((i & 3) == 3)
3036 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3037 }
3038
3039 /* Disable indicating checksum in descriptor, enables RSS hash */
3040 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3041 rxcsum |= IXGBE_RXCSUM_PCSD;
3042 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3043
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003044 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003045 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003046 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003047 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003048 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003049
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003050 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3051 if (tcs > 4)
3052 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3053 else if (tcs > 1)
3054 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3055 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3056 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3057 else
3058 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3059 } else {
3060 if (tcs > 4)
3061 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3062 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003063 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3064 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003065 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003066 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003067 }
3068
Alexander Duyck05abb122010-08-19 13:35:41 +00003069 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003070 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3071 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3072 IXGBE_MRQC_RSS_FIELD_IPV6 |
3073 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003074
Alexander Duyckef6afc02012-02-08 07:51:53 +00003075 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3076 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3077 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3078 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3079
Alexander Duyck05abb122010-08-19 13:35:41 +00003080 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003081}
3082
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003083/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003084 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3085 * @adapter: address of board private structure
3086 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003087 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003088static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003089 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003090{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003091 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003092 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003093 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003094
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003095 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003096 return;
3097
Alexander Duyck73670962010-08-19 13:38:34 +00003098 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003099 rscctrl |= IXGBE_RSCCTL_RSCEN;
3100 /*
3101 * we must limit the number of descriptors so that the
3102 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003103 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003104 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003105 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003106 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003107}
3108
Alexander Duyck9e10e042010-08-19 13:40:06 +00003109#define IXGBE_MAX_RX_DESC_POLL 10
3110static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3111 struct ixgbe_ring *ring)
3112{
3113 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003114 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3115 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003116 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003117
3118 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3119 if (hw->mac.type == ixgbe_mac_82598EB &&
3120 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3121 return;
3122
3123 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003124 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003125 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3126 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3127
3128 if (!wait_loop) {
3129 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3130 "the polling period\n", reg_idx);
3131 }
3132}
3133
Yi Zou2d39d572011-01-06 14:29:56 +00003134void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3135 struct ixgbe_ring *ring)
3136{
3137 struct ixgbe_hw *hw = &adapter->hw;
3138 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3139 u32 rxdctl;
3140 u8 reg_idx = ring->reg_idx;
3141
3142 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3143 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3144
3145 /* write value back with RXDCTL.ENABLE bit cleared */
3146 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3147
3148 if (hw->mac.type == ixgbe_mac_82598EB &&
3149 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3150 return;
3151
3152 /* the hardware may take up to 100us to really disable the rx queue */
3153 do {
3154 udelay(10);
3155 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3156 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3157
3158 if (!wait_loop) {
3159 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3160 "the polling period\n", reg_idx);
3161 }
3162}
3163
Alexander Duyck84418e32010-08-19 13:40:54 +00003164void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3165 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003166{
3167 struct ixgbe_hw *hw = &adapter->hw;
3168 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003169 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003170 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003171
Alexander Duyck9e10e042010-08-19 13:40:06 +00003172 /* disable queue to avoid issues while updating state */
3173 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003174 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003175
Alexander Duyckacd37172010-08-19 13:36:05 +00003176 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3177 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3178 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3179 ring->count * sizeof(union ixgbe_adv_rx_desc));
3180 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3181 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003182 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003183
3184 ixgbe_configure_srrctl(adapter, ring);
3185 ixgbe_configure_rscctl(adapter, ring);
3186
3187 if (hw->mac.type == ixgbe_mac_82598EB) {
3188 /*
3189 * enable cache line friendly hardware writes:
3190 * PTHRESH=32 descriptors (half the internal cache),
3191 * this also removes ugly rx_no_buffer_count increment
3192 * HTHRESH=4 descriptors (to minimize latency on fetch)
3193 * WTHRESH=8 burst writeback up to two cache lines
3194 */
3195 rxdctl &= ~0x3FFFFF;
3196 rxdctl |= 0x080420;
3197 }
3198
3199 /* enable receive descriptor ring */
3200 rxdctl |= IXGBE_RXDCTL_ENABLE;
3201 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3202
3203 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003204 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003205}
3206
Alexander Duyck48654522010-08-19 13:36:27 +00003207static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3208{
3209 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003210 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003211 int p;
3212
3213 /* PSRTYPE must be initialized in non 82598 adapters */
3214 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003215 IXGBE_PSRTYPE_UDPHDR |
3216 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003217 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003218 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003219
3220 if (hw->mac.type == ixgbe_mac_82598EB)
3221 return;
3222
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003223 if (rss_i > 3)
3224 psrtype |= 2 << 29;
3225 else if (rss_i > 1)
3226 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003227
3228 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003229 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003230 psrtype);
3231}
3232
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003233static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3234{
3235 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003236 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003237 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003238 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003239
3240 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3241 return;
3242
3243 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003244 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3245 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003246 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003247 vmdctl |= IXGBE_VT_CTL_REPLEN;
3248 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003249
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003250 vf_shift = VMDQ_P(0) % 32;
3251 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003252
3253 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003254 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3255 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3256 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3257 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003258 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3259 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003260
3261 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003262 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003263
3264 /*
3265 * Set up VF register offsets for selected VT Mode,
3266 * i.e. 32 or 64 VFs for SR-IOV
3267 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003268 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3269 case IXGBE_82599_VMDQ_8Q_MASK:
3270 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3271 break;
3272 case IXGBE_82599_VMDQ_4Q_MASK:
3273 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3274 break;
3275 default:
3276 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3277 break;
3278 }
3279
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003280 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3281
Alexander Duyck435b19f2012-05-18 06:34:08 +00003282
Greg Rosea985b6c32010-11-18 03:02:52 +00003283 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003284 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003285 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003286 /* For VFs that have spoof checking turned off */
3287 for (i = 0; i < adapter->num_vfs; i++) {
3288 if (!adapter->vfinfo[i].spoofchk_enabled)
3289 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3290 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003291}
3292
Alexander Duyck477de6e2010-08-19 13:38:11 +00003293static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003294{
Auke Kok9a799d72007-09-15 14:07:45 -07003295 struct ixgbe_hw *hw = &adapter->hw;
3296 struct net_device *netdev = adapter->netdev;
3297 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003298 struct ixgbe_ring *rx_ring;
3299 int i;
3300 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003301
Alexander Duyck477de6e2010-08-19 13:38:11 +00003302#ifdef IXGBE_FCOE
3303 /* adjust max frame to be able to do baby jumbo for FCoE */
3304 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3305 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3306 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3307
3308#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003309
3310 /* adjust max frame to be at least the size of a standard frame */
3311 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3312 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3313
Alexander Duyck477de6e2010-08-19 13:38:11 +00003314 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3315 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3316 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3317 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3318
3319 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003320 }
3321
Auke Kok9a799d72007-09-15 14:07:45 -07003322 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003323 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3324 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003325 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3326
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003327 /*
3328 * Setup the HW Rx Head and Tail Descriptor Pointers and
3329 * the Base and Length of the Rx Descriptor Ring
3330 */
Auke Kok9a799d72007-09-15 14:07:45 -07003331 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003332 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003333 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3334 set_ring_rsc_enabled(rx_ring);
3335 else
3336 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003337 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003338}
3339
Alexander Duyck73670962010-08-19 13:38:34 +00003340static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3341{
3342 struct ixgbe_hw *hw = &adapter->hw;
3343 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3344
3345 switch (hw->mac.type) {
3346 case ixgbe_mac_82598EB:
3347 /*
3348 * For VMDq support of different descriptor types or
3349 * buffer sizes through the use of multiple SRRCTL
3350 * registers, RDRXCTL.MVMEN must be set to 1
3351 *
3352 * also, the manual doesn't mention it clearly but DCA hints
3353 * will only use queue 0's tags unless this bit is set. Side
3354 * effects of setting this bit are only that SRRCTL must be
3355 * fully programmed [0..15]
3356 */
3357 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3358 break;
3359 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003360 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003361 /* Disable RSC for ACK packets */
3362 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3363 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3364 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3365 /* hardware requires some bits to be set by default */
3366 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3367 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3368 break;
3369 default:
3370 /* We should do nothing since we don't know this hardware */
3371 return;
3372 }
3373
3374 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3375}
3376
Alexander Duyck477de6e2010-08-19 13:38:11 +00003377/**
3378 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3379 * @adapter: board private structure
3380 *
3381 * Configure the Rx unit of the MAC after a reset.
3382 **/
3383static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3384{
3385 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003386 int i;
3387 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003388
3389 /* disable receives while setting up the descriptors */
3390 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3391 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3392
3393 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003394 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003395
Alexander Duyck9e10e042010-08-19 13:40:06 +00003396 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003397 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003398
Alexander Duyck477de6e2010-08-19 13:38:11 +00003399 /* set_rx_buffer_len must be called before ring initialization */
3400 ixgbe_set_rx_buffer_len(adapter);
3401
3402 /*
3403 * Setup the HW Rx Head and Tail Descriptor Pointers and
3404 * the Base and Length of the Rx Descriptor Ring
3405 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003406 for (i = 0; i < adapter->num_rx_queues; i++)
3407 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003408
Alexander Duyck9e10e042010-08-19 13:40:06 +00003409 /* disable drop enable for 82598 parts */
3410 if (hw->mac.type == ixgbe_mac_82598EB)
3411 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3412
3413 /* enable all receives */
3414 rxctrl |= IXGBE_RXCTRL_RXEN;
3415 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003416}
3417
Jiri Pirko8e586132011-12-08 19:52:37 -05003418static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003419{
3420 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003421 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003422
3423 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003424 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003425 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003426
3427 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003428}
3429
Jiri Pirko8e586132011-12-08 19:52:37 -05003430static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003431{
3432 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003433 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003434
Auke Kok9a799d72007-09-15 14:07:45 -07003435 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003436 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003437 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003438
3439 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003440}
3441
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003442/**
3443 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3444 * @adapter: driver data
3445 */
3446static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3447{
3448 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003449 u32 vlnctrl;
3450
3451 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3452 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3453 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3454}
3455
3456/**
3457 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3458 * @adapter: driver data
3459 */
3460static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3461{
3462 struct ixgbe_hw *hw = &adapter->hw;
3463 u32 vlnctrl;
3464
3465 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3466 vlnctrl |= IXGBE_VLNCTRL_VFE;
3467 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3468 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3469}
3470
3471/**
3472 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3473 * @adapter: driver data
3474 */
3475static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3476{
3477 struct ixgbe_hw *hw = &adapter->hw;
3478 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003479 int i, j;
3480
3481 switch (hw->mac.type) {
3482 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003483 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3484 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003485 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3486 break;
3487 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003488 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003489 for (i = 0; i < adapter->num_rx_queues; i++) {
3490 j = adapter->rx_ring[i]->reg_idx;
3491 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3492 vlnctrl &= ~IXGBE_RXDCTL_VME;
3493 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3494 }
3495 break;
3496 default:
3497 break;
3498 }
3499}
3500
3501/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003502 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003503 * @adapter: driver data
3504 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003505static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003506{
3507 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003508 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003509 int i, j;
3510
3511 switch (hw->mac.type) {
3512 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003513 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3514 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003515 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3516 break;
3517 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003518 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003519 for (i = 0; i < adapter->num_rx_queues; i++) {
3520 j = adapter->rx_ring[i]->reg_idx;
3521 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3522 vlnctrl |= IXGBE_RXDCTL_VME;
3523 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3524 }
3525 break;
3526 default:
3527 break;
3528 }
3529}
3530
Auke Kok9a799d72007-09-15 14:07:45 -07003531static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3532{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003533 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003534
Jesse Grossf62bbb52010-10-20 13:56:10 +00003535 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3536
3537 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3538 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003539}
3540
3541/**
Alexander Duyck28500622010-06-15 09:25:48 +00003542 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3543 * @netdev: network interface device structure
3544 *
3545 * Writes unicast address list to the RAR table.
3546 * Returns: -ENOMEM on failure/insufficient address space
3547 * 0 on no addresses written
3548 * X on writing X addresses to the RAR table
3549 **/
3550static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3551{
3552 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3553 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003554 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003555 int count = 0;
3556
John Fastabend95447462012-05-31 12:42:26 +00003557 /* In SR-IOV mode significantly less RAR entries are available */
3558 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3559 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3560
Alexander Duyck28500622010-06-15 09:25:48 +00003561 /* return ENOMEM indicating insufficient memory for addresses */
3562 if (netdev_uc_count(netdev) > rar_entries)
3563 return -ENOMEM;
3564
John Fastabend95447462012-05-31 12:42:26 +00003565 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003566 struct netdev_hw_addr *ha;
3567 /* return error if we do not support writing to RAR table */
3568 if (!hw->mac.ops.set_rar)
3569 return -ENOMEM;
3570
3571 netdev_for_each_uc_addr(ha, netdev) {
3572 if (!rar_entries)
3573 break;
3574 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003575 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003576 count++;
3577 }
3578 }
3579 /* write the addresses in reverse order to avoid write combining */
3580 for (; rar_entries > 0 ; rar_entries--)
3581 hw->mac.ops.clear_rar(hw, rar_entries);
3582
3583 return count;
3584}
3585
3586/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003587 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003588 * @netdev: network interface device structure
3589 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003590 * The set_rx_method entry point is called whenever the unicast/multicast
3591 * address list or the network interface flags are updated. This routine is
3592 * responsible for configuring the hardware for proper unicast, multicast and
3593 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003594 **/
Greg Rose7f870472010-01-09 02:25:29 +00003595void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003596{
3597 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3598 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003599 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3600 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003601
3602 /* Check for Promiscuous and All Multicast modes */
3603
3604 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3605
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003606 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003607 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003608 fctrl |= IXGBE_FCTRL_BAM;
3609 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3610 fctrl |= IXGBE_FCTRL_PMCF;
3611
Alexander Duyck28500622010-06-15 09:25:48 +00003612 /* clear the bits we are changing the status of */
3613 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3614
Auke Kok9a799d72007-09-15 14:07:45 -07003615 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003616 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003617 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003618 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003619 /* don't hardware filter vlans in promisc mode */
3620 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003621 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003622 if (netdev->flags & IFF_ALLMULTI) {
3623 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003624 vmolr |= IXGBE_VMOLR_MPE;
3625 } else {
3626 /*
3627 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003628 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003629 * that we can at least receive multicast traffic
3630 */
3631 hw->mac.ops.update_mc_addr_list(hw, netdev);
3632 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003633 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003634 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003635 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003636 }
3637
3638 /*
3639 * Write addresses to available RAR registers, if there is not
3640 * sufficient space to store all the addresses then enable
3641 * unicast promiscuous mode
3642 */
3643 count = ixgbe_write_uc_addr_list(netdev);
3644 if (count < 0) {
3645 fctrl |= IXGBE_FCTRL_UPE;
3646 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003647 }
3648
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003649 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003650 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003651
3652 if (hw->mac.type != ixgbe_mac_82598EB) {
3653 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003654 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3655 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003656 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003657 }
3658
Ben Greear3f2d1c02012-03-08 08:28:41 +00003659 /* This is useful for sniffing bad packets. */
3660 if (adapter->netdev->features & NETIF_F_RXALL) {
3661 /* UPE and MPE will be handled by normal PROMISC logic
3662 * in e1000e_set_rx_mode */
3663 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3664 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3665 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3666
3667 fctrl &= ~(IXGBE_FCTRL_DPF);
3668 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3669 }
3670
Auke Kok9a799d72007-09-15 14:07:45 -07003671 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003672
3673 if (netdev->features & NETIF_F_HW_VLAN_RX)
3674 ixgbe_vlan_strip_enable(adapter);
3675 else
3676 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003677}
3678
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003679static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3680{
3681 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003682
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003683 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3684 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003685}
3686
3687static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3688{
3689 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003690
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003691 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3692 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003693}
3694
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003695#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003696/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003697 * ixgbe_configure_dcb - Configure DCB hardware
3698 * @adapter: ixgbe adapter struct
3699 *
3700 * This is called by the driver on open to configure the DCB hardware.
3701 * This is also called by the gennetlink interface when reconfiguring
3702 * the DCB state.
3703 */
3704static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3705{
3706 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003707 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003708
Alexander Duyck67ebd792010-08-19 13:34:04 +00003709 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3710 if (hw->mac.type == ixgbe_mac_82598EB)
3711 netif_set_gso_max_size(adapter->netdev, 65536);
3712 return;
3713 }
3714
3715 if (hw->mac.type == ixgbe_mac_82598EB)
3716 netif_set_gso_max_size(adapter->netdev, 32768);
3717
John Fastabendb1208182011-10-15 05:00:10 +00003718#ifdef IXGBE_FCOE
3719 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3720 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3721#endif
3722
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003723 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003724 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003725 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3726 DCB_TX_CONFIG);
3727 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3728 DCB_RX_CONFIG);
3729 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003730 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3731 ixgbe_dcb_hw_ets(&adapter->hw,
3732 adapter->ixgbe_ieee_ets,
3733 max_frame);
3734 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3735 adapter->ixgbe_ieee_pfc->pfc_en,
3736 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003737 }
John Fastabend8187cd42011-02-23 05:58:08 +00003738
3739 /* Enable RSS Hash per TC */
3740 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003741 u32 msb = 0;
3742 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003743
Alexander Duyckd411a932012-06-30 00:14:01 +00003744 while (rss_i) {
3745 msb++;
3746 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003747 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003748
Alexander Duyck4ae63732012-06-22 06:46:33 +00003749 /* write msb to all 8 TCs in one write */
3750 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003751 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003752}
John Fastabend9da712d2011-08-23 03:14:22 +00003753#endif
3754
3755/* Additional bittime to account for IXGBE framing */
3756#define IXGBE_ETH_FRAMING 20
3757
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003758/**
John Fastabend9da712d2011-08-23 03:14:22 +00003759 * ixgbe_hpbthresh - calculate high water mark for flow control
3760 *
3761 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003762 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003763 */
3764static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3765{
3766 struct ixgbe_hw *hw = &adapter->hw;
3767 struct net_device *dev = adapter->netdev;
3768 int link, tc, kb, marker;
3769 u32 dv_id, rx_pba;
3770
3771 /* Calculate max LAN frame size */
3772 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3773
3774#ifdef IXGBE_FCOE
3775 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003776 if ((dev->features & NETIF_F_FCOE_MTU) &&
3777 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3778 (pb == ixgbe_fcoe_get_tc(adapter)))
3779 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003780
3781#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003782 /* Calculate delay value for device */
3783 switch (hw->mac.type) {
3784 case ixgbe_mac_X540:
3785 dv_id = IXGBE_DV_X540(link, tc);
3786 break;
3787 default:
3788 dv_id = IXGBE_DV(link, tc);
3789 break;
3790 }
3791
3792 /* Loopback switch introduces additional latency */
3793 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3794 dv_id += IXGBE_B2BT(tc);
3795
3796 /* Delay value is calculated in bit times convert to KB */
3797 kb = IXGBE_BT2KB(dv_id);
3798 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3799
3800 marker = rx_pba - kb;
3801
3802 /* It is possible that the packet buffer is not large enough
3803 * to provide required headroom. In this case throw an error
3804 * to user and a do the best we can.
3805 */
3806 if (marker < 0) {
3807 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3808 "headroom to support flow control."
3809 "Decrease MTU or number of traffic classes\n", pb);
3810 marker = tc + 1;
3811 }
3812
3813 return marker;
3814}
3815
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003816/**
John Fastabend9da712d2011-08-23 03:14:22 +00003817 * ixgbe_lpbthresh - calculate low water mark for for flow control
3818 *
3819 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003820 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003821 */
3822static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3823{
3824 struct ixgbe_hw *hw = &adapter->hw;
3825 struct net_device *dev = adapter->netdev;
3826 int tc;
3827 u32 dv_id;
3828
3829 /* Calculate max LAN frame size */
3830 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3831
3832 /* Calculate delay value for device */
3833 switch (hw->mac.type) {
3834 case ixgbe_mac_X540:
3835 dv_id = IXGBE_LOW_DV_X540(tc);
3836 break;
3837 default:
3838 dv_id = IXGBE_LOW_DV(tc);
3839 break;
3840 }
3841
3842 /* Delay value is calculated in bit times convert to KB */
3843 return IXGBE_BT2KB(dv_id);
3844}
3845
3846/*
3847 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3848 */
3849static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3850{
3851 struct ixgbe_hw *hw = &adapter->hw;
3852 int num_tc = netdev_get_num_tc(adapter->netdev);
3853 int i;
3854
3855 if (!num_tc)
3856 num_tc = 1;
3857
3858 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3859
3860 for (i = 0; i < num_tc; i++) {
3861 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3862
3863 /* Low water marks must not be larger than high water marks */
3864 if (hw->fc.low_water > hw->fc.high_water[i])
3865 hw->fc.low_water = 0;
3866 }
3867}
John Fastabend80605c652011-05-02 12:34:10 +00003868
3869static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3870{
John Fastabend80605c652011-05-02 12:34:10 +00003871 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003872 int hdrm;
3873 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003874
3875 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3876 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003877 hdrm = 32 << adapter->fdir_pballoc;
3878 else
3879 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003880
Alexander Duyckf7e10272011-07-21 00:40:35 +00003881 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003882 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003883}
3884
Alexander Duycke4911d52011-05-11 07:18:52 +00003885static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3886{
3887 struct ixgbe_hw *hw = &adapter->hw;
3888 struct hlist_node *node, *node2;
3889 struct ixgbe_fdir_filter *filter;
3890
3891 spin_lock(&adapter->fdir_perfect_lock);
3892
3893 if (!hlist_empty(&adapter->fdir_filter_list))
3894 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3895
3896 hlist_for_each_entry_safe(filter, node, node2,
3897 &adapter->fdir_filter_list, fdir_node) {
3898 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003899 &filter->filter,
3900 filter->sw_idx,
3901 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3902 IXGBE_FDIR_DROP_QUEUE :
3903 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003904 }
3905
3906 spin_unlock(&adapter->fdir_perfect_lock);
3907}
3908
Auke Kok9a799d72007-09-15 14:07:45 -07003909static void ixgbe_configure(struct ixgbe_adapter *adapter)
3910{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003911 struct ixgbe_hw *hw = &adapter->hw;
3912
John Fastabend80605c652011-05-02 12:34:10 +00003913 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003914#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003915 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003916#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00003917 /*
3918 * We must restore virtualization before VLANs or else
3919 * the VLVF registers will not be populated
3920 */
3921 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003922
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003923 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003924 ixgbe_restore_vlan(adapter);
3925
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003926 switch (hw->mac.type) {
3927 case ixgbe_mac_82599EB:
3928 case ixgbe_mac_X540:
3929 hw->mac.ops.disable_rx_buff(hw);
3930 break;
3931 default:
3932 break;
3933 }
3934
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003935 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003936 ixgbe_init_fdir_signature_82599(&adapter->hw,
3937 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003938 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3939 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3940 adapter->fdir_pballoc);
3941 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003942 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003943
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003944 switch (hw->mac.type) {
3945 case ixgbe_mac_82599EB:
3946 case ixgbe_mac_X540:
3947 hw->mac.ops.enable_rx_buff(hw);
3948 break;
3949 default:
3950 break;
3951 }
3952
Alexander Duyck7c8ae652012-05-05 05:32:47 +00003953#ifdef IXGBE_FCOE
3954 /* configure FCoE L2 filters, redirection table, and Rx control */
3955 ixgbe_configure_fcoe(adapter);
3956
3957#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07003958 ixgbe_configure_tx(adapter);
3959 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003960}
3961
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003962static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3963{
3964 switch (hw->phy.type) {
3965 case ixgbe_phy_sfp_avago:
3966 case ixgbe_phy_sfp_ftl:
3967 case ixgbe_phy_sfp_intel:
3968 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003969 case ixgbe_phy_sfp_passive_tyco:
3970 case ixgbe_phy_sfp_passive_unknown:
3971 case ixgbe_phy_sfp_active_unknown:
3972 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003973 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003974 case ixgbe_phy_nl:
3975 if (hw->mac.type == ixgbe_mac_82598EB)
3976 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003977 default:
3978 return false;
3979 }
3980}
3981
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003982/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003983 * ixgbe_sfp_link_config - set up SFP+ link
3984 * @adapter: pointer to private adapter struct
3985 **/
3986static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3987{
Alexander Duyck70864002011-04-27 09:13:56 +00003988 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003989 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003990 * is that an SFP was inserted/removed after the reset
3991 * but before SFP detection was enabled. As such the best
3992 * solution is to just start searching as soon as we start
3993 */
3994 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3995 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003996
Alexander Duyck70864002011-04-27 09:13:56 +00003997 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003998}
3999
4000/**
4001 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004002 * @hw: pointer to private hardware struct
4003 *
4004 * Returns 0 on success, negative on failure
4005 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004006static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004007{
Josh Hay3d292262012-12-15 03:28:19 +00004008 u32 speed;
4009 bool autoneg, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004010 u32 ret = IXGBE_ERR_LINK_SETUP;
4011
4012 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00004013 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004014
4015 if (ret)
4016 goto link_cfg_out;
4017
Josh Hay3d292262012-12-15 03:28:19 +00004018 speed = hw->phy.autoneg_advertised;
4019 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4020 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4021 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004022 if (ret)
4023 goto link_cfg_out;
4024
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004025 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00004026 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004027link_cfg_out:
4028 return ret;
4029}
4030
Alexander Duycka34bcff2010-08-19 13:39:20 +00004031static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004032{
Auke Kok9a799d72007-09-15 14:07:45 -07004033 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004034 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004035
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004036 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004037 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4038 IXGBE_GPIE_OCD;
4039 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004040 /*
4041 * use EIAM to auto-mask when MSI-X interrupt is asserted
4042 * this saves a register write for every interrupt
4043 */
4044 switch (hw->mac.type) {
4045 case ixgbe_mac_82598EB:
4046 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4047 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004048 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004049 case ixgbe_mac_X540:
4050 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004051 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4052 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4053 break;
4054 }
4055 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004056 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4057 * specifically only auto mask tx and rx interrupts */
4058 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004059 }
4060
Alexander Duycka34bcff2010-08-19 13:39:20 +00004061 /* XXX: to interrupt immediately for EICS writes, enable this */
4062 /* gpie |= IXGBE_GPIE_EIMEN; */
4063
4064 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4065 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004066
4067 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4068 case IXGBE_82599_VMDQ_8Q_MASK:
4069 gpie |= IXGBE_GPIE_VTMODE_16;
4070 break;
4071 case IXGBE_82599_VMDQ_4Q_MASK:
4072 gpie |= IXGBE_GPIE_VTMODE_32;
4073 break;
4074 default:
4075 gpie |= IXGBE_GPIE_VTMODE_64;
4076 break;
4077 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004078 }
4079
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004080 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004081 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4082 switch (adapter->hw.mac.type) {
4083 case ixgbe_mac_82599EB:
4084 gpie |= IXGBE_SDP0_GPIEN;
4085 break;
4086 case ixgbe_mac_X540:
4087 gpie |= IXGBE_EIMS_TS;
4088 break;
4089 default:
4090 break;
4091 }
4092 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004093
Alexander Duycka34bcff2010-08-19 13:39:20 +00004094 /* Enable fan failure interrupt */
4095 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004096 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004097
Don Skidmore2698b202011-04-13 07:01:52 +00004098 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004099 gpie |= IXGBE_SDP1_GPIEN;
4100 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004101 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004102
4103 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4104}
4105
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004106static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004107{
4108 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004109 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004110 u32 ctrl_ext;
4111
4112 ixgbe_get_hw_control(adapter);
4113 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004114
Auke Kok9a799d72007-09-15 14:07:45 -07004115 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4116 ixgbe_configure_msix(adapter);
4117 else
4118 ixgbe_configure_msi_and_legacy(adapter);
4119
Emil Tantilovec74a472012-09-20 03:33:56 +00004120 /* enable the optics for 82599 SFP+ fiber */
4121 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004122 hw->mac.ops.enable_tx_laser(hw);
4123
Auke Kok9a799d72007-09-15 14:07:45 -07004124 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004125 ixgbe_napi_enable_all(adapter);
4126
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004127 if (ixgbe_is_sfp(hw)) {
4128 ixgbe_sfp_link_config(adapter);
4129 } else {
4130 err = ixgbe_non_sfp_link_config(hw);
4131 if (err)
4132 e_err(probe, "link_config FAILED %d\n", err);
4133 }
4134
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004135 /* clear any pending interrupts, may auto mask */
4136 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004137 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004138
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004139 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004140 * If this adapter has a fan, check to see if we had a failure
4141 * before we enabled the interrupt.
4142 */
4143 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4144 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4145 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004146 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004147 }
4148
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004149 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004150 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004151
Auke Kok9a799d72007-09-15 14:07:45 -07004152 /* bring the link up in the watchdog, this could race with our first
4153 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004154 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4155 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004156 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004157
4158 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4159 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4160 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4161 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004162}
4163
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004164void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4165{
4166 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004167 /* put off any impending NetWatchDogTimeout */
4168 adapter->netdev->trans_start = jiffies;
4169
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004170 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004171 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004172 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004173 /*
4174 * If SR-IOV enabled then wait a bit before bringing the adapter
4175 * back up to give the VFs time to respond to the reset. The
4176 * two second wait is based upon the watchdog timer cycle in
4177 * the VF driver.
4178 */
4179 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4180 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004181 ixgbe_up(adapter);
4182 clear_bit(__IXGBE_RESETTING, &adapter->state);
4183}
4184
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004185void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004186{
4187 /* hardware has been reset, we need to reload some things */
4188 ixgbe_configure(adapter);
4189
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004190 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004191}
4192
4193void ixgbe_reset(struct ixgbe_adapter *adapter)
4194{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004195 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004196 int err;
4197
Alexander Duyck70864002011-04-27 09:13:56 +00004198 /* lock SFP init bit to prevent race conditions with the watchdog */
4199 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4200 usleep_range(1000, 2000);
4201
4202 /* clear all SFP and link config related flags while holding SFP_INIT */
4203 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4204 IXGBE_FLAG2_SFP_NEEDS_RESET);
4205 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4206
Don Skidmore8ca783a2009-05-26 20:40:47 -07004207 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004208 switch (err) {
4209 case 0:
4210 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004211 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004212 break;
4213 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004214 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004215 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004216 case IXGBE_ERR_EEPROM_VERSION:
4217 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004218 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004219 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004220 "your hardware. If you are experiencing problems "
4221 "please contact your Intel or hardware "
4222 "representative who provided you with this "
4223 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004224 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004225 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004226 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004227 }
Auke Kok9a799d72007-09-15 14:07:45 -07004228
Alexander Duyck70864002011-04-27 09:13:56 +00004229 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4230
Auke Kok9a799d72007-09-15 14:07:45 -07004231 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004232 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004233
4234 /* update SAN MAC vmdq pool selection */
4235 if (hw->mac.san_mac_rar_index)
4236 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004237
Jacob Keller1a71ab22012-08-25 03:54:19 +00004238 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4239 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004240}
4241
Auke Kok9a799d72007-09-15 14:07:45 -07004242/**
4243 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004244 * @rx_ring: ring to free buffers from
4245 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004246static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004247{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004248 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004249 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004250 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004251
Alexander Duyck84418e32010-08-19 13:40:54 +00004252 /* ring already cleared, nothing to do */
4253 if (!rx_ring->rx_buffer_info)
4254 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004255
Alexander Duyck84418e32010-08-19 13:40:54 +00004256 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004257 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004258 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004259
Alexander Duyckf8003262012-03-03 02:35:52 +00004260 rx_buffer = &rx_ring->rx_buffer_info[i];
4261 if (rx_buffer->skb) {
4262 struct sk_buff *skb = rx_buffer->skb;
4263 if (IXGBE_CB(skb)->page_released) {
4264 dma_unmap_page(dev,
4265 IXGBE_CB(skb)->dma,
4266 ixgbe_rx_bufsz(rx_ring),
4267 DMA_FROM_DEVICE);
4268 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004269 }
4270 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004271 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004272 rx_buffer->skb = NULL;
4273 if (rx_buffer->dma)
4274 dma_unmap_page(dev, rx_buffer->dma,
4275 ixgbe_rx_pg_size(rx_ring),
4276 DMA_FROM_DEVICE);
4277 rx_buffer->dma = 0;
4278 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004279 __free_pages(rx_buffer->page,
4280 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004281 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004282 }
4283
4284 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4285 memset(rx_ring->rx_buffer_info, 0, size);
4286
4287 /* Zero out the descriptor ring */
4288 memset(rx_ring->desc, 0, rx_ring->size);
4289
Alexander Duyckf8003262012-03-03 02:35:52 +00004290 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004291 rx_ring->next_to_clean = 0;
4292 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004293}
4294
4295/**
4296 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004297 * @tx_ring: ring to be cleaned
4298 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004299static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004300{
4301 struct ixgbe_tx_buffer *tx_buffer_info;
4302 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004303 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004304
Alexander Duyck84418e32010-08-19 13:40:54 +00004305 /* ring already cleared, nothing to do */
4306 if (!tx_ring->tx_buffer_info)
4307 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004308
Alexander Duyck84418e32010-08-19 13:40:54 +00004309 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004310 for (i = 0; i < tx_ring->count; i++) {
4311 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004312 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004313 }
4314
John Fastabenddad8a3b2012-04-23 12:22:39 +00004315 netdev_tx_reset_queue(txring_txq(tx_ring));
4316
Auke Kok9a799d72007-09-15 14:07:45 -07004317 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4318 memset(tx_ring->tx_buffer_info, 0, size);
4319
4320 /* Zero out the descriptor ring */
4321 memset(tx_ring->desc, 0, tx_ring->size);
4322
4323 tx_ring->next_to_use = 0;
4324 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004325}
4326
4327/**
Auke Kok9a799d72007-09-15 14:07:45 -07004328 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4329 * @adapter: board private structure
4330 **/
4331static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4332{
4333 int i;
4334
4335 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004336 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004337}
4338
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004339/**
4340 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4341 * @adapter: board private structure
4342 **/
4343static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4344{
4345 int i;
4346
4347 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004348 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004349}
4350
Alexander Duycke4911d52011-05-11 07:18:52 +00004351static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4352{
4353 struct hlist_node *node, *node2;
4354 struct ixgbe_fdir_filter *filter;
4355
4356 spin_lock(&adapter->fdir_perfect_lock);
4357
4358 hlist_for_each_entry_safe(filter, node, node2,
4359 &adapter->fdir_filter_list, fdir_node) {
4360 hlist_del(&filter->fdir_node);
4361 kfree(filter);
4362 }
4363 adapter->fdir_filter_count = 0;
4364
4365 spin_unlock(&adapter->fdir_perfect_lock);
4366}
4367
Auke Kok9a799d72007-09-15 14:07:45 -07004368void ixgbe_down(struct ixgbe_adapter *adapter)
4369{
4370 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004371 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004372 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004373 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004374
4375 /* signal that we are down to the interrupt handler */
4376 set_bit(__IXGBE_DOWN, &adapter->state);
4377
4378 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004379 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4380 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004381
Yi Zou2d39d572011-01-06 14:29:56 +00004382 /* disable all enabled rx queues */
4383 for (i = 0; i < adapter->num_rx_queues; i++)
4384 /* this call also flushes the previous write */
4385 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4386
Don Skidmore032b4322011-03-18 09:32:53 +00004387 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004388
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004389 netif_tx_stop_all_queues(netdev);
4390
Alexander Duyck70864002011-04-27 09:13:56 +00004391 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004392 netif_carrier_off(netdev);
4393 netif_tx_disable(netdev);
4394
4395 ixgbe_irq_disable(adapter);
4396
4397 ixgbe_napi_disable_all(adapter);
4398
Alexander Duyckd034acf2011-04-27 09:25:34 +00004399 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4400 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004401 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4402
4403 del_timer_sync(&adapter->service_timer);
4404
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004405 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004406 /* Clear EITR Select mapping */
4407 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4408
4409 /* Mark all the VFs as inactive */
4410 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004411 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004412
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004413 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004414 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004415
Auke Kok9a799d72007-09-15 14:07:45 -07004416 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004417 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004418 }
4419
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004420 /* disable transmits in the hardware now that interrupts are off */
4421 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004422 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004423 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004424 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004425
4426 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004427 switch (hw->mac.type) {
4428 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004429 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004430 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004431 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4432 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004433 break;
4434 default:
4435 break;
4436 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004437
Paul Larson6f4a0e42008-06-24 17:00:56 -07004438 if (!pci_channel_offline(adapter->pdev))
4439 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004440
Emil Tantilovec74a472012-09-20 03:33:56 +00004441 /* power down the optics for 82599 SFP+ fiber */
4442 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004443 hw->mac.ops.disable_tx_laser(hw);
4444
Auke Kok9a799d72007-09-15 14:07:45 -07004445 ixgbe_clean_all_tx_rings(adapter);
4446 ixgbe_clean_all_rx_rings(adapter);
4447
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004448#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004449 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004450 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004451#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004452}
4453
Auke Kok9a799d72007-09-15 14:07:45 -07004454/**
Auke Kok9a799d72007-09-15 14:07:45 -07004455 * ixgbe_tx_timeout - Respond to a Tx Hang
4456 * @netdev: network interface device structure
4457 **/
4458static void ixgbe_tx_timeout(struct net_device *netdev)
4459{
4460 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4461
4462 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004463 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004464}
4465
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004466/**
Auke Kok9a799d72007-09-15 14:07:45 -07004467 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4468 * @adapter: board private structure to initialize
4469 *
4470 * ixgbe_sw_init initializes the Adapter private data structure.
4471 * Fields are initialized based on PCI device information and
4472 * OS network device settings (MTU size).
4473 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004474static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004475{
4476 struct ixgbe_hw *hw = &adapter->hw;
4477 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004478 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004479 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004480#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004481 int j;
4482 struct tc_configuration *tc;
4483#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004484
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004485 /* PCI config space info */
4486
4487 hw->vendor_id = pdev->vendor;
4488 hw->device_id = pdev->device;
4489 hw->revision_id = pdev->revision;
4490 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4491 hw->subsystem_device_id = pdev->subsystem_device;
4492
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004493 /* Set common capability flags and settings */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004494 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004495 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004496 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4497 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004498 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
4499 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00004500 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
4501 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004502 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4503#ifdef CONFIG_IXGBE_DCA
4504 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
4505#endif
4506#ifdef IXGBE_FCOE
4507 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4508 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4509#ifdef CONFIG_IXGBE_DCB
4510 /* Default traffic class to use for FCoE */
4511 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4512#endif /* CONFIG_IXGBE_DCB */
4513#endif /* IXGBE_FCOE */
4514
4515 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08004516 switch (hw->mac.type) {
4517 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004518 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
4519 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
4520
Don Skidmorebf069c92009-05-07 10:39:54 +00004521 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4522 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004523
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004524 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00004525 adapter->ring_feature[RING_F_FDIR].limit = 0;
4526 adapter->atr_sample_rate = 0;
4527 adapter->fdir_pballoc = 0;
4528#ifdef IXGBE_FCOE
4529 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
4530 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4531#ifdef CONFIG_IXGBE_DCB
4532 adapter->fcoe.up = 0;
4533#endif /* IXGBE_DCB */
4534#endif /* IXGBE_FCOE */
4535 break;
4536 case ixgbe_mac_82599EB:
4537 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4538 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08004539 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004540 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004541 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
4542 if (fwsm & IXGBE_FWSM_TS_ENABLED)
4543 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08004544 break;
4545 default:
4546 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004547 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004548
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004549#ifdef IXGBE_FCOE
4550 /* FCoE support exists, always init the FCoE lock */
4551 spin_lock_init(&adapter->fcoe.lock);
4552
4553#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004554 /* n-tuple support exists, always init our spinlock */
4555 spin_lock_init(&adapter->fdir_perfect_lock);
4556
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004557#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004558 switch (hw->mac.type) {
4559 case ixgbe_mac_X540:
4560 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4561 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4562 break;
4563 default:
4564 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4565 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4566 break;
4567 }
4568
Alexander Duyck2f90b862008-11-20 20:52:10 -08004569 /* Configure DCB traffic classes */
4570 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4571 tc = &adapter->dcb_cfg.tc_config[j];
4572 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4573 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4574 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4575 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4576 tc->dcb_pfc = pfc_disabled;
4577 }
John Fastabend4de2a022011-09-27 03:52:01 +00004578
4579 /* Initialize default user to priority mapping, UPx->TC0 */
4580 tc = &adapter->dcb_cfg.tc_config[0];
4581 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4582 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4583
Alexander Duyck2f90b862008-11-20 20:52:10 -08004584 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4585 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004586 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004587 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004588 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004589 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4590 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004591
4592#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004593
4594 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004595 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004596 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004597 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004598 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4599 hw->fc.send_xon = true;
Jacob Kellerdb2adc22012-10-24 07:26:02 +00004600 hw->fc.disable_fc_autoneg =
4601 (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
Auke Kok9a799d72007-09-15 14:07:45 -07004602
Alexander Duyck99d74482012-05-09 08:09:25 +00004603#ifdef CONFIG_PCI_IOV
4604 /* assign number of SR-IOV VFs */
4605 if (hw->mac.type != ixgbe_mac_82598EB)
4606 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4607
4608#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004609 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004610 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004611 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004612
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004613 /* set default ring sizes */
4614 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4615 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4616
Alexander Duyckbd198052011-06-11 01:45:08 +00004617 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004618 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004619
Auke Kok9a799d72007-09-15 14:07:45 -07004620 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004621 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004622 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004623 return -EIO;
4624 }
4625
Auke Kok9a799d72007-09-15 14:07:45 -07004626 set_bit(__IXGBE_DOWN, &adapter->state);
4627
4628 return 0;
4629}
4630
4631/**
4632 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004633 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004634 *
4635 * Return 0 on success, negative on failure
4636 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004637int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004638{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004639 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004640 int orig_node = dev_to_node(dev);
4641 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004642 int size;
4643
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004644 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004645
4646 if (tx_ring->q_vector)
4647 numa_node = tx_ring->q_vector->numa_node;
4648
4649 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004650 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004651 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004652 if (!tx_ring->tx_buffer_info)
4653 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004654
4655 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004656 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004657 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004658
Alexander Duyckde88eee2012-02-08 07:49:59 +00004659 set_dev_node(dev, numa_node);
4660 tx_ring->desc = dma_alloc_coherent(dev,
4661 tx_ring->size,
4662 &tx_ring->dma,
4663 GFP_KERNEL);
4664 set_dev_node(dev, orig_node);
4665 if (!tx_ring->desc)
4666 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4667 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004668 if (!tx_ring->desc)
4669 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004670
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004671 tx_ring->next_to_use = 0;
4672 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004673 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004674
4675err:
4676 vfree(tx_ring->tx_buffer_info);
4677 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004678 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004679 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004680}
4681
4682/**
Alexander Duyck69888672008-09-11 20:05:39 -07004683 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4684 * @adapter: board private structure
4685 *
4686 * If this function returns with an error, then it's possible one or
4687 * more of the rings is populated (while the rest are not). It is the
4688 * callers duty to clean those orphaned rings.
4689 *
4690 * Return 0 on success, negative on failure
4691 **/
4692static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4693{
4694 int i, err = 0;
4695
4696 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004697 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004698 if (!err)
4699 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004700
Emil Tantilov396e7992010-07-01 20:05:12 +00004701 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004702 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004703 }
4704
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004705 return 0;
4706err_setup_tx:
4707 /* rewind the index freeing the rings as we go */
4708 while (i--)
4709 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004710 return err;
4711}
4712
4713/**
Auke Kok9a799d72007-09-15 14:07:45 -07004714 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004715 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004716 *
4717 * Returns 0 on success, negative on failure
4718 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004719int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004720{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004721 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004722 int orig_node = dev_to_node(dev);
4723 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004724 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004725
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004726 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004727
4728 if (rx_ring->q_vector)
4729 numa_node = rx_ring->q_vector->numa_node;
4730
4731 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004732 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004733 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004734 if (!rx_ring->rx_buffer_info)
4735 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004736
Auke Kok9a799d72007-09-15 14:07:45 -07004737 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004738 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4739 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004740
Alexander Duyckde88eee2012-02-08 07:49:59 +00004741 set_dev_node(dev, numa_node);
4742 rx_ring->desc = dma_alloc_coherent(dev,
4743 rx_ring->size,
4744 &rx_ring->dma,
4745 GFP_KERNEL);
4746 set_dev_node(dev, orig_node);
4747 if (!rx_ring->desc)
4748 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4749 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004750 if (!rx_ring->desc)
4751 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004752
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004753 rx_ring->next_to_clean = 0;
4754 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004755
4756 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004757err:
4758 vfree(rx_ring->rx_buffer_info);
4759 rx_ring->rx_buffer_info = NULL;
4760 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004761 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004762}
4763
4764/**
Alexander Duyck69888672008-09-11 20:05:39 -07004765 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4766 * @adapter: board private structure
4767 *
4768 * If this function returns with an error, then it's possible one or
4769 * more of the rings is populated (while the rest are not). It is the
4770 * callers duty to clean those orphaned rings.
4771 *
4772 * Return 0 on success, negative on failure
4773 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004774static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4775{
4776 int i, err = 0;
4777
4778 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004779 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004780 if (!err)
4781 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004782
Emil Tantilov396e7992010-07-01 20:05:12 +00004783 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004784 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004785 }
4786
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004787#ifdef IXGBE_FCOE
4788 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4789 if (!err)
4790#endif
4791 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004792err_setup_rx:
4793 /* rewind the index freeing the rings as we go */
4794 while (i--)
4795 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004796 return err;
4797}
4798
4799/**
Auke Kok9a799d72007-09-15 14:07:45 -07004800 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004801 * @tx_ring: Tx descriptor ring for a specific queue
4802 *
4803 * Free all transmit software resources
4804 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004805void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004806{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004807 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004808
4809 vfree(tx_ring->tx_buffer_info);
4810 tx_ring->tx_buffer_info = NULL;
4811
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004812 /* if not set, then don't free */
4813 if (!tx_ring->desc)
4814 return;
4815
4816 dma_free_coherent(tx_ring->dev, tx_ring->size,
4817 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004818
4819 tx_ring->desc = NULL;
4820}
4821
4822/**
4823 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4824 * @adapter: board private structure
4825 *
4826 * Free all transmit software resources
4827 **/
4828static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4829{
4830 int i;
4831
4832 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004833 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004834 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004835}
4836
4837/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004838 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004839 * @rx_ring: ring to clean the resources from
4840 *
4841 * Free all receive software resources
4842 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004843void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004844{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004845 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004846
4847 vfree(rx_ring->rx_buffer_info);
4848 rx_ring->rx_buffer_info = NULL;
4849
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004850 /* if not set, then don't free */
4851 if (!rx_ring->desc)
4852 return;
4853
4854 dma_free_coherent(rx_ring->dev, rx_ring->size,
4855 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004856
4857 rx_ring->desc = NULL;
4858}
4859
4860/**
4861 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4862 * @adapter: board private structure
4863 *
4864 * Free all receive software resources
4865 **/
4866static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4867{
4868 int i;
4869
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004870#ifdef IXGBE_FCOE
4871 ixgbe_free_fcoe_ddp_resources(adapter);
4872
4873#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004874 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004875 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004876 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004877}
4878
4879/**
Auke Kok9a799d72007-09-15 14:07:45 -07004880 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4881 * @netdev: network interface device structure
4882 * @new_mtu: new value for maximum frame size
4883 *
4884 * Returns 0 on success, negative on failure
4885 **/
4886static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4887{
4888 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4889 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4890
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004891 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004892 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4893 return -EINVAL;
4894
4895 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00004896 * For 82599EB we cannot allow legacy VFs to enable their receive
4897 * paths when MTU greater than 1500 is configured. So display a
4898 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00004899 */
4900 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4901 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Alexander Duyckc5604512013-01-09 08:50:42 +00004902 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck872844d2012-08-15 02:10:43 +00004903 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004904
Emil Tantilov396e7992010-07-01 20:05:12 +00004905 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004906
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004907 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004908 netdev->mtu = new_mtu;
4909
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004910 if (netif_running(netdev))
4911 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004912
4913 return 0;
4914}
4915
4916/**
4917 * ixgbe_open - Called when a network interface is made active
4918 * @netdev: network interface device structure
4919 *
4920 * Returns 0 on success, negative value on failure
4921 *
4922 * The open entry point is called when a network interface is made
4923 * active by the system (IFF_UP). At this point all resources needed
4924 * for transmit and receive operations are allocated, the interrupt
4925 * handler is registered with the OS, the watchdog timer is started,
4926 * and the stack is notified that the interface is ready.
4927 **/
4928static int ixgbe_open(struct net_device *netdev)
4929{
4930 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4931 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004932
Auke Kok4bebfaa2008-02-11 09:26:01 -08004933 /* disallow open during test */
4934 if (test_bit(__IXGBE_TESTING, &adapter->state))
4935 return -EBUSY;
4936
Jesse Brandeburg54386462009-04-17 20:44:27 +00004937 netif_carrier_off(netdev);
4938
Auke Kok9a799d72007-09-15 14:07:45 -07004939 /* allocate transmit descriptors */
4940 err = ixgbe_setup_all_tx_resources(adapter);
4941 if (err)
4942 goto err_setup_tx;
4943
Auke Kok9a799d72007-09-15 14:07:45 -07004944 /* allocate receive descriptors */
4945 err = ixgbe_setup_all_rx_resources(adapter);
4946 if (err)
4947 goto err_setup_rx;
4948
4949 ixgbe_configure(adapter);
4950
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004951 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004952 if (err)
4953 goto err_req_irq;
4954
Alexander Duyckac802f52012-07-12 05:52:53 +00004955 /* Notify the stack of the actual queue counts. */
4956 err = netif_set_real_num_tx_queues(netdev,
4957 adapter->num_rx_pools > 1 ? 1 :
4958 adapter->num_tx_queues);
4959 if (err)
4960 goto err_set_queues;
4961
4962
4963 err = netif_set_real_num_rx_queues(netdev,
4964 adapter->num_rx_pools > 1 ? 1 :
4965 adapter->num_rx_queues);
4966 if (err)
4967 goto err_set_queues;
4968
Jacob Keller1a71ab22012-08-25 03:54:19 +00004969 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004970
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004971 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004972
4973 return 0;
4974
Alexander Duyckac802f52012-07-12 05:52:53 +00004975err_set_queues:
4976 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004977err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004978 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004979err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004980 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004981err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07004982 ixgbe_reset(adapter);
4983
4984 return err;
4985}
4986
4987/**
4988 * ixgbe_close - Disables a network interface
4989 * @netdev: network interface device structure
4990 *
4991 * Returns 0, this is not allowed to fail
4992 *
4993 * The close entry point is called when an interface is de-activated
4994 * by the OS. The hardware is still under the drivers control, but
4995 * needs to be disabled. A global MAC reset is issued to stop the
4996 * hardware, and all transmit and receive resources are freed.
4997 **/
4998static int ixgbe_close(struct net_device *netdev)
4999{
5000 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005001
Jacob Keller1a71ab22012-08-25 03:54:19 +00005002 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00005003
Auke Kok9a799d72007-09-15 14:07:45 -07005004 ixgbe_down(adapter);
5005 ixgbe_free_irq(adapter);
5006
Alexander Duycke4911d52011-05-11 07:18:52 +00005007 ixgbe_fdir_filter_exit(adapter);
5008
Auke Kok9a799d72007-09-15 14:07:45 -07005009 ixgbe_free_all_tx_resources(adapter);
5010 ixgbe_free_all_rx_resources(adapter);
5011
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005012 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005013
5014 return 0;
5015}
5016
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005017#ifdef CONFIG_PM
5018static int ixgbe_resume(struct pci_dev *pdev)
5019{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005020 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5021 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005022 u32 err;
5023
5024 pci_set_power_state(pdev, PCI_D0);
5025 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005026 /*
5027 * pci_restore_state clears dev->state_saved so call
5028 * pci_save_state to restore it.
5029 */
5030 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005031
5032 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005033 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005034 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005035 return err;
5036 }
5037 pci_set_master(pdev);
5038
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005039 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005040
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005041 ixgbe_reset(adapter);
5042
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005043 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5044
Alexander Duyckac802f52012-07-12 05:52:53 +00005045 rtnl_lock();
5046 err = ixgbe_init_interrupt_scheme(adapter);
5047 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005048 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005049
5050 rtnl_unlock();
5051
5052 if (err)
5053 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005054
5055 netif_device_attach(netdev);
5056
5057 return 0;
5058}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005059#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005060
5061static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005062{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005063 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5064 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005065 struct ixgbe_hw *hw = &adapter->hw;
5066 u32 ctrl, fctrl;
5067 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005068#ifdef CONFIG_PM
5069 int retval = 0;
5070#endif
5071
5072 netif_device_detach(netdev);
5073
5074 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00005075 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005076 ixgbe_down(adapter);
5077 ixgbe_free_irq(adapter);
5078 ixgbe_free_all_tx_resources(adapter);
5079 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00005080 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005081 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005082
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005083 ixgbe_clear_interrupt_scheme(adapter);
5084
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005085#ifdef CONFIG_PM
5086 retval = pci_save_state(pdev);
5087 if (retval)
5088 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005089
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005090#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005091 if (wufc) {
5092 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005093
Emil Tantilovec74a472012-09-20 03:33:56 +00005094 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5095 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005096 hw->mac.ops.enable_tx_laser(hw);
5097
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005098 /* turn on all-multi mode if wake on multicast is enabled */
5099 if (wufc & IXGBE_WUFC_MC) {
5100 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5101 fctrl |= IXGBE_FCTRL_MPE;
5102 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5103 }
5104
5105 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5106 ctrl |= IXGBE_CTRL_GIO_DIS;
5107 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5108
5109 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5110 } else {
5111 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5112 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5113 }
5114
Alexander Duyckbd508172010-11-16 19:27:03 -08005115 switch (hw->mac.type) {
5116 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005117 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005118 break;
5119 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005120 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005121 pci_wake_from_d3(pdev, !!wufc);
5122 break;
5123 default:
5124 break;
5125 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005126
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005127 *enable_wake = !!wufc;
5128
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005129 ixgbe_release_hw_control(adapter);
5130
5131 pci_disable_device(pdev);
5132
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005133 return 0;
5134}
5135
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005136#ifdef CONFIG_PM
5137static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5138{
5139 int retval;
5140 bool wake;
5141
5142 retval = __ixgbe_shutdown(pdev, &wake);
5143 if (retval)
5144 return retval;
5145
5146 if (wake) {
5147 pci_prepare_to_sleep(pdev);
5148 } else {
5149 pci_wake_from_d3(pdev, false);
5150 pci_set_power_state(pdev, PCI_D3hot);
5151 }
5152
5153 return 0;
5154}
5155#endif /* CONFIG_PM */
5156
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005157static void ixgbe_shutdown(struct pci_dev *pdev)
5158{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005159 bool wake;
5160
5161 __ixgbe_shutdown(pdev, &wake);
5162
5163 if (system_state == SYSTEM_POWER_OFF) {
5164 pci_wake_from_d3(pdev, wake);
5165 pci_set_power_state(pdev, PCI_D3hot);
5166 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005167}
5168
5169/**
Auke Kok9a799d72007-09-15 14:07:45 -07005170 * ixgbe_update_stats - Update the board statistics counters.
5171 * @adapter: board private structure
5172 **/
5173void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5174{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005175 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005176 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005177 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005178 u64 total_mpc = 0;
5179 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005180 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5181 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005182 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005183
Don Skidmored08935c2010-06-11 13:20:29 +00005184 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5185 test_bit(__IXGBE_RESETTING, &adapter->state))
5186 return;
5187
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005188 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005189 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005190 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005191 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005192 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5193 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005194 }
5195 adapter->rsc_total_count = rsc_count;
5196 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005197 }
5198
Alexander Duyck5b7da512010-11-16 19:26:50 -08005199 for (i = 0; i < adapter->num_rx_queues; i++) {
5200 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5201 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5202 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5203 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005204 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005205 bytes += rx_ring->stats.bytes;
5206 packets += rx_ring->stats.packets;
5207 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005208 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005209 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5210 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005211 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005212 netdev->stats.rx_bytes = bytes;
5213 netdev->stats.rx_packets = packets;
5214
5215 bytes = 0;
5216 packets = 0;
5217 /* gather some stats to the adapter struct that are per queue */
5218 for (i = 0; i < adapter->num_tx_queues; i++) {
5219 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5220 restart_queue += tx_ring->tx_stats.restart_queue;
5221 tx_busy += tx_ring->tx_stats.tx_busy;
5222 bytes += tx_ring->stats.bytes;
5223 packets += tx_ring->stats.packets;
5224 }
5225 adapter->restart_queue = restart_queue;
5226 adapter->tx_busy = tx_busy;
5227 netdev->stats.tx_bytes = bytes;
5228 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005229
Joe Perches7ca647b2010-09-07 21:35:40 +00005230 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005231
5232 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005233 for (i = 0; i < 8; i++) {
5234 /* for packet buffers not used, the register should read 0 */
5235 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5236 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005237 hwstats->mpc[i] += mpc;
5238 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005239 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5240 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005241 switch (hw->mac.type) {
5242 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005243 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5244 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5245 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005246 hwstats->pxonrxc[i] +=
5247 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005248 break;
5249 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005250 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005251 hwstats->pxonrxc[i] +=
5252 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005253 break;
5254 default:
5255 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005256 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005257 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005258
5259 /*16 register reads */
5260 for (i = 0; i < 16; i++) {
5261 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5262 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5263 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5264 (hw->mac.type == ixgbe_mac_X540)) {
5265 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5266 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5267 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5268 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5269 }
5270 }
5271
Joe Perches7ca647b2010-09-07 21:35:40 +00005272 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005273 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005274 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005275
John Fastabendc84d3242010-11-16 19:27:12 -08005276 ixgbe_update_xoff_received(adapter);
5277
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005278 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005279 switch (hw->mac.type) {
5280 case ixgbe_mac_82598EB:
5281 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005282 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5283 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5284 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5285 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005286 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005287 /* OS2BMC stats are X540 only*/
5288 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5289 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5290 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5291 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5292 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005293 for (i = 0; i < 16; i++)
5294 adapter->hw_rx_no_dma_resources +=
5295 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005296 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005297 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005298 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005299 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005300 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005301 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005302 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005303 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5304 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005305#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005306 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5307 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5308 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5309 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5310 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5311 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005312 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005313 if (adapter->fcoe.ddp_pool) {
5314 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5315 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5316 unsigned int cpu;
5317 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005318 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005319 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5320 noddp += ddp_pool->noddp;
5321 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005322 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005323 hwstats->fcoe_noddp = noddp;
5324 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005325 }
Yi Zou6d455222009-05-13 13:12:16 +00005326#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005327 break;
5328 default:
5329 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005330 }
Auke Kok9a799d72007-09-15 14:07:45 -07005331 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005332 hwstats->bprc += bprc;
5333 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005334 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005335 hwstats->mprc -= bprc;
5336 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5337 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5338 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5339 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5340 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5341 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5342 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5343 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005344 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005345 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005346 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005347 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005348 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5349 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005350 /*
5351 * 82598 errata - tx of flow control packets is included in tx counters
5352 */
5353 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005354 hwstats->gptc -= xon_off_tot;
5355 hwstats->mptc -= xon_off_tot;
5356 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5357 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5358 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5359 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5360 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5361 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5362 hwstats->ptc64 -= xon_off_tot;
5363 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5364 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5365 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5366 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5367 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5368 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005369
5370 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005371 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005372
5373 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005374 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005375 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005376 netdev->stats.rx_length_errors = hwstats->rlec;
5377 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005378 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005379}
5380
5381/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005382 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005383 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005384 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005385static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005386{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005387 struct ixgbe_hw *hw = &adapter->hw;
5388 int i;
5389
Alexander Duyckd034acf2011-04-27 09:25:34 +00005390 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5391 return;
5392
5393 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5394
5395 /* if interface is down do nothing */
5396 if (test_bit(__IXGBE_DOWN, &adapter->state))
5397 return;
5398
5399 /* do nothing if we are not using signature filters */
5400 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5401 return;
5402
5403 adapter->fdir_overflow++;
5404
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005405 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5406 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005407 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005408 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005409 /* re-enable flow director interrupts */
5410 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005411 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005412 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005413 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005414 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005415}
5416
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005417/**
5418 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005419 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005420 *
5421 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005422 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005423 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005424 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005425 */
5426static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5427{
Auke Kok9a799d72007-09-15 14:07:45 -07005428 struct ixgbe_hw *hw = &adapter->hw;
5429 u64 eics = 0;
5430 int i;
5431
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005432 /* If we're down or resetting, just bail */
5433 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5434 test_bit(__IXGBE_RESETTING, &adapter->state))
5435 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005436
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005437 /* Force detection of hung controller */
5438 if (netif_carrier_ok(adapter->netdev)) {
5439 for (i = 0; i < adapter->num_tx_queues; i++)
5440 set_check_for_tx_hang(adapter->tx_ring[i]);
5441 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005442
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005443 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005444 /*
5445 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005446 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005447 * would set *both* EIMS and EICS for any bit in EIAM
5448 */
5449 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5450 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005451 } else {
5452 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005453 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005454 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005455 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005456 eics |= ((u64)1 << i);
5457 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005458 }
5459
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005460 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005461 ixgbe_irq_rearm_queues(adapter, eics);
5462
Alexander Duyckfe49f042009-06-04 16:00:09 +00005463}
5464
5465/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005466 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005467 * @adapter: pointer to the device adapter structure
5468 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005469 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005470static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005471{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005472 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005473 u32 link_speed = adapter->link_speed;
5474 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005475 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005476
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005477 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5478 return;
5479
5480 if (hw->mac.ops.check_link) {
5481 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005482 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005483 /* always assume link is up, if no check link function */
5484 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5485 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005486 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005487
5488 if (adapter->ixgbe_ieee_pfc)
5489 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5490
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005491 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005492 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005493 ixgbe_set_rx_drop_en(adapter);
5494 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005495
5496 if (link_up ||
5497 time_after(jiffies, (adapter->link_check_timeout +
5498 IXGBE_TRY_LINK_TIMEOUT))) {
5499 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5500 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5501 IXGBE_WRITE_FLUSH(hw);
5502 }
5503
5504 adapter->link_up = link_up;
5505 adapter->link_speed = link_speed;
5506}
5507
Alexander Duyck107d3012012-10-02 00:17:03 +00005508static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5509{
5510#ifdef CONFIG_IXGBE_DCB
5511 struct net_device *netdev = adapter->netdev;
5512 struct dcb_app app = {
5513 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5514 .protocol = 0,
5515 };
5516 u8 up = 0;
5517
5518 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5519 up = dcb_ieee_getapp_mask(netdev, &app);
5520
5521 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5522#endif
5523}
5524
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005525/**
5526 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5527 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005528 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005529 **/
5530static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5531{
5532 struct net_device *netdev = adapter->netdev;
5533 struct ixgbe_hw *hw = &adapter->hw;
5534 u32 link_speed = adapter->link_speed;
5535 bool flow_rx, flow_tx;
5536
5537 /* only continue if link was previously down */
5538 if (netif_carrier_ok(netdev))
5539 return;
5540
5541 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5542
5543 switch (hw->mac.type) {
5544 case ixgbe_mac_82598EB: {
5545 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5546 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5547 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5548 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5549 }
5550 break;
5551 case ixgbe_mac_X540:
5552 case ixgbe_mac_82599EB: {
5553 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5554 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5555 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5556 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5557 }
5558 break;
5559 default:
5560 flow_tx = false;
5561 flow_rx = false;
5562 break;
5563 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005564
Jacob Keller6cb562d2012-12-05 07:24:41 +00005565 adapter->last_rx_ptp_check = jiffies;
5566
Jacob Keller1a71ab22012-08-25 03:54:19 +00005567 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5568 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005569
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005570 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5571 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5572 "10 Gbps" :
5573 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5574 "1 Gbps" :
5575 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5576 "100 Mbps" :
5577 "unknown speed"))),
5578 ((flow_rx && flow_tx) ? "RX/TX" :
5579 (flow_rx ? "RX" :
5580 (flow_tx ? "TX" : "None"))));
5581
5582 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005583 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005584
Alexander Duyck107d3012012-10-02 00:17:03 +00005585 /* update the default user priority for VFs */
5586 ixgbe_update_default_up(adapter);
5587
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005588 /* ping all the active vfs to let them know link has changed */
5589 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005590}
5591
5592/**
5593 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5594 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005595 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005596 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005597static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005598{
5599 struct net_device *netdev = adapter->netdev;
5600 struct ixgbe_hw *hw = &adapter->hw;
5601
5602 adapter->link_up = false;
5603 adapter->link_speed = 0;
5604
5605 /* only continue if link was up previously */
5606 if (!netif_carrier_ok(netdev))
5607 return;
5608
5609 /* poll for SFP+ cable when link is down */
5610 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5611 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5612
Jacob Keller1a71ab22012-08-25 03:54:19 +00005613 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5614 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005615
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005616 e_info(drv, "NIC Link is Down\n");
5617 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005618
5619 /* ping all the active vfs to let them know link has changed */
5620 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005621}
5622
5623/**
5624 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005625 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005626 **/
5627static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5628{
5629 int i;
5630 int some_tx_pending = 0;
5631
5632 if (!netif_carrier_ok(adapter->netdev)) {
5633 for (i = 0; i < adapter->num_tx_queues; i++) {
5634 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5635 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5636 some_tx_pending = 1;
5637 break;
5638 }
5639 }
5640
5641 if (some_tx_pending) {
5642 /* We've lost link, so the controller stops DMA,
5643 * but we've got queued Tx work that's never going
5644 * to get done, so reset controller to flush Tx.
5645 * (Do the reset outside of interrupt context).
5646 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00005647 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005648 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005649 }
5650 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005651}
5652
Greg Rosea985b6c32010-11-18 03:02:52 +00005653static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5654{
5655 u32 ssvpc;
5656
Greg Rose0584d992012-08-08 00:00:58 +00005657 /* Do not perform spoof check for 82598 or if not in IOV mode */
5658 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5659 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005660 return;
5661
5662 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5663
5664 /*
5665 * ssvpc register is cleared on read, if zero then no
5666 * spoofed packets in the last interval.
5667 */
5668 if (!ssvpc)
5669 return;
5670
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005671 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005672}
5673
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005674/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005675 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005676 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005677 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005678static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005679{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005680 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005681 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5682 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005683 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005684
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005685 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005686
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005687 if (adapter->link_up)
5688 ixgbe_watchdog_link_is_up(adapter);
5689 else
5690 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005691
Greg Rosea985b6c32010-11-18 03:02:52 +00005692 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005693 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005694
5695 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005696}
5697
Alexander Duyck70864002011-04-27 09:13:56 +00005698/**
5699 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005700 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005701 **/
5702static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5703{
5704 struct ixgbe_hw *hw = &adapter->hw;
5705 s32 err;
5706
5707 /* not searching for SFP so there is nothing to do here */
5708 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5709 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5710 return;
5711
5712 /* someone else is in init, wait until next service event */
5713 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5714 return;
5715
5716 err = hw->phy.ops.identify_sfp(hw);
5717 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5718 goto sfp_out;
5719
5720 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5721 /* If no cable is present, then we need to reset
5722 * the next time we find a good cable. */
5723 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5724 }
5725
5726 /* exit on error */
5727 if (err)
5728 goto sfp_out;
5729
5730 /* exit if reset not needed */
5731 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5732 goto sfp_out;
5733
5734 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5735
5736 /*
5737 * A module may be identified correctly, but the EEPROM may not have
5738 * support for that module. setup_sfp() will fail in that case, so
5739 * we should not allow that module to load.
5740 */
5741 if (hw->mac.type == ixgbe_mac_82598EB)
5742 err = hw->phy.ops.reset(hw);
5743 else
5744 err = hw->mac.ops.setup_sfp(hw);
5745
5746 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5747 goto sfp_out;
5748
5749 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5750 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5751
5752sfp_out:
5753 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5754
5755 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5756 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5757 e_dev_err("failed to initialize because an unsupported "
5758 "SFP+ module type was detected.\n");
5759 e_dev_err("Reload the driver after installing a "
5760 "supported module.\n");
5761 unregister_netdev(adapter->netdev);
5762 }
5763}
5764
5765/**
5766 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005767 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005768 **/
5769static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5770{
5771 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00005772 u32 speed;
5773 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00005774
5775 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5776 return;
5777
5778 /* someone else is in init, wait until next service event */
5779 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5780 return;
5781
5782 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5783
Josh Hay3d292262012-12-15 03:28:19 +00005784 speed = hw->phy.autoneg_advertised;
5785 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5786 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Alexander Duyck70864002011-04-27 09:13:56 +00005787 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005788 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00005789
5790 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5791 adapter->link_check_timeout = jiffies;
5792 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5793}
5794
Greg Rose83c61fa2011-09-07 05:59:35 +00005795#ifdef CONFIG_PCI_IOV
5796static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5797{
5798 int vf;
5799 struct ixgbe_hw *hw = &adapter->hw;
5800 struct net_device *netdev = adapter->netdev;
5801 u32 gpc;
5802 u32 ciaa, ciad;
5803
5804 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5805 if (gpc) /* If incrementing then no need for the check below */
5806 return;
5807 /*
5808 * Check to see if a bad DMA write target from an errant or
5809 * malicious VF has caused a PCIe error. If so then we can
5810 * issue a VFLR to the offending VF(s) and then resume without
5811 * requesting a full slot reset.
5812 */
5813
5814 for (vf = 0; vf < adapter->num_vfs; vf++) {
5815 ciaa = (vf << 16) | 0x80000000;
5816 /* 32 bit read so align, we really want status at offset 6 */
5817 ciaa |= PCI_COMMAND;
5818 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5819 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5820 ciaa &= 0x7FFFFFFF;
5821 /* disable debug mode asap after reading data */
5822 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5823 /* Get the upper 16 bits which will be the PCI status reg */
5824 ciad >>= 16;
5825 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5826 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5827 /* Issue VFLR */
5828 ciaa = (vf << 16) | 0x80000000;
5829 ciaa |= 0xA8;
5830 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5831 ciad = 0x00008000; /* VFLR */
5832 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5833 ciaa &= 0x7FFFFFFF;
5834 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5835 }
5836 }
5837}
5838
5839#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005840/**
5841 * ixgbe_service_timer - Timer Call-back
5842 * @data: pointer to adapter cast into an unsigned long
5843 **/
5844static void ixgbe_service_timer(unsigned long data)
5845{
5846 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5847 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005848 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005849
5850 /* poll faster when waiting for link */
5851 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5852 next_event_offset = HZ / 10;
5853 else
5854 next_event_offset = HZ * 2;
5855
Greg Rose83c61fa2011-09-07 05:59:35 +00005856#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005857 /*
5858 * don't bother with SR-IOV VF DMA hang check if there are
5859 * no VFs or the link is down
5860 */
5861 if (!adapter->num_vfs ||
5862 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5863 goto normal_timer_service;
5864
5865 /* If we have VFs allocated then we must check for DMA hangs */
5866 ixgbe_check_for_bad_vf(adapter);
5867 next_event_offset = HZ / 50;
5868 adapter->timer_event_accumulator++;
5869
5870 if (adapter->timer_event_accumulator >= 100)
5871 adapter->timer_event_accumulator = 0;
5872 else
5873 ready = false;
5874
5875normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005876#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005877 /* Reset the timer */
5878 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5879
Greg Rose83c61fa2011-09-07 05:59:35 +00005880 if (ready)
5881 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005882}
5883
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005884static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5885{
5886 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5887 return;
5888
5889 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5890
5891 /* If we're already down or resetting, just bail */
5892 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5893 test_bit(__IXGBE_RESETTING, &adapter->state))
5894 return;
5895
5896 ixgbe_dump(adapter);
5897 netdev_err(adapter->netdev, "Reset adapter\n");
5898 adapter->tx_timeout_count++;
5899
5900 ixgbe_reinit_locked(adapter);
5901}
5902
Alexander Duyck70864002011-04-27 09:13:56 +00005903/**
5904 * ixgbe_service_task - manages and runs subtasks
5905 * @work: pointer to work_struct containing our data
5906 **/
5907static void ixgbe_service_task(struct work_struct *work)
5908{
5909 struct ixgbe_adapter *adapter = container_of(work,
5910 struct ixgbe_adapter,
5911 service_task);
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005912 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005913 ixgbe_sfp_detection_subtask(adapter);
5914 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005915 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005916 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005917 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005918 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00005919
5920 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) {
5921 ixgbe_ptp_overflow_check(adapter);
5922 ixgbe_ptp_rx_hang(adapter);
5923 }
Alexander Duyck70864002011-04-27 09:13:56 +00005924
5925 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005926}
5927
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005928static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5929 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005930 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005931{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005932 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005933 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005934 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005935
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00005936 if (skb->ip_summed != CHECKSUM_PARTIAL)
5937 return 0;
5938
Alexander Duyck897ab152011-05-27 05:31:47 +00005939 if (!skb_is_gso(skb))
5940 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005941
Alexander Duyck897ab152011-05-27 05:31:47 +00005942 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005943 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005944 if (err)
5945 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005946 }
5947
Alexander Duyck897ab152011-05-27 05:31:47 +00005948 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5949 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5950
Alexander Duyck244e27a2012-02-08 07:51:11 +00005951 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005952 struct iphdr *iph = ip_hdr(skb);
5953 iph->tot_len = 0;
5954 iph->check = 0;
5955 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5956 iph->daddr, 0,
5957 IPPROTO_TCP,
5958 0);
5959 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005960 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5961 IXGBE_TX_FLAGS_CSUM |
5962 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005963 } else if (skb_is_gso_v6(skb)) {
5964 ipv6_hdr(skb)->payload_len = 0;
5965 tcp_hdr(skb)->check =
5966 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5967 &ipv6_hdr(skb)->daddr,
5968 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005969 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5970 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005971 }
5972
Alexander Duyck091a6242012-02-08 07:51:01 +00005973 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005974 l4len = tcp_hdrlen(skb);
5975 *hdr_len = skb_transport_offset(skb) + l4len;
5976
Alexander Duyck091a6242012-02-08 07:51:01 +00005977 /* update gso size and bytecount with header size */
5978 first->gso_segs = skb_shinfo(skb)->gso_segs;
5979 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5980
Alexander Duyckc44f5f52012-10-30 06:01:45 +00005981 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00005982 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5983 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00005984
5985 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5986 vlan_macip_lens = skb_network_header_len(skb);
5987 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005988 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005989
5990 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005991 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005992
5993 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005994}
5995
Alexander Duyck244e27a2012-02-08 07:51:11 +00005996static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5997 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005998{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005999 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006000 u32 vlan_macip_lens = 0;
6001 u32 mss_l4len_idx = 0;
6002 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006003
Alexander Duyck897ab152011-05-27 05:31:47 +00006004 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00006005 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6006 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6007 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006008 } else {
6009 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006010 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006011 case __constant_htons(ETH_P_IP):
6012 vlan_macip_lens |= skb_network_header_len(skb);
6013 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6014 l4_hdr = ip_hdr(skb)->protocol;
6015 break;
6016 case __constant_htons(ETH_P_IPV6):
6017 vlan_macip_lens |= skb_network_header_len(skb);
6018 l4_hdr = ipv6_hdr(skb)->nexthdr;
6019 break;
6020 default:
6021 if (unlikely(net_ratelimit())) {
6022 dev_warn(tx_ring->dev,
6023 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006024 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006025 }
6026 break;
6027 }
Auke Kok9a799d72007-09-15 14:07:45 -07006028
Alexander Duyck897ab152011-05-27 05:31:47 +00006029 switch (l4_hdr) {
6030 case IPPROTO_TCP:
6031 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6032 mss_l4len_idx = tcp_hdrlen(skb) <<
6033 IXGBE_ADVTXD_L4LEN_SHIFT;
6034 break;
6035 case IPPROTO_SCTP:
6036 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6037 mss_l4len_idx = sizeof(struct sctphdr) <<
6038 IXGBE_ADVTXD_L4LEN_SHIFT;
6039 break;
6040 case IPPROTO_UDP:
6041 mss_l4len_idx = sizeof(struct udphdr) <<
6042 IXGBE_ADVTXD_L4LEN_SHIFT;
6043 break;
6044 default:
6045 if (unlikely(net_ratelimit())) {
6046 dev_warn(tx_ring->dev,
6047 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006048 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006049 }
6050 break;
6051 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006052
6053 /* update TX checksum flag */
6054 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006055 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006056
Alexander Duyck244e27a2012-02-08 07:51:11 +00006057 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006058 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006059 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006060
6061 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6062 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006063}
6064
Alexander Duyck472148c2012-11-07 02:34:28 +00006065#define IXGBE_SET_FLAG(_input, _flag, _result) \
6066 ((_flag <= _result) ? \
6067 ((u32)(_input & _flag) * (_result / _flag)) : \
6068 ((u32)(_input & _flag) / (_flag / _result)))
6069
6070static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006071{
6072 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006073 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6074 IXGBE_ADVTXD_DCMD_DEXT |
6075 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006076
6077 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006078 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6079 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006080
Alexander Duyckd3d00232011-07-15 02:31:25 +00006081 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006082 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6083 IXGBE_ADVTXD_DCMD_TSE);
6084
6085 /* set timestamp bit if present */
6086 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6087 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006088
Alexander Duyck62748b72012-07-20 08:09:01 +00006089 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006090 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006091
Alexander Duyckd3d00232011-07-15 02:31:25 +00006092 return cmd_type;
6093}
6094
Alexander Duyck729739b2012-02-08 07:51:06 +00006095static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6096 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006097{
Alexander Duyck472148c2012-11-07 02:34:28 +00006098 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006099
6100 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006101 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6102 IXGBE_TX_FLAGS_CSUM,
6103 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006104
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006105 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006106 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6107 IXGBE_TX_FLAGS_IPV4,
6108 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006109
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006110 /*
6111 * Check Context must be set if Tx switch is enabled, which it
6112 * always is for case where virtual functions are running
6113 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006114 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6115 IXGBE_TX_FLAGS_CC,
6116 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006117
Alexander Duyck472148c2012-11-07 02:34:28 +00006118 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006119}
6120
6121#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6122 IXGBE_TXD_CMD_RS)
6123
6124static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006125 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006126 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006127{
Alexander Duyck729739b2012-02-08 07:51:06 +00006128 struct sk_buff *skb = first->skb;
6129 struct ixgbe_tx_buffer *tx_buffer;
6130 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00006131 struct skb_frag_struct *frag;
6132 dma_addr_t dma;
6133 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006134 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00006135 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006136 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006137
Alexander Duyck729739b2012-02-08 07:51:06 +00006138 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6139
Alexander Duyckec718252012-10-30 06:01:55 +00006140 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
6141
6142 size = skb_headlen(skb);
6143 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00006144
Alexander Duyckd3d00232011-07-15 02:31:25 +00006145#ifdef IXGBE_FCOE
6146 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006147 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006148 size -= sizeof(struct fcoe_crc_eof) - data_len;
6149 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006150 } else {
6151 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006152 }
Auke Kok9a799d72007-09-15 14:07:45 -07006153 }
6154
Alexander Duyckd3d00232011-07-15 02:31:25 +00006155#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006156 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006157
Alexander Duyckec718252012-10-30 06:01:55 +00006158 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006159
Alexander Duyckec718252012-10-30 06:01:55 +00006160 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
6161 if (dma_mapping_error(tx_ring->dev, dma))
6162 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006163
Alexander Duyckec718252012-10-30 06:01:55 +00006164 /* record length, and DMA address */
6165 dma_unmap_len_set(tx_buffer, len, size);
6166 dma_unmap_addr_set(tx_buffer, dma, dma);
6167
6168 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6169
Alexander Duyck729739b2012-02-08 07:51:06 +00006170 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006171 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00006172 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006173
Alexander Duyckd3d00232011-07-15 02:31:25 +00006174 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006175 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006176 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006177 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006178 i = 0;
6179 }
Alexander Duyckec718252012-10-30 06:01:55 +00006180 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006181
6182 dma += IXGBE_MAX_DATA_PER_TXD;
6183 size -= IXGBE_MAX_DATA_PER_TXD;
6184
6185 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006186 }
6187
Alexander Duyck729739b2012-02-08 07:51:06 +00006188 if (likely(!data_len))
6189 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006190
Alexander Duyck472148c2012-11-07 02:34:28 +00006191 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006192
Alexander Duyck729739b2012-02-08 07:51:06 +00006193 i++;
6194 tx_desc++;
6195 if (i == tx_ring->count) {
6196 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6197 i = 0;
6198 }
Alexander Duyckec718252012-10-30 06:01:55 +00006199 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006200
Alexander Duyckd3d00232011-07-15 02:31:25 +00006201#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006202 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006203#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006204 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006205#endif
6206 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006207
Alexander Duyck729739b2012-02-08 07:51:06 +00006208 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6209 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07006210
Alexander Duyck729739b2012-02-08 07:51:06 +00006211 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07006212 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006213
Alexander Duyck729739b2012-02-08 07:51:06 +00006214 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00006215 cmd_type |= size | IXGBE_TXD_CMD;
6216 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006217
Alexander Duyck091a6242012-02-08 07:51:01 +00006218 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006219
Alexander Duyckd3d00232011-07-15 02:31:25 +00006220 /* set the timestamp */
6221 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006222
6223 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006224 * Force memory writes to complete before letting h/w know there
6225 * are new descriptors to fetch. (Only applicable for weak-ordered
6226 * memory model archs, such as IA-64).
6227 *
6228 * We also need this memory barrier to make certain all of the
6229 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006230 */
6231 wmb();
6232
Alexander Duyckd3d00232011-07-15 02:31:25 +00006233 /* set next_to_watch value indicating a packet is present */
6234 first->next_to_watch = tx_desc;
6235
Alexander Duyck729739b2012-02-08 07:51:06 +00006236 i++;
6237 if (i == tx_ring->count)
6238 i = 0;
6239
6240 tx_ring->next_to_use = i;
6241
Alexander Duyckd3d00232011-07-15 02:31:25 +00006242 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006243 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006244
6245 return;
6246dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006247 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006248
6249 /* clear dma mappings for failed tx_buffer_info map */
6250 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006251 tx_buffer = &tx_ring->tx_buffer_info[i];
6252 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6253 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006254 break;
6255 if (i == 0)
6256 i = tx_ring->count;
6257 i--;
6258 }
6259
Alexander Duyckd3d00232011-07-15 02:31:25 +00006260 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006261}
6262
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006263static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006264 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006265{
Alexander Duyck69830522011-01-06 14:29:58 +00006266 struct ixgbe_q_vector *q_vector = ring->q_vector;
6267 union ixgbe_atr_hash_dword input = { .dword = 0 };
6268 union ixgbe_atr_hash_dword common = { .dword = 0 };
6269 union {
6270 unsigned char *network;
6271 struct iphdr *ipv4;
6272 struct ipv6hdr *ipv6;
6273 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006274 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006275 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006276
Alexander Duyck69830522011-01-06 14:29:58 +00006277 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6278 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006279 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006280
Alexander Duyck69830522011-01-06 14:29:58 +00006281 /* do nothing if sampling is disabled */
6282 if (!ring->atr_sample_rate)
6283 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006284
Alexander Duyck69830522011-01-06 14:29:58 +00006285 ring->atr_count++;
6286
6287 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006288 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006289
6290 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006291 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006292 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006293 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006294 hdr.ipv4->protocol != IPPROTO_TCP))
6295 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006296
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006297 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006298
Alexander Duyck66f32a82011-06-29 05:43:22 +00006299 /* skip this packet since it is invalid or the socket is closing */
6300 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006301 return;
6302
6303 /* sample on all syn packets or once every atr sample count */
6304 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6305 return;
6306
6307 /* reset sample count */
6308 ring->atr_count = 0;
6309
Alexander Duyck244e27a2012-02-08 07:51:11 +00006310 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006311
6312 /*
6313 * src and dst are inverted, think how the receiver sees them
6314 *
6315 * The input is broken into two sections, a non-compressed section
6316 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6317 * is XORed together and stored in the compressed dword.
6318 */
6319 input.formatted.vlan_id = vlan_id;
6320
6321 /*
6322 * since src port and flex bytes occupy the same word XOR them together
6323 * and write the value to source port portion of compressed dword
6324 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006325 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006326 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6327 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006328 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006329 common.port.dst ^= th->source;
6330
Alexander Duyck244e27a2012-02-08 07:51:11 +00006331 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006332 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6333 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6334 } else {
6335 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6336 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6337 hdr.ipv6->saddr.s6_addr32[1] ^
6338 hdr.ipv6->saddr.s6_addr32[2] ^
6339 hdr.ipv6->saddr.s6_addr32[3] ^
6340 hdr.ipv6->daddr.s6_addr32[0] ^
6341 hdr.ipv6->daddr.s6_addr32[1] ^
6342 hdr.ipv6->daddr.s6_addr32[2] ^
6343 hdr.ipv6->daddr.s6_addr32[3];
6344 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006345
6346 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006347 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6348 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006349}
6350
Alexander Duyck63544e92011-05-27 05:31:42 +00006351static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006352{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006353 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006354 /* Herbert's original patch had:
6355 * smp_mb__after_netif_stop_queue();
6356 * but since that doesn't exist yet, just open code it. */
6357 smp_mb();
6358
6359 /* We need to check again in a case another CPU has just
6360 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006361 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006362 return -EBUSY;
6363
6364 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006365 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006366 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006367 return 0;
6368}
6369
Alexander Duyck82d4e462011-06-11 01:44:58 +00006370static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006371{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006372 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006373 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006374 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006375}
6376
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006377static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6378{
6379 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006380 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6381 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006382#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006383 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006384
John Fastabende5b64632011-03-08 03:44:52 +00006385 if (((protocol == htons(ETH_P_FCOE)) ||
6386 (protocol == htons(ETH_P_FIP))) &&
6387 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckc0876632012-05-10 00:01:46 +00006388 struct ixgbe_ring_feature *f;
6389
6390 f = &adapter->ring_feature[RING_F_FCOE];
6391
6392 while (txq >= f->indices)
6393 txq -= f->indices;
Alexander Duycke4b317e2012-05-05 05:30:53 +00006394 txq += adapter->ring_feature[RING_F_FCOE].offset;
Alexander Duyckc0876632012-05-10 00:01:46 +00006395
John Fastabende5b64632011-03-08 03:44:52 +00006396 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006397 }
6398#endif
6399
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006400 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6401 while (unlikely(txq >= dev->real_num_tx_queues))
6402 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006403 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006404 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006405
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006406 return skb_tx_hash(dev, skb);
6407}
6408
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006409netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006410 struct ixgbe_adapter *adapter,
6411 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006412{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006413 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006414 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006415 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006416#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6417 unsigned short f;
6418#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006419 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006420 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006421 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006422
Alexander Duycka535c302011-05-27 05:31:52 +00006423 /*
6424 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006425 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006426 * + 2 desc gap to keep tail from touching head,
6427 * + 1 desc for context descriptor,
6428 * otherwise try next time
6429 */
6430#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6431 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6432 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6433#else
6434 count += skb_shinfo(skb)->nr_frags;
6435#endif
6436 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6437 tx_ring->tx_stats.tx_busy++;
6438 return NETDEV_TX_BUSY;
6439 }
6440
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006441 /* record the location of the first descriptor for this packet */
6442 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6443 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006444 first->bytecount = skb->len;
6445 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006446
Alexander Duyck66f32a82011-06-29 05:43:22 +00006447 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006448 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006449 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6450 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6451 /* else if it is a SW VLAN check the next protocol and store the tag */
6452 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6453 struct vlan_hdr *vhdr, _vhdr;
6454 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6455 if (!vhdr)
6456 goto out_drop;
6457
6458 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006459 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6460 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006461 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006462 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006463
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006464 skb_tx_timestamp(skb);
6465
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006466 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6467 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6468 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00006469
6470 /* schedule check for Tx timestamp */
6471 adapter->ptp_tx_skb = skb_get(skb);
6472 adapter->ptp_tx_start = jiffies;
6473 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006474 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006475
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006476#ifdef CONFIG_PCI_IOV
6477 /*
6478 * Use the l2switch_enable flag - would be false if the DMA
6479 * Tx switch had been disabled.
6480 */
6481 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00006482 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006483
6484#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006485 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006486 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006487 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6488 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006489 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006490 tx_flags |= (skb->priority & 0x7) <<
6491 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006492 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6493 struct vlan_ethhdr *vhdr;
6494 if (skb_header_cloned(skb) &&
6495 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6496 goto out_drop;
6497 vhdr = (struct vlan_ethhdr *)skb->data;
6498 vhdr->h_vlan_TCI = htons(tx_flags >>
6499 IXGBE_TX_FLAGS_VLAN_SHIFT);
6500 } else {
6501 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6502 }
6503 }
Alexander Duycka535c302011-05-27 05:31:52 +00006504
Alexander Duyck244e27a2012-02-08 07:51:11 +00006505 /* record initial flags and protocol */
6506 first->tx_flags = tx_flags;
6507 first->protocol = protocol;
6508
Yi Zoueacd73f2009-05-13 13:11:06 +00006509#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006510 /* setup tx offload for FCoE */
6511 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006512 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006513 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006514 if (tso < 0)
6515 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006516
Alexander Duyck66f32a82011-06-29 05:43:22 +00006517 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006518 }
Auke Kok9a799d72007-09-15 14:07:45 -07006519
Auke Kok9a799d72007-09-15 14:07:45 -07006520#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006521 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006522 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006523 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006524 else if (!tso)
6525 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006526
6527 /* add the ATR filter if ATR is on */
6528 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006529 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006530
6531#ifdef IXGBE_FCOE
6532xmit_fcoe:
6533#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006534 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006535
6536 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006537
6538 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006539
6540out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006541 dev_kfree_skb_any(first->skb);
6542 first->skb = NULL;
6543
Alexander Duyck897ab152011-05-27 05:31:47 +00006544 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006545}
6546
Alexander Duycka50c29d2012-02-08 07:50:40 +00006547static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6548 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006549{
6550 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006551 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006552
Alexander Duycka50c29d2012-02-08 07:50:40 +00006553 /*
6554 * The minimum packet size for olinfo paylen is 17 so pad the skb
6555 * in order to meet this minimum size requirement.
6556 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006557 if (unlikely(skb->len < 17)) {
6558 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006559 return NETDEV_TX_OK;
6560 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006561 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006562 }
6563
Auke Kok9a799d72007-09-15 14:07:45 -07006564 tx_ring = adapter->tx_ring[skb->queue_mapping];
6565 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6566}
6567
6568/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006569 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006570 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006571 * @p: pointer to an address structure
6572 *
Auke Kok9a799d72007-09-15 14:07:45 -07006573 * Returns 0 on success, negative on failure
6574 **/
6575static int ixgbe_set_mac(struct net_device *netdev, void *p)
6576{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006577 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6578 struct ixgbe_hw *hw = &adapter->hw;
6579 struct sockaddr *addr = p;
6580
6581 if (!is_valid_ether_addr(addr->sa_data))
6582 return -EADDRNOTAVAIL;
6583
6584 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6585 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6586
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006587 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006588
6589 return 0;
6590}
6591
Ben Hutchings6b73e102009-04-29 08:08:58 +00006592static int
6593ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6594{
6595 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6596 struct ixgbe_hw *hw = &adapter->hw;
6597 u16 value;
6598 int rc;
6599
6600 if (prtad != hw->phy.mdio.prtad)
6601 return -EINVAL;
6602 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6603 if (!rc)
6604 rc = value;
6605 return rc;
6606}
6607
6608static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6609 u16 addr, u16 value)
6610{
6611 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6612 struct ixgbe_hw *hw = &adapter->hw;
6613
6614 if (prtad != hw->phy.mdio.prtad)
6615 return -EINVAL;
6616 return hw->phy.ops.write_reg(hw, addr, devad, value);
6617}
6618
6619static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6620{
6621 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6622
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006623 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006624 case SIOCSHWTSTAMP:
6625 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006626 default:
6627 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6628 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006629}
6630
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006631/**
6632 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006633 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006634 * @netdev: network interface device structure
6635 *
6636 * Returns non-zero on failure
6637 **/
6638static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6639{
6640 int err = 0;
6641 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006642 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006643
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006644 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006645 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006646 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006647 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006648
6649 /* update SAN MAC vmdq pool selection */
6650 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006651 }
6652 return err;
6653}
6654
6655/**
6656 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006657 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006658 * @netdev: network interface device structure
6659 *
6660 * Returns non-zero on failure
6661 **/
6662static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6663{
6664 int err = 0;
6665 struct ixgbe_adapter *adapter = netdev_priv(dev);
6666 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6667
6668 if (is_valid_ether_addr(mac->san_addr)) {
6669 rtnl_lock();
6670 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6671 rtnl_unlock();
6672 }
6673 return err;
6674}
6675
Auke Kok9a799d72007-09-15 14:07:45 -07006676#ifdef CONFIG_NET_POLL_CONTROLLER
6677/*
6678 * Polling 'interrupt' - used by things like netconsole to send skbs
6679 * without having to re-enable interrupts. It's not called while
6680 * the interrupt routine is executing.
6681 */
6682static void ixgbe_netpoll(struct net_device *netdev)
6683{
6684 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006685 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006686
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006687 /* if interface is down do nothing */
6688 if (test_bit(__IXGBE_DOWN, &adapter->state))
6689 return;
6690
Auke Kok9a799d72007-09-15 14:07:45 -07006691 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006692 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006693 for (i = 0; i < adapter->num_q_vectors; i++)
6694 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006695 } else {
6696 ixgbe_intr(adapter->pdev->irq, netdev);
6697 }
Auke Kok9a799d72007-09-15 14:07:45 -07006698 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006699}
Auke Kok9a799d72007-09-15 14:07:45 -07006700
Alexander Duyck581330b2012-02-08 07:51:47 +00006701#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006702static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6703 struct rtnl_link_stats64 *stats)
6704{
6705 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6706 int i;
6707
Eric Dumazet1a515022010-11-16 19:26:42 -08006708 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006709 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006710 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006711 u64 bytes, packets;
6712 unsigned int start;
6713
Eric Dumazet1a515022010-11-16 19:26:42 -08006714 if (ring) {
6715 do {
6716 start = u64_stats_fetch_begin_bh(&ring->syncp);
6717 packets = ring->stats.packets;
6718 bytes = ring->stats.bytes;
6719 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6720 stats->rx_packets += packets;
6721 stats->rx_bytes += bytes;
6722 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006723 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006724
6725 for (i = 0; i < adapter->num_tx_queues; i++) {
6726 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6727 u64 bytes, packets;
6728 unsigned int start;
6729
6730 if (ring) {
6731 do {
6732 start = u64_stats_fetch_begin_bh(&ring->syncp);
6733 packets = ring->stats.packets;
6734 bytes = ring->stats.bytes;
6735 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6736 stats->tx_packets += packets;
6737 stats->tx_bytes += bytes;
6738 }
6739 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006740 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006741 /* following stats updated by ixgbe_watchdog_task() */
6742 stats->multicast = netdev->stats.multicast;
6743 stats->rx_errors = netdev->stats.rx_errors;
6744 stats->rx_length_errors = netdev->stats.rx_length_errors;
6745 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6746 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6747 return stats;
6748}
6749
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006750#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006751/**
6752 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6753 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006754 * @tc: number of traffic classes currently enabled
6755 *
6756 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6757 * 802.1Q priority maps to a packet buffer that exists.
6758 */
6759static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6760{
6761 struct ixgbe_hw *hw = &adapter->hw;
6762 u32 reg, rsave;
6763 int i;
6764
6765 /* 82598 have a static priority to TC mapping that can not
6766 * be changed so no validation is needed.
6767 */
6768 if (hw->mac.type == ixgbe_mac_82598EB)
6769 return;
6770
6771 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6772 rsave = reg;
6773
6774 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6775 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6776
6777 /* If up2tc is out of bounds default to zero */
6778 if (up2tc > tc)
6779 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6780 }
6781
6782 if (reg != rsave)
6783 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6784
6785 return;
6786}
6787
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006788/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006789 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6790 * @adapter: Pointer to adapter struct
6791 *
6792 * Populate the netdev user priority to tc map
6793 */
6794static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6795{
6796 struct net_device *dev = adapter->netdev;
6797 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6798 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6799 u8 prio;
6800
6801 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6802 u8 tc = 0;
6803
6804 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6805 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6806 else if (ets)
6807 tc = ets->prio_tc[prio];
6808
6809 netdev_set_prio_tc_map(dev, prio, tc);
6810 }
6811}
6812
6813/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006814 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006815 *
6816 * @netdev: net device to configure
6817 * @tc: number of traffic classes to enable
6818 */
6819int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6820{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006821 struct ixgbe_adapter *adapter = netdev_priv(dev);
6822 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006823
John Fastabend8b1c0b22011-05-03 02:26:48 +00006824 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006825 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006826 (hw->mac.type == ixgbe_mac_82598EB &&
6827 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006828 return -EINVAL;
6829
6830 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006831 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006832 * hardware is not flexible enough to do this dynamically.
6833 */
6834 if (netif_running(dev))
6835 ixgbe_close(dev);
6836 ixgbe_clear_interrupt_scheme(adapter);
6837
John Fastabende7589ea2011-07-18 22:38:36 +00006838 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006839 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006840 ixgbe_set_prio_tc_map(adapter);
6841
John Fastabende7589ea2011-07-18 22:38:36 +00006842 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006843
Alexander Duyck943561d2012-05-09 22:14:44 -07006844 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6845 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006846 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006847 }
John Fastabende7589ea2011-07-18 22:38:36 +00006848 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006849 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006850
Alexander Duyck943561d2012-05-09 22:14:44 -07006851 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6852 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006853
6854 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006855
6856 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6857 adapter->dcb_cfg.pfc_mode_enable = false;
6858 }
6859
John Fastabend8b1c0b22011-05-03 02:26:48 +00006860 ixgbe_init_interrupt_scheme(adapter);
6861 ixgbe_validate_rtr(adapter, tc);
6862 if (netif_running(dev))
6863 ixgbe_open(dev);
6864
6865 return 0;
6866}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006867
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006868#endif /* CONFIG_IXGBE_DCB */
Greg Roseda36b642012-12-11 08:26:43 +00006869#ifdef CONFIG_PCI_IOV
6870void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
6871{
6872 struct net_device *netdev = adapter->netdev;
6873
6874 rtnl_lock();
6875#ifdef CONFIG_IXGBE_DCB
6876 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
6877#else
6878 if (netif_running(netdev))
6879 ixgbe_close(netdev);
6880 ixgbe_clear_interrupt_scheme(adapter);
6881 ixgbe_init_interrupt_scheme(adapter);
6882 if (netif_running(netdev))
6883 ixgbe_open(netdev);
6884#endif
6885 rtnl_unlock();
6886}
6887
6888#endif
Don Skidmore082757a2011-07-21 05:55:00 +00006889void ixgbe_do_reset(struct net_device *netdev)
6890{
6891 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6892
6893 if (netif_running(netdev))
6894 ixgbe_reinit_locked(adapter);
6895 else
6896 ixgbe_reset(adapter);
6897}
6898
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006899static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006900 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006901{
6902 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6903
Don Skidmore082757a2011-07-21 05:55:00 +00006904 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006905 if (!(features & NETIF_F_RXCSUM))
6906 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006907
Alexander Duyck567d2de2012-02-11 07:18:57 +00006908 /* Turn off LRO if not RSC capable */
6909 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6910 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006911
Alexander Duyck567d2de2012-02-11 07:18:57 +00006912 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006913}
6914
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006915static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006916 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006917{
6918 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006919 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006920 bool need_reset = false;
6921
Don Skidmore082757a2011-07-21 05:55:00 +00006922 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006923 if (!(features & NETIF_F_LRO)) {
6924 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006925 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006926 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6927 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6928 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6929 if (adapter->rx_itr_setting == 1 ||
6930 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6931 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6932 need_reset = true;
6933 } else if ((changed ^ features) & NETIF_F_LRO) {
6934 e_info(probe, "rx-usecs set too low, "
6935 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006936 }
6937 }
6938
6939 /*
6940 * Check if Flow Director n-tuple support was enabled or disabled. If
6941 * the state changed, we need to reset.
6942 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006943 switch (features & NETIF_F_NTUPLE) {
6944 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00006945 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006946 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6947 need_reset = true;
6948
Alexander Duyck567d2de2012-02-11 07:18:57 +00006949 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6950 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00006951 break;
6952 default:
6953 /* turn off perfect filters, enable ATR and reset */
6954 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6955 need_reset = true;
6956
6957 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6958
6959 /* We cannot enable ATR if SR-IOV is enabled */
6960 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6961 break;
6962
6963 /* We cannot enable ATR if we have 2 or more traffic classes */
6964 if (netdev_get_num_tc(netdev) > 1)
6965 break;
6966
6967 /* We cannot enable ATR if RSS is disabled */
6968 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6969 break;
6970
6971 /* A sample rate of 0 indicates ATR disabled */
6972 if (!adapter->atr_sample_rate)
6973 break;
6974
6975 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6976 break;
Don Skidmore082757a2011-07-21 05:55:00 +00006977 }
6978
John Fastabend146d4cc2012-05-15 05:59:26 +00006979 if (features & NETIF_F_HW_VLAN_RX)
6980 ixgbe_vlan_strip_enable(adapter);
6981 else
6982 ixgbe_vlan_strip_disable(adapter);
6983
Ben Greear3f2d1c02012-03-08 08:28:41 +00006984 if (changed & NETIF_F_RXALL)
6985 need_reset = true;
6986
Alexander Duyck567d2de2012-02-11 07:18:57 +00006987 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006988 if (need_reset)
6989 ixgbe_do_reset(netdev);
6990
6991 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006992}
6993
stephen hemmingeredc7d572012-10-01 12:32:33 +00006994static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006995 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006996 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006997 u16 flags)
6998{
6999 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00007000 int err;
7001
7002 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7003 return -EOPNOTSUPP;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007004
John Fastabendb1ac1ef2012-11-01 05:00:44 +00007005 /* Hardware does not support aging addresses so if a
7006 * ndm_state is given only allow permanent addresses
7007 */
7008 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007009 pr_info("%s: FDB only supports static addresses\n",
7010 ixgbe_driver_name);
7011 return -EINVAL;
7012 }
7013
Ben Hutchings46acc462012-11-01 09:11:11 +00007014 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00007015 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
7016
7017 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007018 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007019 else
John Fastabend95447462012-05-31 12:42:26 +00007020 err = -ENOMEM;
7021 } else if (is_multicast_ether_addr(addr)) {
7022 err = dev_mc_add_excl(dev, addr);
7023 } else {
7024 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007025 }
7026
7027 /* Only return duplicate errors if NLM_F_EXCL is set */
7028 if (err == -EEXIST && !(flags & NLM_F_EXCL))
7029 err = 0;
7030
7031 return err;
7032}
7033
Vlad Yasevich1690be62013-02-13 12:00:18 +00007034static int ixgbe_ndo_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007035 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00007036 const unsigned char *addr)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007037{
7038 struct ixgbe_adapter *adapter = netdev_priv(dev);
7039 int err = -EOPNOTSUPP;
7040
7041 if (ndm->ndm_state & NUD_PERMANENT) {
7042 pr_info("%s: FDB only supports static addresses\n",
7043 ixgbe_driver_name);
7044 return -EINVAL;
7045 }
7046
7047 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7048 if (is_unicast_ether_addr(addr))
7049 err = dev_uc_del(dev, addr);
7050 else if (is_multicast_ether_addr(addr))
7051 err = dev_mc_del(dev, addr);
7052 else
7053 err = -EINVAL;
7054 }
7055
7056 return err;
7057}
7058
7059static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7060 struct netlink_callback *cb,
7061 struct net_device *dev,
7062 int idx)
7063{
7064 struct ixgbe_adapter *adapter = netdev_priv(dev);
7065
7066 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7067 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7068
7069 return idx;
7070}
7071
John Fastabend815cccb2012-10-24 08:13:09 +00007072static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7073 struct nlmsghdr *nlh)
7074{
7075 struct ixgbe_adapter *adapter = netdev_priv(dev);
7076 struct nlattr *attr, *br_spec;
7077 int rem;
7078
7079 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7080 return -EOPNOTSUPP;
7081
7082 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7083
7084 nla_for_each_nested(attr, br_spec, rem) {
7085 __u16 mode;
7086 u32 reg = 0;
7087
7088 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7089 continue;
7090
7091 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007092 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007093 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007094 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7095 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007096 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007097 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7098 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007099 return -EINVAL;
7100
7101 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7102
7103 e_info(drv, "enabling bridge mode: %s\n",
7104 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7105 }
7106
7107 return 0;
7108}
7109
7110static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00007111 struct net_device *dev,
7112 u32 filter_mask)
John Fastabend815cccb2012-10-24 08:13:09 +00007113{
7114 struct ixgbe_adapter *adapter = netdev_priv(dev);
7115 u16 mode;
7116
7117 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7118 return 0;
7119
Greg Rose9b735982012-11-08 02:41:35 +00007120 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007121 mode = BRIDGE_MODE_VEB;
7122 else
7123 mode = BRIDGE_MODE_VEPA;
7124
7125 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7126}
7127
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007128static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007129 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007130 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007131 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007132 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007133 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007134 .ndo_validate_addr = eth_validate_addr,
7135 .ndo_set_mac_address = ixgbe_set_mac,
7136 .ndo_change_mtu = ixgbe_change_mtu,
7137 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007138 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7139 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007140 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007141 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7142 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7143 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007144 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007145 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007146 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007147#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007148 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007149#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007150#ifdef CONFIG_NET_POLL_CONTROLLER
7151 .ndo_poll_controller = ixgbe_netpoll,
7152#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007153#ifdef IXGBE_FCOE
7154 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007155 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007156 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007157 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7158 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007159 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007160 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007161#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007162 .ndo_set_features = ixgbe_set_features,
7163 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007164 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7165 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7166 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
John Fastabend815cccb2012-10-24 08:13:09 +00007167 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7168 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007169};
7170
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007171/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007172 * ixgbe_wol_supported - Check whether device supports WoL
7173 * @hw: hw specific details
7174 * @device_id: the device ID
7175 * @subdev_id: the subsystem device ID
7176 *
7177 * This function is used by probe and ethtool to determine
7178 * which devices have WoL support
7179 *
7180 **/
7181int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7182 u16 subdevice_id)
7183{
7184 struct ixgbe_hw *hw = &adapter->hw;
7185 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7186 int is_wol_supported = 0;
7187
7188 switch (device_id) {
7189 case IXGBE_DEV_ID_82599_SFP:
7190 /* Only these subdevices could supports WOL */
7191 switch (subdevice_id) {
7192 case IXGBE_SUBDEV_ID_82599_560FLR:
7193 /* only support first port */
7194 if (hw->bus.func != 0)
7195 break;
7196 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007197 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007198 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007199 is_wol_supported = 1;
7200 break;
7201 }
7202 break;
7203 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7204 /* All except this subdevice support WOL */
7205 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7206 is_wol_supported = 1;
7207 break;
7208 case IXGBE_DEV_ID_82599_KX4:
7209 is_wol_supported = 1;
7210 break;
7211 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007212 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007213 /* check eeprom to see if enabled wol */
7214 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7215 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7216 (hw->bus.func == 0))) {
7217 is_wol_supported = 1;
7218 }
7219 break;
7220 }
7221
7222 return is_wol_supported;
7223}
7224
7225/**
Auke Kok9a799d72007-09-15 14:07:45 -07007226 * ixgbe_probe - Device Initialization Routine
7227 * @pdev: PCI device information struct
7228 * @ent: entry in ixgbe_pci_tbl
7229 *
7230 * Returns 0 on success, negative on failure
7231 *
7232 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7233 * The OS initialization, configuring of the adapter private structure,
7234 * and a hardware reset occur.
7235 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007236static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007237{
7238 struct net_device *netdev;
7239 struct ixgbe_adapter *adapter = NULL;
7240 struct ixgbe_hw *hw;
7241 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007242 static int cards_found;
7243 int i, err, pci_using_dac;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007244 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00007245 u8 part_str[IXGBE_PBANUM_LENGTH];
Yi Zoueacd73f2009-05-13 13:11:06 +00007246#ifdef IXGBE_FCOE
7247 u16 device_caps;
7248#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007249 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007250
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007251 /* Catch broken hardware that put the wrong VF device ID in
7252 * the PCIe SR-IOV capability.
7253 */
7254 if (pdev->is_virtfn) {
7255 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7256 pci_name(pdev), pdev->vendor, pdev->device);
7257 return -EINVAL;
7258 }
7259
gouji-new9ce77662009-05-06 10:44:45 +00007260 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007261 if (err)
7262 return err;
7263
Nick Nunley1b507732010-04-27 13:10:27 +00007264 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7265 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007266 pci_using_dac = 1;
7267 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007268 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007269 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007270 err = dma_set_coherent_mask(&pdev->dev,
7271 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007272 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007273 dev_err(&pdev->dev,
7274 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007275 goto err_dma;
7276 }
7277 }
7278 pci_using_dac = 0;
7279 }
7280
gouji-new9ce77662009-05-06 10:44:45 +00007281 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007282 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007283 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007284 dev_err(&pdev->dev,
7285 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007286 goto err_pci_reg;
7287 }
7288
Frans Pop19d5afd2009-10-02 10:04:12 -07007289 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007290
Auke Kok9a799d72007-09-15 14:07:45 -07007291 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007292 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007293
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007294 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +00007295#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007296 /* 8 TC w/ 4 queues per TC */
7297 indices = 4 * MAX_TRAFFIC_CLASS;
7298#else
7299 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +00007300#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007301 }
John Fastabende901acd2011-04-26 07:26:08 +00007302
John Fastabendc85a2612010-02-25 23:15:21 +00007303 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007304 if (!netdev) {
7305 err = -ENOMEM;
7306 goto err_alloc_etherdev;
7307 }
7308
Auke Kok9a799d72007-09-15 14:07:45 -07007309 SET_NETDEV_DEV(netdev, &pdev->dev);
7310
Auke Kok9a799d72007-09-15 14:07:45 -07007311 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007312 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007313
7314 adapter->netdev = netdev;
7315 adapter->pdev = pdev;
7316 hw = &adapter->hw;
7317 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007318 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007319
Jeff Kirsher05857982008-09-11 19:57:00 -07007320 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007321 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007322 if (!hw->hw_addr) {
7323 err = -EIO;
7324 goto err_ioremap;
7325 }
7326
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007327 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007328 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007329 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007330 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007331
Auke Kok9a799d72007-09-15 14:07:45 -07007332 adapter->bd_number = cards_found;
7333
Auke Kok9a799d72007-09-15 14:07:45 -07007334 /* Setup hw api */
7335 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007336 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007337
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007338 /* EEPROM */
7339 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7340 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7341 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7342 if (!(eec & (1 << 8)))
7343 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7344
7345 /* PHY */
7346 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007347 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007348 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7349 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7350 hw->phy.mdio.mmds = 0;
7351 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7352 hw->phy.mdio.dev = netdev;
7353 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7354 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007355
Don Skidmore8ca783a2009-05-26 20:40:47 -07007356 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007357
7358 /* setup the private structure */
7359 err = ixgbe_sw_init(adapter);
7360 if (err)
7361 goto err_sw_init;
7362
Don Skidmoree86bff02010-02-11 04:14:08 +00007363 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007364 switch (adapter->hw.mac.type) {
7365 case ixgbe_mac_82599EB:
7366 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007367 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007368 break;
7369 default:
7370 break;
7371 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007372
Don Skidmorebf069c92009-05-07 10:39:54 +00007373 /*
7374 * If there is a fan on this device and it has failed log the
7375 * failure.
7376 */
7377 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7378 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7379 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007380 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007381 }
7382
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007383 if (allow_unsupported_sfp)
7384 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7385
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007386 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007387 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007388 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007389 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007390 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7391 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007392 err = 0;
7393 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007394 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007395 "module type was detected.\n");
7396 e_dev_err("Reload the driver after installing a supported "
7397 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007398 goto err_sw_init;
7399 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007400 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007401 goto err_sw_init;
7402 }
7403
Alexander Duyck99d74482012-05-09 08:09:25 +00007404#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +00007405 /* SR-IOV not supported on the 82598 */
7406 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7407 goto skip_sriov;
7408 /* Mailbox */
7409 ixgbe_init_mbx_params_pf(hw);
7410 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
7411 ixgbe_enable_sriov(adapter);
Donald Dutile43dc4e02012-12-11 08:26:48 +00007412 pci_sriov_set_totalvfs(pdev, 63);
Greg Rose60a1a682012-12-11 08:26:33 +00007413skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007414
Alexander Duyck99d74482012-05-09 08:09:25 +00007415#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007416 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007417 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007418 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007419 NETIF_F_HW_VLAN_TX |
7420 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007421 NETIF_F_HW_VLAN_FILTER |
7422 NETIF_F_TSO |
7423 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007424 NETIF_F_RXHASH |
7425 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007426
Don Skidmore082757a2011-07-21 05:55:00 +00007427 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007428
Don Skidmore58be7662011-04-12 09:42:11 +00007429 switch (adapter->hw.mac.type) {
7430 case ixgbe_mac_82599EB:
7431 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007432 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007433 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7434 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007435 break;
7436 default:
7437 break;
7438 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007439
Ben Greear3f2d1c02012-03-08 08:28:41 +00007440 netdev->hw_features |= NETIF_F_RXALL;
7441
Jeff Kirsherad31c402008-06-05 04:05:30 -07007442 netdev->vlan_features |= NETIF_F_TSO;
7443 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007444 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007445 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007446 netdev->vlan_features |= NETIF_F_SG;
7447
Jiri Pirko01789342011-08-16 06:29:00 +00007448 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007449 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007450
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007451#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007452 netdev->dcbnl_ops = &dcbnl_ops;
7453#endif
7454
Yi Zoueacd73f2009-05-13 13:11:06 +00007455#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007456 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007457 unsigned int fcoe_l;
7458
Yi Zoueacd73f2009-05-13 13:11:06 +00007459 if (hw->mac.ops.get_device_caps) {
7460 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007461 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7462 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007463 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007464
Alexander Duyckd3cb9862013-01-16 01:35:35 +00007465
7466 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
7467 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007468
Alexander Duycka58915c2012-05-25 06:38:18 +00007469 netdev->features |= NETIF_F_FSO |
7470 NETIF_F_FCOE_CRC;
7471
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007472 netdev->vlan_features |= NETIF_F_FSO |
7473 NETIF_F_FCOE_CRC |
7474 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007475 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007476#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007477 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007478 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007479 netdev->vlan_features |= NETIF_F_HIGHDMA;
7480 }
Auke Kok9a799d72007-09-15 14:07:45 -07007481
Don Skidmore082757a2011-07-21 05:55:00 +00007482 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7483 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007484 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007485 netdev->features |= NETIF_F_LRO;
7486
Auke Kok9a799d72007-09-15 14:07:45 -07007487 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007488 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007489 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007490 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007491 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007492 }
7493
7494 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007495
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007496 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007497 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007498 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007499 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007500 }
7501
Alexander Duyck70864002011-04-27 09:13:56 +00007502 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007503 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007504
Alexander Duyck70864002011-04-27 09:13:56 +00007505 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7506 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007507
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007508 err = ixgbe_init_interrupt_scheme(adapter);
7509 if (err)
7510 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007511
Jacob Keller8e2813f2012-04-21 06:05:40 +00007512 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007513 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007514 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7515 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007516 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007517
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007518 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7519
Emil Tantilov15e52092011-09-29 05:01:29 +00007520 /* save off EEPROM version number */
7521 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7522 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7523
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007524 /* pick up the PCI bus settings for reporting later */
7525 hw->mac.ops.get_bus_info(hw);
7526
Auke Kok9a799d72007-09-15 14:07:45 -07007527 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007528 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007529 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7530 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007531 "Unknown"),
7532 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7533 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7534 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7535 "Unknown"),
7536 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007537
7538 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7539 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007540 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007541 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007542 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007543 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007544 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007545 else
Don Skidmore289700db2010-12-03 03:32:58 +00007546 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7547 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007548
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007549 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007550 e_dev_warn("PCI-Express bandwidth available for this card is "
7551 "not sufficient for optimal performance.\n");
7552 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7553 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007554 }
7555
Auke Kok9a799d72007-09-15 14:07:45 -07007556 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007557 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007558 if (err == IXGBE_ERR_EEPROM_VERSION) {
7559 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007560 e_dev_warn("This device is a pre-production adapter/LOM. "
7561 "Please be aware there may be issues associated "
7562 "with your hardware. If you are experiencing "
7563 "problems please contact your Intel or hardware "
7564 "representative who provided you with this "
7565 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007566 }
Auke Kok9a799d72007-09-15 14:07:45 -07007567 strcpy(netdev->name, "eth%d");
7568 err = register_netdev(netdev);
7569 if (err)
7570 goto err_register;
7571
Emil Tantilovec74a472012-09-20 03:33:56 +00007572 /* power down the optics for 82599 SFP+ fiber */
7573 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007574 hw->mac.ops.disable_tx_laser(hw);
7575
Jesse Brandeburg54386462009-04-17 20:44:27 +00007576 /* carrier off reporting is important to ethtool even BEFORE open */
7577 netif_carrier_off(netdev);
7578
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007579#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007580 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007581 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007582 ixgbe_setup_dca(adapter);
7583 }
7584#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007585 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007586 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007587 for (i = 0; i < adapter->num_vfs; i++)
7588 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7589 }
7590
Jacob Keller2466dd92011-09-08 03:50:54 +00007591 /* firmware requires driver version to be 0xFFFFFFFF
7592 * since os does not support feature
7593 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007594 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007595 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7596 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007597
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007598 /* add san mac addr to netdev */
7599 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007600
Neerav Parikhea818752012-01-04 20:23:40 +00007601 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007602 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007603
Don Skidmore12109822012-05-04 06:07:08 +00007604#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007605 if (ixgbe_sysfs_init(adapter))
7606 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007607#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007608
Catherine Sullivan00949162012-08-10 01:59:10 +00007609#ifdef CONFIG_DEBUG_FS
7610 ixgbe_dbg_adapter_init(adapter);
7611#endif /* CONFIG_DEBUG_FS */
7612
Auke Kok9a799d72007-09-15 14:07:45 -07007613 return 0;
7614
7615err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007616 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007617 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007618err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007619 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007620 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007621 iounmap(hw->hw_addr);
7622err_ioremap:
7623 free_netdev(netdev);
7624err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007625 pci_release_selected_regions(pdev,
7626 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007627err_pci_reg:
7628err_dma:
7629 pci_disable_device(pdev);
7630 return err;
7631}
7632
7633/**
7634 * ixgbe_remove - Device Removal Routine
7635 * @pdev: PCI device information struct
7636 *
7637 * ixgbe_remove is called by the PCI subsystem to alert the driver
7638 * that it should release a PCI device. The could be caused by a
7639 * Hot-Plug event, or because the driver is going to be removed from
7640 * memory.
7641 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007642static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007643{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007644 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7645 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007646
Catherine Sullivan00949162012-08-10 01:59:10 +00007647#ifdef CONFIG_DEBUG_FS
7648 ixgbe_dbg_adapter_exit(adapter);
7649#endif /*CONFIG_DEBUG_FS */
7650
Auke Kok9a799d72007-09-15 14:07:45 -07007651 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007652 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007653
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007654
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007655#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007656 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7657 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7658 dca_remove_requester(&pdev->dev);
7659 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7660 }
7661
7662#endif
Don Skidmore12109822012-05-04 06:07:08 +00007663#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007664 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007665#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007666
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007667 /* remove the added san mac */
7668 ixgbe_del_sanmac_netdev(netdev);
7669
Donald Skidmorec4900be2008-11-20 21:11:42 -08007670 if (netdev->reg_state == NETREG_REGISTERED)
7671 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007672
Greg Roseda36b642012-12-11 08:26:43 +00007673#ifdef CONFIG_PCI_IOV
7674 /*
7675 * Only disable SR-IOV on unload if the user specified the now
7676 * deprecated max_vfs module parameter.
7677 */
7678 if (max_vfs)
7679 ixgbe_disable_sriov(adapter);
7680#endif
Alexander Duyck7a921c92009-05-06 10:43:28 +00007681 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007682
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007683 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007684
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007685#ifdef CONFIG_DCB
7686 kfree(adapter->ixgbe_ieee_pfc);
7687 kfree(adapter->ixgbe_ieee_ets);
7688
7689#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007690 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007691 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007692 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007693
Emil Tantilov849c4542010-06-03 16:53:41 +00007694 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007695
Auke Kok9a799d72007-09-15 14:07:45 -07007696 free_netdev(netdev);
7697
Frans Pop19d5afd2009-10-02 10:04:12 -07007698 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007699
Auke Kok9a799d72007-09-15 14:07:45 -07007700 pci_disable_device(pdev);
7701}
7702
7703/**
7704 * ixgbe_io_error_detected - called when PCI error is detected
7705 * @pdev: Pointer to PCI device
7706 * @state: The current pci connection state
7707 *
7708 * This function is called after a PCI bus error affecting
7709 * this device has been detected.
7710 */
7711static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007712 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007713{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007714 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7715 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007716
Greg Rose83c61fa2011-09-07 05:59:35 +00007717#ifdef CONFIG_PCI_IOV
7718 struct pci_dev *bdev, *vfdev;
7719 u32 dw0, dw1, dw2, dw3;
7720 int vf, pos;
7721 u16 req_id, pf_func;
7722
7723 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7724 adapter->num_vfs == 0)
7725 goto skip_bad_vf_detection;
7726
7727 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007728 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007729 bdev = bdev->bus->self;
7730
7731 if (!bdev)
7732 goto skip_bad_vf_detection;
7733
7734 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7735 if (!pos)
7736 goto skip_bad_vf_detection;
7737
7738 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7739 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7740 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7741 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7742
7743 req_id = dw1 >> 16;
7744 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7745 if (!(req_id & 0x0080))
7746 goto skip_bad_vf_detection;
7747
7748 pf_func = req_id & 0x01;
7749 if ((pf_func & 1) == (pdev->devfn & 1)) {
7750 unsigned int device_id;
7751
7752 vf = (req_id & 0x7F) >> 1;
7753 e_dev_err("VF %d has caused a PCIe error\n", vf);
7754 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7755 "%8.8x\tdw3: %8.8x\n",
7756 dw0, dw1, dw2, dw3);
7757 switch (adapter->hw.mac.type) {
7758 case ixgbe_mac_82599EB:
7759 device_id = IXGBE_82599_VF_DEVICE_ID;
7760 break;
7761 case ixgbe_mac_X540:
7762 device_id = IXGBE_X540_VF_DEVICE_ID;
7763 break;
7764 default:
7765 device_id = 0;
7766 break;
7767 }
7768
7769 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007770 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007771 while (vfdev) {
7772 if (vfdev->devfn == (req_id & 0xFF))
7773 break;
Jon Mason36e90312012-07-19 21:02:09 +00007774 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007775 device_id, vfdev);
7776 }
7777 /*
7778 * There's a slim chance the VF could have been hot plugged,
7779 * so if it is no longer present we don't need to issue the
7780 * VFLR. Just clean up the AER in that case.
7781 */
7782 if (vfdev) {
7783 e_dev_err("Issuing VFLR to VF %d\n", vf);
7784 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
Greg Roseb4fafbe2012-12-13 01:14:06 +00007785 /* Free device reference count */
7786 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +00007787 }
7788
7789 pci_cleanup_aer_uncorrect_error_status(pdev);
7790 }
7791
7792 /*
7793 * Even though the error may have occurred on the other port
7794 * we still need to increment the vf error reference count for
7795 * both ports because the I/O resume function will be called
7796 * for both of them.
7797 */
7798 adapter->vferr_refcount++;
7799
7800 return PCI_ERS_RESULT_RECOVERED;
7801
7802skip_bad_vf_detection:
7803#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007804 netif_device_detach(netdev);
7805
Breno Leitao3044b8d2009-05-06 10:44:26 +00007806 if (state == pci_channel_io_perm_failure)
7807 return PCI_ERS_RESULT_DISCONNECT;
7808
Auke Kok9a799d72007-09-15 14:07:45 -07007809 if (netif_running(netdev))
7810 ixgbe_down(adapter);
7811 pci_disable_device(pdev);
7812
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007813 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007814 return PCI_ERS_RESULT_NEED_RESET;
7815}
7816
7817/**
7818 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7819 * @pdev: Pointer to PCI device
7820 *
7821 * Restart the card from scratch, as if from a cold-boot.
7822 */
7823static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7824{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007825 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007826 pci_ers_result_t result;
7827 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007828
gouji-new9ce77662009-05-06 10:44:45 +00007829 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007830 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007831 result = PCI_ERS_RESULT_DISCONNECT;
7832 } else {
7833 pci_set_master(pdev);
7834 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007835 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007836
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007837 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007838
7839 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007840 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007841 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007842 }
Auke Kok9a799d72007-09-15 14:07:45 -07007843
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007844 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7845 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007846 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7847 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007848 /* non-fatal, continue */
7849 }
Auke Kok9a799d72007-09-15 14:07:45 -07007850
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007851 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007852}
7853
7854/**
7855 * ixgbe_io_resume - called when traffic can start flowing again.
7856 * @pdev: Pointer to PCI device
7857 *
7858 * This callback is called when the error recovery driver tells us that
7859 * its OK to resume normal operation.
7860 */
7861static void ixgbe_io_resume(struct pci_dev *pdev)
7862{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007863 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7864 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007865
Greg Rose83c61fa2011-09-07 05:59:35 +00007866#ifdef CONFIG_PCI_IOV
7867 if (adapter->vferr_refcount) {
7868 e_info(drv, "Resuming after VF err\n");
7869 adapter->vferr_refcount--;
7870 return;
7871 }
7872
7873#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007874 if (netif_running(netdev))
7875 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007876
7877 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007878}
7879
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007880static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007881 .error_detected = ixgbe_io_error_detected,
7882 .slot_reset = ixgbe_io_slot_reset,
7883 .resume = ixgbe_io_resume,
7884};
7885
7886static struct pci_driver ixgbe_driver = {
7887 .name = ixgbe_driver_name,
7888 .id_table = ixgbe_pci_tbl,
7889 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007890 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07007891#ifdef CONFIG_PM
7892 .suspend = ixgbe_suspend,
7893 .resume = ixgbe_resume,
7894#endif
7895 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +00007896 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -07007897 .err_handler = &ixgbe_err_handler
7898};
7899
7900/**
7901 * ixgbe_init_module - Driver Registration Routine
7902 *
7903 * ixgbe_init_module is the first routine called when the driver is
7904 * loaded. All it does is register with the PCI subsystem.
7905 **/
7906static int __init ixgbe_init_module(void)
7907{
7908 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007909 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007910 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007911
Catherine Sullivan00949162012-08-10 01:59:10 +00007912#ifdef CONFIG_DEBUG_FS
7913 ixgbe_dbg_init();
7914#endif /* CONFIG_DEBUG_FS */
7915
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007916#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007917 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007918#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007919
Auke Kok9a799d72007-09-15 14:07:45 -07007920 ret = pci_register_driver(&ixgbe_driver);
7921 return ret;
7922}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007923
Auke Kok9a799d72007-09-15 14:07:45 -07007924module_init(ixgbe_init_module);
7925
7926/**
7927 * ixgbe_exit_module - Driver Exit Cleanup Routine
7928 *
7929 * ixgbe_exit_module is called just before the driver is removed
7930 * from memory.
7931 **/
7932static void __exit ixgbe_exit_module(void)
7933{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007934#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007935 dca_unregister_notify(&dca_notifier);
7936#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007937 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00007938
7939#ifdef CONFIG_DEBUG_FS
7940 ixgbe_dbg_exit();
7941#endif /* CONFIG_DEBUG_FS */
7942
Eric Dumazet1a515022010-11-16 19:26:42 -08007943 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007944}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007945
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007946#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007947static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007948 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007949{
7950 int ret_val;
7951
7952 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007953 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007954
7955 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7956}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007957
Alexander Duyckb4533682009-03-31 21:32:42 +00007958#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007959
Auke Kok9a799d72007-09-15 14:07:45 -07007960module_exit(ixgbe_exit_module);
7961
7962/* ixgbe_main.c */