blob: 4c2e9d6564ad7cf1ff1892c6e846f465959dd490 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000047#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000049#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070050
51#include "ixgbe.h"
52#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000053#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000054#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070055
56char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070057static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000058 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000059#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000060char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000062#else
63static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
65#endif
Don Skidmore14a8d4bb2012-11-09 05:03:53 +000066#define DRV_VERSION "3.11.33-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070067const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000068static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000069 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070070
71static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070072 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000073 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080074 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070075};
76
77/* ixgbe_pci_tbl - PCI Device ID Table
78 *
79 * Wildcard entries (PCI_ANY_ID) should come last
80 * Last entry must be all 0s
81 *
82 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
83 * Class, Class Mask, private data (not used) }
84 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000085static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700115 /* required last entry */
116 {0, }
117};
118MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
119
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400120#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800121static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000122 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800123static struct notifier_block dca_notifier = {
124 .notifier_call = ixgbe_notify_dca,
125 .next = NULL,
126 .priority = 0
127};
128#endif
129
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000130#ifdef CONFIG_PCI_IOV
131static unsigned int max_vfs;
132module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000133MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000134 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000135#endif /* CONFIG_PCI_IOV */
136
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000137static unsigned int allow_unsupported_sfp;
138module_param(allow_unsupported_sfp, uint, 0);
139MODULE_PARM_DESC(allow_unsupported_sfp,
140 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
141
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000142#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
143static int debug = -1;
144module_param(debug, int, 0);
145MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
146
Auke Kok9a799d72007-09-15 14:07:45 -0700147MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
148MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
149MODULE_LICENSE("GPL");
150MODULE_VERSION(DRV_VERSION);
151
Alexander Duyck70864002011-04-27 09:13:56 +0000152static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
153{
154 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
155 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
156 schedule_work(&adapter->service_task);
157}
158
159static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
160{
161 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
162
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000163 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000164 smp_mb__before_clear_bit();
165 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
166}
167
Taku Izumidcd79ae2010-04-27 14:39:53 +0000168struct ixgbe_reg_info {
169 u32 ofs;
170 char *name;
171};
172
173static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
174
175 /* General Registers */
176 {IXGBE_CTRL, "CTRL"},
177 {IXGBE_STATUS, "STATUS"},
178 {IXGBE_CTRL_EXT, "CTRL_EXT"},
179
180 /* Interrupt Registers */
181 {IXGBE_EICR, "EICR"},
182
183 /* RX Registers */
184 {IXGBE_SRRCTL(0), "SRRCTL"},
185 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
186 {IXGBE_RDLEN(0), "RDLEN"},
187 {IXGBE_RDH(0), "RDH"},
188 {IXGBE_RDT(0), "RDT"},
189 {IXGBE_RXDCTL(0), "RXDCTL"},
190 {IXGBE_RDBAL(0), "RDBAL"},
191 {IXGBE_RDBAH(0), "RDBAH"},
192
193 /* TX Registers */
194 {IXGBE_TDBAL(0), "TDBAL"},
195 {IXGBE_TDBAH(0), "TDBAH"},
196 {IXGBE_TDLEN(0), "TDLEN"},
197 {IXGBE_TDH(0), "TDH"},
198 {IXGBE_TDT(0), "TDT"},
199 {IXGBE_TXDCTL(0), "TXDCTL"},
200
201 /* List Terminator */
202 {}
203};
204
205
206/*
207 * ixgbe_regdump - register printout routine
208 */
209static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
210{
211 int i = 0, j = 0;
212 char rname[16];
213 u32 regs[64];
214
215 switch (reginfo->ofs) {
216 case IXGBE_SRRCTL(0):
217 for (i = 0; i < 64; i++)
218 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
219 break;
220 case IXGBE_DCA_RXCTRL(0):
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
223 break;
224 case IXGBE_RDLEN(0):
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
227 break;
228 case IXGBE_RDH(0):
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
231 break;
232 case IXGBE_RDT(0):
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
235 break;
236 case IXGBE_RXDCTL(0):
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
239 break;
240 case IXGBE_RDBAL(0):
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
243 break;
244 case IXGBE_RDBAH(0):
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
247 break;
248 case IXGBE_TDBAL(0):
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
251 break;
252 case IXGBE_TDBAH(0):
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
255 break;
256 case IXGBE_TDLEN(0):
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
259 break;
260 case IXGBE_TDH(0):
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
263 break;
264 case IXGBE_TDT(0):
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
267 break;
268 case IXGBE_TXDCTL(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
271 break;
272 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000273 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000274 IXGBE_READ_REG(hw, reginfo->ofs));
275 return;
276 }
277
278 for (i = 0; i < 8; i++) {
279 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000280 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000281 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000282 pr_cont(" %08x", regs[i*8+j]);
283 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000284 }
285
286}
287
288/*
289 * ixgbe_dump - Print registers, tx-rings and rx-rings
290 */
291static void ixgbe_dump(struct ixgbe_adapter *adapter)
292{
293 struct net_device *netdev = adapter->netdev;
294 struct ixgbe_hw *hw = &adapter->hw;
295 struct ixgbe_reg_info *reginfo;
296 int n = 0;
297 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000298 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000299 union ixgbe_adv_tx_desc *tx_desc;
300 struct my_u0 { u64 a; u64 b; } *u0;
301 struct ixgbe_ring *rx_ring;
302 union ixgbe_adv_rx_desc *rx_desc;
303 struct ixgbe_rx_buffer *rx_buffer_info;
304 u32 staterr;
305 int i = 0;
306
307 if (!netif_msg_hw(adapter))
308 return;
309
310 /* Print netdevice Info */
311 if (netdev) {
312 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000313 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000315 pr_info("%-15s %016lX %016lX %016lX\n",
316 netdev->name,
317 netdev->state,
318 netdev->trans_start,
319 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000320 }
321
322 /* Print Registers */
323 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000324 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000325 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
326 reginfo->name; reginfo++) {
327 ixgbe_regdump(hw, reginfo);
328 }
329
330 /* Print TX Ring Summary */
331 if (!netdev || !netif_running(netdev))
332 goto exit;
333
334 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000335 pr_info(" %s %s %s %s\n",
336 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
337 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000338 for (n = 0; n < adapter->num_tx_queues; n++) {
339 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000340 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000341 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000342 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000343 (u64)dma_unmap_addr(tx_buffer, dma),
344 dma_unmap_len(tx_buffer, len),
345 tx_buffer->next_to_watch,
346 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000347 }
348
349 /* Print TX Rings */
350 if (!netif_msg_tx_done(adapter))
351 goto rx_ring_summary;
352
353 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
354
355 /* Transmit Descriptor Formats
356 *
Josh Hay39ac8682012-09-26 05:59:36 +0000357 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000358 * +--------------------------------------------------------------+
359 * 0 | Buffer Address [63:0] |
360 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000361 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000362 * +--------------------------------------------------------------+
363 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000364 *
365 * 82598 Advanced Transmit Descriptor (Write-Back Format)
366 * +--------------------------------------------------------------+
367 * 0 | RSV [63:0] |
368 * +--------------------------------------------------------------+
369 * 8 | RSV | STA | NXTSEQ |
370 * +--------------------------------------------------------------+
371 * 63 36 35 32 31 0
372 *
373 * 82599+ Advanced Transmit Descriptor
374 * +--------------------------------------------------------------+
375 * 0 | Buffer Address [63:0] |
376 * +--------------------------------------------------------------+
377 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
378 * +--------------------------------------------------------------+
379 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
380 *
381 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
382 * +--------------------------------------------------------------+
383 * 0 | RSV [63:0] |
384 * +--------------------------------------------------------------+
385 * 8 | RSV | STA | RSV |
386 * +--------------------------------------------------------------+
387 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 */
389
390 for (n = 0; n < adapter->num_tx_queues; n++) {
391 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000392 pr_info("------------------------------------\n");
393 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
394 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000395 pr_info("%s%s %s %s %s %s\n",
396 "T [desc] [address 63:0 ] ",
397 "[PlPOIdStDDt Ln] [bi->dma ] ",
398 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000399
400 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000401 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000402 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000403 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000404 if (dma_unmap_len(tx_buffer, len) > 0) {
405 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
406 i,
407 le64_to_cpu(u0->a),
408 le64_to_cpu(u0->b),
409 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000410 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000411 tx_buffer->next_to_watch,
412 (u64)tx_buffer->time_stamp,
413 tx_buffer->skb);
414 if (i == tx_ring->next_to_use &&
415 i == tx_ring->next_to_clean)
416 pr_cont(" NTC/U\n");
417 else if (i == tx_ring->next_to_use)
418 pr_cont(" NTU\n");
419 else if (i == tx_ring->next_to_clean)
420 pr_cont(" NTC\n");
421 else
422 pr_cont("\n");
423
424 if (netif_msg_pktdata(adapter) &&
425 tx_buffer->skb)
426 print_hex_dump(KERN_INFO, "",
427 DUMP_PREFIX_ADDRESS, 16, 1,
428 tx_buffer->skb->data,
429 dma_unmap_len(tx_buffer, len),
430 true);
431 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000432 }
433 }
434
435 /* Print RX Rings Summary */
436rx_ring_summary:
437 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000439 for (n = 0; n < adapter->num_rx_queues; n++) {
440 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000441 pr_info("%5d %5X %5X\n",
442 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000443 }
444
445 /* Print RX Rings */
446 if (!netif_msg_rx_status(adapter))
447 goto exit;
448
449 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
450
Josh Hay39ac8682012-09-26 05:59:36 +0000451 /* Receive Descriptor Formats
452 *
453 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000454 * 63 1 0
455 * +-----------------------------------------------------+
456 * 0 | Packet Buffer Address [63:1] |A0/NSE|
457 * +----------------------------------------------+------+
458 * 8 | Header Buffer Address [63:1] | DD |
459 * +-----------------------------------------------------+
460 *
461 *
Josh Hay39ac8682012-09-26 05:59:36 +0000462 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000463 *
464 * 63 48 47 32 31 30 21 20 16 15 4 3 0
465 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000466 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
467 * | Packet | IP | | | | Type | Type |
468 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000469 * +------------------------------------------------------+
470 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
471 * +------------------------------------------------------+
472 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000473 *
474 * 82599+ Advanced Receive Descriptor (Read) Format
475 * 63 1 0
476 * +-----------------------------------------------------+
477 * 0 | Packet Buffer Address [63:1] |A0/NSE|
478 * +----------------------------------------------+------+
479 * 8 | Header Buffer Address [63:1] | DD |
480 * +-----------------------------------------------------+
481 *
482 *
483 * 82599+ Advanced Receive Descriptor (Write-Back) Format
484 *
485 * 63 48 47 32 31 30 21 20 17 16 4 3 0
486 * +------------------------------------------------------+
487 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
488 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
489 * |/ Flow Dir Flt ID | | | | | |
490 * +------------------------------------------------------+
491 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
492 * +------------------------------------------------------+
493 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000494 */
Josh Hay39ac8682012-09-26 05:59:36 +0000495
Taku Izumidcd79ae2010-04-27 14:39:53 +0000496 for (n = 0; n < adapter->num_rx_queues; n++) {
497 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000498 pr_info("------------------------------------\n");
499 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
500 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000501 pr_info("%s%s%s",
502 "R [desc] [ PktBuf A0] ",
503 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000504 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000505 pr_info("%s%s%s",
506 "RWB[desc] [PcsmIpSHl PtRs] ",
507 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000508 "<-- Adv Rx Write-Back format\n");
509
510 for (i = 0; i < rx_ring->count; i++) {
511 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000512 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000513 u0 = (struct my_u0 *)rx_desc;
514 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
515 if (staterr & IXGBE_RXD_STAT_DD) {
516 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000517 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000518 "%016llX ---------------- %p", i,
519 le64_to_cpu(u0->a),
520 le64_to_cpu(u0->b),
521 rx_buffer_info->skb);
522 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000523 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000524 "%016llX %016llX %p", i,
525 le64_to_cpu(u0->a),
526 le64_to_cpu(u0->b),
527 (u64)rx_buffer_info->dma,
528 rx_buffer_info->skb);
529
Emil Tantilov9c50c032012-07-26 01:21:24 +0000530 if (netif_msg_pktdata(adapter) &&
531 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000532 print_hex_dump(KERN_INFO, "",
533 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000534 page_address(rx_buffer_info->page) +
535 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000536 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000537 }
538 }
539
540 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000542 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000543 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000544 else
Joe Perchesc7689572010-09-07 21:35:17 +0000545 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000546
547 }
548 }
549
550exit:
551 return;
552}
553
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800554static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
555{
556 u32 ctrl_ext;
557
558 /* Let firmware take over control of h/w */
559 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
560 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000561 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800562}
563
564static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
565{
566 u32 ctrl_ext;
567
568 /* Let firmware know the driver has taken over */
569 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800572}
Auke Kok9a799d72007-09-15 14:07:45 -0700573
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000574/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000575 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
576 * @adapter: pointer to adapter struct
577 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
578 * @queue: queue to map the corresponding interrupt to
579 * @msix_vector: the vector to map to the corresponding queue
580 *
581 */
582static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000583 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700584{
585 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000586 struct ixgbe_hw *hw = &adapter->hw;
587 switch (hw->mac.type) {
588 case ixgbe_mac_82598EB:
589 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
590 if (direction == -1)
591 direction = 0;
592 index = (((direction * 64) + queue) >> 2) & 0x1F;
593 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
594 ivar &= ~(0xFF << (8 * (queue & 0x3)));
595 ivar |= (msix_vector << (8 * (queue & 0x3)));
596 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
597 break;
598 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800599 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000600 if (direction == -1) {
601 /* other causes */
602 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
603 index = ((queue & 1) * 8);
604 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
605 ivar &= ~(0xFF << index);
606 ivar |= (msix_vector << index);
607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
608 break;
609 } else {
610 /* tx or rx causes */
611 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
612 index = ((16 * (queue & 1)) + (8 * direction));
613 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
614 ivar &= ~(0xFF << index);
615 ivar |= (msix_vector << index);
616 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
617 break;
618 }
619 default:
620 break;
621 }
Auke Kok9a799d72007-09-15 14:07:45 -0700622}
623
Alexander Duyckfe49f042009-06-04 16:00:09 +0000624static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000625 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000626{
627 u32 mask;
628
Alexander Duyckbd508172010-11-16 19:27:03 -0800629 switch (adapter->hw.mac.type) {
630 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000631 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
632 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800633 break;
634 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800635 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000636 mask = (qmask & 0xFFFFFFFF);
637 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
638 mask = (qmask >> 32);
639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800640 break;
641 default:
642 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000643 }
644}
645
Alexander Duyck729739b2012-02-08 07:51:06 +0000646void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
647 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000648{
Alexander Duyck729739b2012-02-08 07:51:06 +0000649 if (tx_buffer->skb) {
650 dev_kfree_skb_any(tx_buffer->skb);
651 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000652 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000653 dma_unmap_addr(tx_buffer, dma),
654 dma_unmap_len(tx_buffer, len),
655 DMA_TO_DEVICE);
656 } else if (dma_unmap_len(tx_buffer, len)) {
657 dma_unmap_page(ring->dev,
658 dma_unmap_addr(tx_buffer, dma),
659 dma_unmap_len(tx_buffer, len),
660 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000661 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000662 tx_buffer->next_to_watch = NULL;
663 tx_buffer->skb = NULL;
664 dma_unmap_len_set(tx_buffer, len, 0);
665 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700666}
667
Alexander Duyck943561d2012-05-09 22:14:44 -0700668static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
669{
670 struct ixgbe_hw *hw = &adapter->hw;
671 struct ixgbe_hw_stats *hwstats = &adapter->stats;
672 int i;
673 u32 data;
674
675 if ((hw->fc.current_mode != ixgbe_fc_full) &&
676 (hw->fc.current_mode != ixgbe_fc_rx_pause))
677 return;
678
679 switch (hw->mac.type) {
680 case ixgbe_mac_82598EB:
681 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
682 break;
683 default:
684 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
685 }
686 hwstats->lxoffrxc += data;
687
688 /* refill credits (no tx hang) if we received xoff */
689 if (!data)
690 return;
691
692 for (i = 0; i < adapter->num_tx_queues; i++)
693 clear_bit(__IXGBE_HANG_CHECK_ARMED,
694 &adapter->tx_ring[i]->state);
695}
696
John Fastabendc84d3242010-11-16 19:27:12 -0800697static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700698{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700699 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800700 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800701 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000702 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800703 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700704 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700705
Alexander Duyck943561d2012-05-09 22:14:44 -0700706 if (adapter->ixgbe_ieee_pfc)
707 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800708
Alexander Duyck943561d2012-05-09 22:14:44 -0700709 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
710 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800711 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700712 }
John Fastabendc84d3242010-11-16 19:27:12 -0800713
714 /* update stats for each tc, only valid with PFC enabled */
715 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000716 u32 pxoffrxc;
717
John Fastabendc84d3242010-11-16 19:27:12 -0800718 switch (hw->mac.type) {
719 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000720 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800721 break;
722 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000723 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800724 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000725 hwstats->pxoffrxc[i] += pxoffrxc;
726 /* Get the TC for given UP */
727 tc = netdev_get_prio_tc_map(adapter->netdev, i);
728 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700729 }
730
John Fastabendc84d3242010-11-16 19:27:12 -0800731 /* disarm tx queues that have received xoff frames */
732 for (i = 0; i < adapter->num_tx_queues; i++) {
733 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800734
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000735 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800736 if (xoff[tc])
737 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
738 }
739}
740
741static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
742{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000743 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800744}
745
746static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
747{
748 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
749 struct ixgbe_hw *hw = &adapter->hw;
750
751 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
752 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
753
754 if (head != tail)
755 return (head < tail) ?
756 tail - head : (tail + ring->count - head);
757
758 return 0;
759}
760
761static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
762{
763 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
764 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
765 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
766 bool ret = false;
767
768 clear_check_for_tx_hang(tx_ring);
769
770 /*
771 * Check for a hung queue, but be thorough. This verifies
772 * that a transmit has been completed since the previous
773 * check AND there is at least one packet pending. The
774 * ARMED bit is set to indicate a potential hang. The
775 * bit is cleared if a pause frame is received to remove
776 * false hang detection due to PFC or 802.3x frames. By
777 * requiring this to fail twice we avoid races with
778 * pfc clearing the ARMED bit and conditions where we
779 * run the check_tx_hang logic with a transmit completion
780 * pending but without time to complete it yet.
781 */
782 if ((tx_done_old == tx_done) && tx_pending) {
783 /* make sure it is true for two checks in a row */
784 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
785 &tx_ring->state);
786 } else {
787 /* update completed stats and continue */
788 tx_ring->tx_stats.tx_done_old = tx_done;
789 /* reset the countdown */
790 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
791 }
792
793 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700794}
795
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000796/**
797 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
798 * @adapter: driver private struct
799 **/
800static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
801{
802
803 /* Do the reset outside of interrupt context */
804 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
805 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
806 ixgbe_service_event_schedule(adapter);
807 }
808}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700809
Auke Kok9a799d72007-09-15 14:07:45 -0700810/**
811 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000812 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700813 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700814 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000815static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000816 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700817{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000818 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000819 struct ixgbe_tx_buffer *tx_buffer;
820 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700821 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000822 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000823 unsigned int i = tx_ring->next_to_clean;
824
825 if (test_bit(__IXGBE_DOWN, &adapter->state))
826 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700827
Alexander Duyckd3d00232011-07-15 02:31:25 +0000828 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000829 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000830 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800831
Alexander Duyck729739b2012-02-08 07:51:06 +0000832 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000833 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700834
Alexander Duyckd3d00232011-07-15 02:31:25 +0000835 /* if next_to_watch is not set then there is no work pending */
836 if (!eop_desc)
837 break;
838
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000839 /* prevent any other reads prior to eop_desc */
840 rmb();
841
Alexander Duyckd3d00232011-07-15 02:31:25 +0000842 /* if DD is not set pending work has not been completed */
843 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
844 break;
845
Alexander Duyckd3d00232011-07-15 02:31:25 +0000846 /* clear next_to_watch to prevent false hangs */
847 tx_buffer->next_to_watch = NULL;
848
Alexander Duyck091a6242012-02-08 07:51:01 +0000849 /* update the statistics for this packet */
850 total_bytes += tx_buffer->bytecount;
851 total_packets += tx_buffer->gso_segs;
852
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000853 /* free the skb */
854 dev_kfree_skb_any(tx_buffer->skb);
855
Alexander Duyck729739b2012-02-08 07:51:06 +0000856 /* unmap skb header data */
857 dma_unmap_single(tx_ring->dev,
858 dma_unmap_addr(tx_buffer, dma),
859 dma_unmap_len(tx_buffer, len),
860 DMA_TO_DEVICE);
861
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000862 /* clear tx_buffer data */
863 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000864 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000865
Alexander Duyck729739b2012-02-08 07:51:06 +0000866 /* unmap remaining buffers */
867 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000868 tx_buffer++;
869 tx_desc++;
870 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000871 if (unlikely(!i)) {
872 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000873 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000874 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000875 }
876
Alexander Duyck729739b2012-02-08 07:51:06 +0000877 /* unmap any remaining paged data */
878 if (dma_unmap_len(tx_buffer, len)) {
879 dma_unmap_page(tx_ring->dev,
880 dma_unmap_addr(tx_buffer, dma),
881 dma_unmap_len(tx_buffer, len),
882 DMA_TO_DEVICE);
883 dma_unmap_len_set(tx_buffer, len, 0);
884 }
885 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800886
Alexander Duyck729739b2012-02-08 07:51:06 +0000887 /* move us one more past the eop_desc for start of next pkt */
888 tx_buffer++;
889 tx_desc++;
890 i++;
891 if (unlikely(!i)) {
892 i -= tx_ring->count;
893 tx_buffer = tx_ring->tx_buffer_info;
894 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
895 }
896
897 /* issue prefetch for next Tx descriptor */
898 prefetch(tx_desc);
899
900 /* update budget accounting */
901 budget--;
902 } while (likely(budget));
903
904 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700905 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000906 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800907 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000908 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000909 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000910 q_vector->tx.total_bytes += total_bytes;
911 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800912
John Fastabendc84d3242010-11-16 19:27:12 -0800913 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800914 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800915 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800916 e_err(drv, "Detected Tx Unit Hang\n"
917 " Tx Queue <%d>\n"
918 " TDH, TDT <%x>, <%x>\n"
919 " next_to_use <%x>\n"
920 " next_to_clean <%x>\n"
921 "tx_buffer_info[next_to_clean]\n"
922 " time_stamp <%lx>\n"
923 " jiffies <%lx>\n",
924 tx_ring->queue_index,
925 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
926 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000927 tx_ring->next_to_use, i,
928 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800929
930 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
931
932 e_info(probe,
933 "tx hang %d detected on queue %d, resetting adapter\n",
934 adapter->tx_timeout_count + 1, tx_ring->queue_index);
935
936 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000937 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800938
939 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000940 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800941 }
Auke Kok9a799d72007-09-15 14:07:45 -0700942
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000943 netdev_tx_completed_queue(txring_txq(tx_ring),
944 total_packets, total_bytes);
945
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800946#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000947 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000948 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800949 /* Make sure that anybody stopping the queue after this
950 * sees the new next_to_clean.
951 */
952 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000953 if (__netif_subqueue_stopped(tx_ring->netdev,
954 tx_ring->queue_index)
955 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
956 netif_wake_subqueue(tx_ring->netdev,
957 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800958 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800959 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800960 }
Auke Kok9a799d72007-09-15 14:07:45 -0700961
Alexander Duyck59224552011-08-31 00:01:06 +0000962 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700963}
964
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400965#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800966static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800967 struct ixgbe_ring *tx_ring,
968 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800969{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000970 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000971 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
972 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800973
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800974 switch (hw->mac.type) {
975 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000976 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800977 break;
978 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800979 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000980 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
981 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
982 break;
983 default:
984 /* for unknown hardware do not write register */
985 return;
986 }
987
988 /*
989 * We can enable relaxed ordering for reads, but not writes when
990 * DCA is enabled. This is due to a known issue in some chipsets
991 * which will cause the DCA tag to be cleared.
992 */
993 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
994 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
995 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
996
997 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
998}
999
1000static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1001 struct ixgbe_ring *rx_ring,
1002 int cpu)
1003{
1004 struct ixgbe_hw *hw = &adapter->hw;
1005 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1006 u8 reg_idx = rx_ring->reg_idx;
1007
1008
1009 switch (hw->mac.type) {
1010 case ixgbe_mac_82599EB:
1011 case ixgbe_mac_X540:
1012 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001013 break;
1014 default:
1015 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001016 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001017
1018 /*
1019 * We can enable relaxed ordering for reads, but not writes when
1020 * DCA is enabled. This is due to a known issue in some chipsets
1021 * which will cause the DCA tag to be cleared.
1022 */
1023 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001024 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1025
1026 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001027}
1028
1029static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1030{
1031 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001032 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001033 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001034
1035 if (q_vector->cpu == cpu)
1036 goto out_no_update;
1037
Alexander Duycka5579282012-02-08 07:50:04 +00001038 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001039 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001040
Alexander Duycka5579282012-02-08 07:50:04 +00001041 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001042 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001043
1044 q_vector->cpu = cpu;
1045out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001046 put_cpu();
1047}
1048
1049static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1050{
1051 int i;
1052
1053 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1054 return;
1055
Alexander Duycke35ec122009-05-21 13:07:12 +00001056 /* always use CB2 mode, difference is masked in the CB driver */
1057 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1058
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001059 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001060 adapter->q_vector[i]->cpu = -1;
1061 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001062 }
1063}
1064
1065static int __ixgbe_notify_dca(struct device *dev, void *data)
1066{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001067 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001068 unsigned long event = *(unsigned long *)data;
1069
Don Skidmore2a72c312011-07-20 02:27:05 +00001070 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001071 return 0;
1072
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001073 switch (event) {
1074 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001075 /* if we're already enabled, don't do it again */
1076 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1077 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001078 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001079 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001080 ixgbe_setup_dca(adapter);
1081 break;
1082 }
1083 /* Fall Through since DCA is disabled. */
1084 case DCA_PROVIDER_REMOVE:
1085 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1086 dca_remove_requester(dev);
1087 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1088 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1089 }
1090 break;
1091 }
1092
Denis V. Lunev652f0932008-03-27 14:39:17 +03001093 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001094}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001095
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001096#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001097static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1098 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001099 struct sk_buff *skb)
1100{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001101 if (ring->netdev->features & NETIF_F_RXHASH)
1102 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001103}
1104
Alexander Duyckf8003262012-03-03 02:35:52 +00001105#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001106/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001107 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001108 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001109 * @rx_desc: advanced rx descriptor
1110 *
1111 * Returns : true if it is FCoE pkt
1112 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001113static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001114 union ixgbe_adv_rx_desc *rx_desc)
1115{
1116 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1117
Alexander Duyck57efd442012-06-25 21:54:46 +00001118 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001119 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1120 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1121 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1122}
1123
Alexander Duyckf8003262012-03-03 02:35:52 +00001124#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001125/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001126 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001127 * @ring: structure containing ring specific data
1128 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001129 * @skb: skb currently being received and modified
1130 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001131static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001132 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001133 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001134{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001135 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001136
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001137 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001138 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001139 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001140
1141 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001142 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1143 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001144 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001145 return;
1146 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001147
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001148 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001149 return;
1150
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001151 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001152 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001153
1154 /*
1155 * 82599 errata, UDP frames with a 0 checksum can be marked as
1156 * checksum errors.
1157 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001158 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1159 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001160 return;
1161
Alexander Duyck8a0da212012-01-31 02:59:49 +00001162 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001163 return;
1164 }
1165
Auke Kok9a799d72007-09-15 14:07:45 -07001166 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001167 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001168}
1169
Alexander Duyck84ea2592010-11-16 19:26:49 -08001170static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001171{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001172 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001173
1174 /* update next to alloc since we have filled the ring */
1175 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001176 /*
1177 * Force memory writes to complete before letting h/w
1178 * know there are new descriptors to fetch. (Only
1179 * applicable for weak-ordered memory model archs,
1180 * such as IA-64).
1181 */
1182 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001183 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001184}
1185
Alexander Duyckf990b792012-01-31 02:59:34 +00001186static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1187 struct ixgbe_rx_buffer *bi)
1188{
1189 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001190 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001191
Alexander Duyckf8003262012-03-03 02:35:52 +00001192 /* since we are recycling buffers we should seldom need to alloc */
1193 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001194 return true;
1195
Alexander Duyckf8003262012-03-03 02:35:52 +00001196 /* alloc new page for storage */
1197 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001198 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1199 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001200 if (unlikely(!page)) {
1201 rx_ring->rx_stats.alloc_rx_page_failed++;
1202 return false;
1203 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001204 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001205 }
1206
Alexander Duyckf8003262012-03-03 02:35:52 +00001207 /* map page for use */
1208 dma = dma_map_page(rx_ring->dev, page, 0,
1209 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001210
Alexander Duyckf8003262012-03-03 02:35:52 +00001211 /*
1212 * if mapping failed free memory back to system since
1213 * there isn't much point in holding memory we can't use
1214 */
1215 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001216 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001217 bi->page = NULL;
1218
Alexander Duyckf990b792012-01-31 02:59:34 +00001219 rx_ring->rx_stats.alloc_rx_page_failed++;
1220 return false;
1221 }
1222
Alexander Duyckf8003262012-03-03 02:35:52 +00001223 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001224 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001225
Alexander Duyckf990b792012-01-31 02:59:34 +00001226 return true;
1227}
1228
Auke Kok9a799d72007-09-15 14:07:45 -07001229/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001230 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001231 * @rx_ring: ring to place buffers on
1232 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001233 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001234void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001235{
Auke Kok9a799d72007-09-15 14:07:45 -07001236 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001237 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001238 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001239
Alexander Duyckf8003262012-03-03 02:35:52 +00001240 /* nothing to do */
1241 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001242 return;
1243
Alexander Duycke4f74022012-01-31 02:59:44 +00001244 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001245 bi = &rx_ring->rx_buffer_info[i];
1246 i -= rx_ring->count;
1247
Alexander Duyckf8003262012-03-03 02:35:52 +00001248 do {
1249 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001250 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001251
Alexander Duyckf8003262012-03-03 02:35:52 +00001252 /*
1253 * Refresh the desc even if buffer_addrs didn't change
1254 * because each write-back erases this info.
1255 */
1256 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001257
Alexander Duyckf990b792012-01-31 02:59:34 +00001258 rx_desc++;
1259 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001260 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001261 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001262 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001263 bi = rx_ring->rx_buffer_info;
1264 i -= rx_ring->count;
1265 }
1266
1267 /* clear the hdr_addr for the next_to_use descriptor */
1268 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001269
1270 cleaned_count--;
1271 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001272
Alexander Duyckf990b792012-01-31 02:59:34 +00001273 i += rx_ring->count;
1274
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001275 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001276 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001277}
1278
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001279/**
1280 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1281 * @data: pointer to the start of the headers
1282 * @max_len: total length of section to find headers in
1283 *
1284 * This function is meant to determine the length of headers that will
1285 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1286 * motivation of doing this is to only perform one pull for IPv4 TCP
1287 * packets so that we can do basic things like calculating the gso_size
1288 * based on the average data per packet.
1289 **/
1290static unsigned int ixgbe_get_headlen(unsigned char *data,
1291 unsigned int max_len)
1292{
1293 union {
1294 unsigned char *network;
1295 /* l2 headers */
1296 struct ethhdr *eth;
1297 struct vlan_hdr *vlan;
1298 /* l3 headers */
1299 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001300 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001301 } hdr;
1302 __be16 protocol;
1303 u8 nexthdr = 0; /* default to not TCP */
1304 u8 hlen;
1305
1306 /* this should never happen, but better safe than sorry */
1307 if (max_len < ETH_HLEN)
1308 return max_len;
1309
1310 /* initialize network frame pointer */
1311 hdr.network = data;
1312
1313 /* set first protocol and move network header forward */
1314 protocol = hdr.eth->h_proto;
1315 hdr.network += ETH_HLEN;
1316
1317 /* handle any vlan tag if present */
1318 if (protocol == __constant_htons(ETH_P_8021Q)) {
1319 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1320 return max_len;
1321
1322 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1323 hdr.network += VLAN_HLEN;
1324 }
1325
1326 /* handle L3 protocols */
1327 if (protocol == __constant_htons(ETH_P_IP)) {
1328 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1329 return max_len;
1330
1331 /* access ihl as a u8 to avoid unaligned access on ia64 */
1332 hlen = (hdr.network[0] & 0x0F) << 2;
1333
1334 /* verify hlen meets minimum size requirements */
1335 if (hlen < sizeof(struct iphdr))
1336 return hdr.network - data;
1337
Alexander Duycked83da12012-11-13 01:13:33 +00001338 /* record next protocol if header is present */
1339 if (!hdr.ipv4->frag_off)
1340 nexthdr = hdr.ipv4->protocol;
Alexander Duycka048b402012-05-24 08:26:29 +00001341 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1342 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1343 return max_len;
1344
1345 /* record next protocol */
1346 nexthdr = hdr.ipv6->nexthdr;
Alexander Duycked83da12012-11-13 01:13:33 +00001347 hlen = sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001348#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001349 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1350 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1351 return max_len;
Alexander Duycked83da12012-11-13 01:13:33 +00001352 hlen = FCOE_HEADER_LEN;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001353#endif
1354 } else {
1355 return hdr.network - data;
1356 }
1357
Alexander Duycked83da12012-11-13 01:13:33 +00001358 /* relocate pointer to start of L4 header */
1359 hdr.network += hlen;
1360
Alexander Duycka048b402012-05-24 08:26:29 +00001361 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001362 if (nexthdr == IPPROTO_TCP) {
1363 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1364 return max_len;
1365
1366 /* access doff as a u8 to avoid unaligned access on ia64 */
1367 hlen = (hdr.network[12] & 0xF0) >> 2;
1368
1369 /* verify hlen meets minimum size requirements */
1370 if (hlen < sizeof(struct tcphdr))
1371 return hdr.network - data;
1372
1373 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001374 } else if (nexthdr == IPPROTO_UDP) {
1375 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1376 return max_len;
1377
1378 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001379 }
1380
1381 /*
1382 * If everything has gone correctly hdr.network should be the
1383 * data section of the packet and will be the end of the header.
1384 * If not then it probably represents the end of the last recognized
1385 * header.
1386 */
1387 if ((hdr.network - data) < max_len)
1388 return hdr.network - data;
1389 else
1390 return max_len;
1391}
1392
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001393static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1394 struct sk_buff *skb)
1395{
Alexander Duyckf8003262012-03-03 02:35:52 +00001396 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001397
1398 /* set gso_size to avoid messing up TCP MSS */
1399 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1400 IXGBE_CB(skb)->append_cnt);
1401}
1402
1403static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1404 struct sk_buff *skb)
1405{
1406 /* if append_cnt is 0 then frame is not RSC */
1407 if (!IXGBE_CB(skb)->append_cnt)
1408 return;
1409
1410 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1411 rx_ring->rx_stats.rsc_flush++;
1412
1413 ixgbe_set_rsc_gso_size(rx_ring, skb);
1414
1415 /* gso_size is computed using append_cnt so always clear it last */
1416 IXGBE_CB(skb)->append_cnt = 0;
1417}
1418
Alexander Duyck8a0da212012-01-31 02:59:49 +00001419/**
1420 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1421 * @rx_ring: rx descriptor ring packet is being transacted on
1422 * @rx_desc: pointer to the EOP Rx descriptor
1423 * @skb: pointer to current skb being populated
1424 *
1425 * This function checks the ring, descriptor, and packet information in
1426 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1427 * other fields within the skb.
1428 **/
1429static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1430 union ixgbe_adv_rx_desc *rx_desc,
1431 struct sk_buff *skb)
1432{
John Fastabend43e95f12012-05-15 06:12:17 +00001433 struct net_device *dev = rx_ring->netdev;
1434
Alexander Duyck8a0da212012-01-31 02:59:49 +00001435 ixgbe_update_rsc_stats(rx_ring, skb);
1436
1437 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1438
1439 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1440
Jacob Keller6cb562d2012-12-05 07:24:41 +00001441 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001442
John Fastabend43e95f12012-05-15 06:12:17 +00001443 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1444 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001445 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1446 __vlan_hwaccel_put_tag(skb, vid);
1447 }
1448
1449 skb_record_rx_queue(skb, rx_ring->queue_index);
1450
John Fastabend43e95f12012-05-15 06:12:17 +00001451 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001452}
1453
1454static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1455 struct sk_buff *skb)
1456{
1457 struct ixgbe_adapter *adapter = q_vector->adapter;
1458
1459 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1460 napi_gro_receive(&q_vector->napi, skb);
1461 else
1462 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001463}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001464
Alexander Duyckf8003262012-03-03 02:35:52 +00001465/**
1466 * ixgbe_is_non_eop - process handling of non-EOP buffers
1467 * @rx_ring: Rx ring being processed
1468 * @rx_desc: Rx descriptor for current buffer
1469 * @skb: Current socket buffer containing buffer in progress
1470 *
1471 * This function updates next to clean. If the buffer is an EOP buffer
1472 * this function exits returning false, otherwise it will place the
1473 * sk_buff in the next buffer to be chained and return true indicating
1474 * that this is in fact a non-EOP buffer.
1475 **/
1476static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1477 union ixgbe_adv_rx_desc *rx_desc,
1478 struct sk_buff *skb)
1479{
1480 u32 ntc = rx_ring->next_to_clean + 1;
1481
1482 /* fetch, update, and store next to clean */
1483 ntc = (ntc < rx_ring->count) ? ntc : 0;
1484 rx_ring->next_to_clean = ntc;
1485
1486 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1487
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001488 /* update RSC append count if present */
1489 if (ring_is_rsc_enabled(rx_ring)) {
1490 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1491 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1492
1493 if (unlikely(rsc_enabled)) {
1494 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1495
1496 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1497 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1498
1499 /* update ntc based on RSC value */
1500 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1501 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1502 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1503 }
1504 }
1505
1506 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001507 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1508 return false;
1509
Alexander Duyckf8003262012-03-03 02:35:52 +00001510 /* place skb in next buffer to be received */
1511 rx_ring->rx_buffer_info[ntc].skb = skb;
1512 rx_ring->rx_stats.non_eop_descs++;
1513
1514 return true;
1515}
1516
1517/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001518 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1519 * @rx_ring: rx descriptor ring packet is being transacted on
1520 * @skb: pointer to current skb being adjusted
1521 *
1522 * This function is an ixgbe specific version of __pskb_pull_tail. The
1523 * main difference between this version and the original function is that
1524 * this function can make several assumptions about the state of things
1525 * that allow for significant optimizations versus the standard function.
1526 * As a result we can do things like drop a frag and maintain an accurate
1527 * truesize for the skb.
1528 */
1529static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1530 struct sk_buff *skb)
1531{
1532 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1533 unsigned char *va;
1534 unsigned int pull_len;
1535
1536 /*
1537 * it is valid to use page_address instead of kmap since we are
1538 * working with pages allocated out of the lomem pool per
1539 * alloc_page(GFP_ATOMIC)
1540 */
1541 va = skb_frag_address(frag);
1542
1543 /*
1544 * we need the header to contain the greater of either ETH_HLEN or
1545 * 60 bytes if the skb->len is less than 60 for skb_pad.
1546 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001547 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001548
1549 /* align pull length to size of long to optimize memcpy performance */
1550 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1551
1552 /* update all of the pointers */
1553 skb_frag_size_sub(frag, pull_len);
1554 frag->page_offset += pull_len;
1555 skb->data_len -= pull_len;
1556 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001557}
1558
1559/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001560 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1561 * @rx_ring: rx descriptor ring packet is being transacted on
1562 * @skb: pointer to current skb being updated
1563 *
1564 * This function provides a basic DMA sync up for the first fragment of an
1565 * skb. The reason for doing this is that the first fragment cannot be
1566 * unmapped until we have reached the end of packet descriptor for a buffer
1567 * chain.
1568 */
1569static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1570 struct sk_buff *skb)
1571{
1572 /* if the page was released unmap it, else just sync our portion */
1573 if (unlikely(IXGBE_CB(skb)->page_released)) {
1574 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1575 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1576 IXGBE_CB(skb)->page_released = false;
1577 } else {
1578 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1579
1580 dma_sync_single_range_for_cpu(rx_ring->dev,
1581 IXGBE_CB(skb)->dma,
1582 frag->page_offset,
1583 ixgbe_rx_bufsz(rx_ring),
1584 DMA_FROM_DEVICE);
1585 }
1586 IXGBE_CB(skb)->dma = 0;
1587}
1588
1589/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001590 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1591 * @rx_ring: rx descriptor ring packet is being transacted on
1592 * @rx_desc: pointer to the EOP Rx descriptor
1593 * @skb: pointer to current skb being fixed
1594 *
1595 * Check for corrupted packet headers caused by senders on the local L2
1596 * embedded NIC switch not setting up their Tx Descriptors right. These
1597 * should be very rare.
1598 *
1599 * Also address the case where we are pulling data in on pages only
1600 * and as such no data is present in the skb header.
1601 *
1602 * In addition if skb is not at least 60 bytes we need to pad it so that
1603 * it is large enough to qualify as a valid Ethernet frame.
1604 *
1605 * Returns true if an error was encountered and skb was freed.
1606 **/
1607static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1608 union ixgbe_adv_rx_desc *rx_desc,
1609 struct sk_buff *skb)
1610{
Alexander Duyckf8003262012-03-03 02:35:52 +00001611 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001612
1613 /* verify that the packet does not have any known errors */
1614 if (unlikely(ixgbe_test_staterr(rx_desc,
1615 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1616 !(netdev->features & NETIF_F_RXALL))) {
1617 dev_kfree_skb_any(skb);
1618 return true;
1619 }
1620
Alexander Duyck19861ce2012-07-20 08:08:33 +00001621 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001622 if (skb_is_nonlinear(skb))
1623 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001624
Alexander Duyck57efd442012-06-25 21:54:46 +00001625#ifdef IXGBE_FCOE
1626 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1627 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1628 return false;
1629
1630#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001631 /* if skb_pad returns an error the skb was freed */
1632 if (unlikely(skb->len < 60)) {
1633 int pad_len = 60 - skb->len;
1634
1635 if (skb_pad(skb, pad_len))
1636 return true;
1637 __skb_put(skb, pad_len);
1638 }
1639
1640 return false;
1641}
1642
1643/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001644 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1645 * @rx_ring: rx descriptor ring to store buffers on
1646 * @old_buff: donor buffer to have page reused
1647 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001648 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001649 **/
1650static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1651 struct ixgbe_rx_buffer *old_buff)
1652{
1653 struct ixgbe_rx_buffer *new_buff;
1654 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001655
1656 new_buff = &rx_ring->rx_buffer_info[nta];
1657
1658 /* update, and store next to alloc */
1659 nta++;
1660 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1661
1662 /* transfer page from old buffer to new buffer */
1663 new_buff->page = old_buff->page;
1664 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001665 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001666
1667 /* sync the buffer for use by the device */
1668 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001669 new_buff->page_offset,
1670 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001671 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001672}
1673
1674/**
1675 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1676 * @rx_ring: rx descriptor ring to transact packets on
1677 * @rx_buffer: buffer containing page to add
1678 * @rx_desc: descriptor containing length of buffer written by hardware
1679 * @skb: sk_buff to place the data into
1680 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001681 * This function will add the data contained in rx_buffer->page to the skb.
1682 * This is done either through a direct copy if the data in the buffer is
1683 * less than the skb header size, otherwise it will just attach the page as
1684 * a frag to the skb.
1685 *
1686 * The function will then update the page offset if necessary and return
1687 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001688 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001689static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001690 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001691 union ixgbe_adv_rx_desc *rx_desc,
1692 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001693{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001694 struct page *page = rx_buffer->page;
1695 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001696#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001697 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001698#else
1699 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1700 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1701 ixgbe_rx_bufsz(rx_ring);
1702#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001703
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001704 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1705 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1706
1707 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1708
1709 /* we can reuse buffer as-is, just make sure it is local */
1710 if (likely(page_to_nid(page) == numa_node_id()))
1711 return true;
1712
1713 /* this page cannot be reused so discard it */
1714 put_page(page);
1715 return false;
1716 }
1717
Alexander Duyck0549ae22012-07-20 08:08:18 +00001718 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1719 rx_buffer->page_offset, size, truesize);
1720
Alexander Duyck09816fb2012-07-20 08:08:23 +00001721 /* avoid re-using remote pages */
1722 if (unlikely(page_to_nid(page) != numa_node_id()))
1723 return false;
1724
1725#if (PAGE_SIZE < 8192)
1726 /* if we are only owner of page we can reuse it */
1727 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001728 return false;
1729
1730 /* flip page offset to other buffer */
1731 rx_buffer->page_offset ^= truesize;
1732
Alexander Duyck09816fb2012-07-20 08:08:23 +00001733 /*
1734 * since we are the only owner of the page and we need to
1735 * increment it, just set the value to 2 in order to avoid
1736 * an unecessary locked operation
1737 */
1738 atomic_set(&page->_count, 2);
1739#else
1740 /* move offset up to the next cache line */
1741 rx_buffer->page_offset += truesize;
1742
1743 if (rx_buffer->page_offset > last_offset)
1744 return false;
1745
Alexander Duyck0549ae22012-07-20 08:08:18 +00001746 /* bump ref count on page before it is given to the stack */
1747 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001748#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001749
1750 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001751}
1752
Alexander Duyck18806c92012-07-20 08:08:44 +00001753static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1754 union ixgbe_adv_rx_desc *rx_desc)
1755{
1756 struct ixgbe_rx_buffer *rx_buffer;
1757 struct sk_buff *skb;
1758 struct page *page;
1759
1760 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1761 page = rx_buffer->page;
1762 prefetchw(page);
1763
1764 skb = rx_buffer->skb;
1765
1766 if (likely(!skb)) {
1767 void *page_addr = page_address(page) +
1768 rx_buffer->page_offset;
1769
1770 /* prefetch first cache line of first page */
1771 prefetch(page_addr);
1772#if L1_CACHE_BYTES < 128
1773 prefetch(page_addr + L1_CACHE_BYTES);
1774#endif
1775
1776 /* allocate a skb to store the frags */
1777 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1778 IXGBE_RX_HDR_SIZE);
1779 if (unlikely(!skb)) {
1780 rx_ring->rx_stats.alloc_rx_buff_failed++;
1781 return NULL;
1782 }
1783
1784 /*
1785 * we will be copying header into skb->data in
1786 * pskb_may_pull so it is in our interest to prefetch
1787 * it now to avoid a possible cache miss
1788 */
1789 prefetchw(skb->data);
1790
1791 /*
1792 * Delay unmapping of the first packet. It carries the
1793 * header information, HW may still access the header
1794 * after the writeback. Only unmap it when EOP is
1795 * reached
1796 */
1797 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1798 goto dma_sync;
1799
1800 IXGBE_CB(skb)->dma = rx_buffer->dma;
1801 } else {
1802 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1803 ixgbe_dma_sync_frag(rx_ring, skb);
1804
1805dma_sync:
1806 /* we are reusing so sync this buffer for CPU use */
1807 dma_sync_single_range_for_cpu(rx_ring->dev,
1808 rx_buffer->dma,
1809 rx_buffer->page_offset,
1810 ixgbe_rx_bufsz(rx_ring),
1811 DMA_FROM_DEVICE);
1812 }
1813
1814 /* pull page into skb */
1815 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1816 /* hand second half of page back to the ring */
1817 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1818 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1819 /* the page has been released from the ring */
1820 IXGBE_CB(skb)->page_released = true;
1821 } else {
1822 /* we are not reusing the buffer so unmap it */
1823 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1824 ixgbe_rx_pg_size(rx_ring),
1825 DMA_FROM_DEVICE);
1826 }
1827
1828 /* clear contents of buffer_info */
1829 rx_buffer->skb = NULL;
1830 rx_buffer->dma = 0;
1831 rx_buffer->page = NULL;
1832
1833 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001834}
1835
1836/**
1837 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1838 * @q_vector: structure containing interrupt and ring information
1839 * @rx_ring: rx descriptor ring to transact packets on
1840 * @budget: Total limit on number of packets to process
1841 *
1842 * This function provides a "bounce buffer" approach to Rx interrupt
1843 * processing. The advantage to this is that on systems that have
1844 * expensive overhead for IOMMU access this provides a means of avoiding
1845 * it by maintaining the mapping of the page to the syste.
1846 *
1847 * Returns true if all work is completed without reaching budget
1848 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001849static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001850 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001851 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001852{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001853 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001854#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001855 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001856 int ddp_bytes;
1857 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001858#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001859 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001860
Alexander Duyckf8003262012-03-03 02:35:52 +00001861 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001862 union ixgbe_adv_rx_desc *rx_desc;
1863 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001864
Alexander Duyckf8003262012-03-03 02:35:52 +00001865 /* return some buffers to hardware, one at a time is too slow */
1866 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1867 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1868 cleaned_count = 0;
1869 }
Auke Kok9a799d72007-09-15 14:07:45 -07001870
Alexander Duyck18806c92012-07-20 08:08:44 +00001871 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001872
Alexander Duyckf8003262012-03-03 02:35:52 +00001873 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1874 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001875
Alexander Duyckf8003262012-03-03 02:35:52 +00001876 /*
1877 * This memory barrier is needed to keep us from reading
1878 * any other fields out of the rx_desc until we know the
1879 * RXD_STAT_DD bit is set
1880 */
1881 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001882
Alexander Duyck18806c92012-07-20 08:08:44 +00001883 /* retrieve a buffer from the ring */
1884 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001885
Alexander Duyck18806c92012-07-20 08:08:44 +00001886 /* exit if we failed to retrieve a buffer */
1887 if (!skb)
1888 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001889
Auke Kok9a799d72007-09-15 14:07:45 -07001890 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001891
Alexander Duyckf8003262012-03-03 02:35:52 +00001892 /* place incomplete frames back on ring for completion */
1893 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1894 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001895
Alexander Duyckf8003262012-03-03 02:35:52 +00001896 /* verify the packet layout is correct */
1897 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1898 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001899
1900 /* probably a little skewed due to removing CRC */
1901 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001902
Alexander Duyck8a0da212012-01-31 02:59:49 +00001903 /* populate checksum, timestamp, VLAN, and protocol */
1904 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1905
Yi Zou332d4a72009-05-13 13:11:53 +00001906#ifdef IXGBE_FCOE
1907 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001908 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001909 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001910 /* include DDPed FCoE data */
1911 if (ddp_bytes > 0) {
1912 if (!mss) {
1913 mss = rx_ring->netdev->mtu -
1914 sizeof(struct fcoe_hdr) -
1915 sizeof(struct fc_frame_header) -
1916 sizeof(struct fcoe_crc_eof);
1917 if (mss > 512)
1918 mss &= ~511;
1919 }
1920 total_rx_bytes += ddp_bytes;
1921 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1922 mss);
1923 }
David S. Miller823dcd22011-08-20 10:39:12 -07001924 if (!ddp_bytes) {
1925 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001926 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001927 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001928 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001929
Yi Zou332d4a72009-05-13 13:11:53 +00001930#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001931 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001932
Alexander Duyckf8003262012-03-03 02:35:52 +00001933 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001934 total_rx_packets++;
1935 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001936
Alexander Duyckc267fc12010-11-16 19:27:00 -08001937 u64_stats_update_begin(&rx_ring->syncp);
1938 rx_ring->stats.packets += total_rx_packets;
1939 rx_ring->stats.bytes += total_rx_bytes;
1940 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001941 q_vector->rx.total_packets += total_rx_packets;
1942 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001943
Alexander Duyckf8003262012-03-03 02:35:52 +00001944 if (cleaned_count)
1945 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1946
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001947 return (total_rx_packets < budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001948}
1949
Auke Kok9a799d72007-09-15 14:07:45 -07001950/**
1951 * ixgbe_configure_msix - Configure MSI-X hardware
1952 * @adapter: board private structure
1953 *
1954 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1955 * interrupts.
1956 **/
1957static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1958{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001959 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001960 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001961 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001962
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001963 /* Populate MSIX to EITR Select */
1964 if (adapter->num_vfs > 32) {
1965 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1966 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1967 }
1968
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001969 /*
1970 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001971 * corresponding register.
1972 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001973 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001974 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001975 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001976
Alexander Duycka5579282012-02-08 07:50:04 +00001977 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001978 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001979
Alexander Duycka5579282012-02-08 07:50:04 +00001980 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001981 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001982
Alexander Duyckfe49f042009-06-04 16:00:09 +00001983 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001984 }
1985
Alexander Duyckbd508172010-11-16 19:27:03 -08001986 switch (adapter->hw.mac.type) {
1987 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001988 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001989 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001990 break;
1991 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001992 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001993 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001994 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001995 default:
1996 break;
1997 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001998 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001999
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002000 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002001 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002002 mask &= ~(IXGBE_EIMS_OTHER |
2003 IXGBE_EIMS_MAILBOX |
2004 IXGBE_EIMS_LSC);
2005
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002006 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002007}
2008
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002009enum latency_range {
2010 lowest_latency = 0,
2011 low_latency = 1,
2012 bulk_latency = 2,
2013 latency_invalid = 255
2014};
2015
2016/**
2017 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002018 * @q_vector: structure containing interrupt and ring information
2019 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002020 *
2021 * Stores a new ITR value based on packets and byte
2022 * counts during the last interrupt. The advantage of per interrupt
2023 * computation is faster updates and more accurate ITR for the current
2024 * traffic pattern. Constants in this function were computed
2025 * based on theoretical maximum wire speed and thresholds were set based
2026 * on testing data as well as attempting to minimize response time
2027 * while increasing bulk throughput.
2028 * this functionality is controlled by the InterruptThrottleRate module
2029 * parameter (see ixgbe_param.c)
2030 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002031static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2032 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002033{
Alexander Duyckbd198052011-06-11 01:45:08 +00002034 int bytes = ring_container->total_bytes;
2035 int packets = ring_container->total_packets;
2036 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002037 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002038 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002039
2040 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002041 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002042
2043 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002044 * 0-10MB/s lowest (100000 ints/s)
2045 * 10-20MB/s low (20000 ints/s)
2046 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002047 */
2048 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002049 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002050 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2051
2052 switch (itr_setting) {
2053 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002054 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002055 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002056 break;
2057 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002058 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002059 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002060 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002061 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002062 break;
2063 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002064 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002065 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002066 break;
2067 }
2068
Alexander Duyckbd198052011-06-11 01:45:08 +00002069 /* clear work counters since we have the values we need */
2070 ring_container->total_bytes = 0;
2071 ring_container->total_packets = 0;
2072
2073 /* write updated itr to ring container */
2074 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002075}
2076
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002077/**
2078 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002079 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002080 *
2081 * This function is made to be called by ethtool and by the driver
2082 * when it needs to update EITR registers at runtime. Hardware
2083 * specific quirks/differences are taken care of here.
2084 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002085void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002086{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002087 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002088 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002089 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002090 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002091
Alexander Duyckbd508172010-11-16 19:27:03 -08002092 switch (adapter->hw.mac.type) {
2093 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002094 /* must write high and low 16 bits to reset counter */
2095 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002096 break;
2097 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002098 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002099 /*
2100 * set the WDIS bit to not clear the timer bits and cause an
2101 * immediate assertion of the interrupt
2102 */
2103 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002104 break;
2105 default:
2106 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002107 }
2108 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2109}
2110
Alexander Duyckbd198052011-06-11 01:45:08 +00002111static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002112{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002113 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002114 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002115
Alexander Duyckbd198052011-06-11 01:45:08 +00002116 ixgbe_update_itr(q_vector, &q_vector->tx);
2117 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002118
Alexander Duyck08c88332011-06-11 01:45:03 +00002119 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002120
2121 switch (current_itr) {
2122 /* counts and packets in update_itr are dependent on these numbers */
2123 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002124 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002125 break;
2126 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002127 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002128 break;
2129 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002130 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002131 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002132 default:
2133 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002134 }
2135
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002136 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002137 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002138 new_itr = (10 * new_itr * q_vector->itr) /
2139 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002140
Alexander Duyckbd198052011-06-11 01:45:08 +00002141 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002142 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002143
2144 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002145 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002146}
2147
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002148/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002149 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002150 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002151 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002152static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002153{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002154 struct ixgbe_hw *hw = &adapter->hw;
2155 u32 eicr = adapter->interrupt_event;
2156
Alexander Duyckf0f97782011-04-22 04:08:09 +00002157 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002158 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002159
Alexander Duyckf0f97782011-04-22 04:08:09 +00002160 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2161 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2162 return;
2163
2164 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2165
Joe Perches7ca647b2010-09-07 21:35:40 +00002166 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002167 case IXGBE_DEV_ID_82599_T3_LOM:
2168 /*
2169 * Since the warning interrupt is for both ports
2170 * we don't have to check if:
2171 * - This interrupt wasn't for our port.
2172 * - We may have missed the interrupt so always have to
2173 * check if we got a LSC
2174 */
2175 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2176 !(eicr & IXGBE_EICR_LSC))
2177 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002178
Alexander Duyckf0f97782011-04-22 04:08:09 +00002179 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2180 u32 autoneg;
2181 bool link_up = false;
2182
Joe Perches7ca647b2010-09-07 21:35:40 +00002183 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2184
Alexander Duyckf0f97782011-04-22 04:08:09 +00002185 if (link_up)
2186 return;
2187 }
2188
2189 /* Check if this is not due to overtemp */
2190 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2191 return;
2192
2193 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002194 default:
2195 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2196 return;
2197 break;
2198 }
2199 e_crit(drv,
2200 "Network adapter has been stopped because it has over heated. "
2201 "Restart the computer. If the problem persists, "
2202 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002203
2204 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002205}
2206
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002207static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2208{
2209 struct ixgbe_hw *hw = &adapter->hw;
2210
2211 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2212 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002213 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002214 /* write to clear the interrupt */
2215 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2216 }
2217}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002218
Jacob Keller4f51bf72011-08-20 04:49:45 +00002219static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2220{
2221 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2222 return;
2223
2224 switch (adapter->hw.mac.type) {
2225 case ixgbe_mac_82599EB:
2226 /*
2227 * Need to check link state so complete overtemp check
2228 * on service task
2229 */
2230 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2231 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2232 adapter->interrupt_event = eicr;
2233 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2234 ixgbe_service_event_schedule(adapter);
2235 return;
2236 }
2237 return;
2238 case ixgbe_mac_X540:
2239 if (!(eicr & IXGBE_EICR_TS))
2240 return;
2241 break;
2242 default:
2243 return;
2244 }
2245
2246 e_crit(drv,
2247 "Network adapter has been stopped because it has over heated. "
2248 "Restart the computer. If the problem persists, "
2249 "power off the system and replace the adapter\n");
2250}
2251
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002252static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2253{
2254 struct ixgbe_hw *hw = &adapter->hw;
2255
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002256 if (eicr & IXGBE_EICR_GPI_SDP2) {
2257 /* Clear the interrupt */
2258 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002259 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2260 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2261 ixgbe_service_event_schedule(adapter);
2262 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002263 }
2264
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002265 if (eicr & IXGBE_EICR_GPI_SDP1) {
2266 /* Clear the interrupt */
2267 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002268 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2269 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2270 ixgbe_service_event_schedule(adapter);
2271 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002272 }
2273}
2274
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002275static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2276{
2277 struct ixgbe_hw *hw = &adapter->hw;
2278
2279 adapter->lsc_int++;
2280 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2281 adapter->link_check_timeout = jiffies;
2282 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2283 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002284 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002285 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002286 }
2287}
2288
Alexander Duyckfe49f042009-06-04 16:00:09 +00002289static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2290 u64 qmask)
2291{
2292 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002293 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002294
Alexander Duyckbd508172010-11-16 19:27:03 -08002295 switch (hw->mac.type) {
2296 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002297 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002298 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2299 break;
2300 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002301 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002302 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002303 if (mask)
2304 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002305 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002306 if (mask)
2307 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2308 break;
2309 default:
2310 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002311 }
2312 /* skip the flush */
2313}
2314
2315static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002316 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002317{
2318 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002319 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002320
Alexander Duyckbd508172010-11-16 19:27:03 -08002321 switch (hw->mac.type) {
2322 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002323 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002324 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2325 break;
2326 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002327 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002328 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002329 if (mask)
2330 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002331 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002332 if (mask)
2333 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2334 break;
2335 default:
2336 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002337 }
2338 /* skip the flush */
2339}
2340
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002341/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002342 * ixgbe_irq_enable - Enable default interrupt generation settings
2343 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002345static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2346 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002347{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002348 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002349
Alexander Duyck2c4af692011-07-15 07:29:55 +00002350 /* don't reenable LSC while waiting for link */
2351 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2352 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002353
Alexander Duyck2c4af692011-07-15 07:29:55 +00002354 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002355 switch (adapter->hw.mac.type) {
2356 case ixgbe_mac_82599EB:
2357 mask |= IXGBE_EIMS_GPI_SDP0;
2358 break;
2359 case ixgbe_mac_X540:
2360 mask |= IXGBE_EIMS_TS;
2361 break;
2362 default:
2363 break;
2364 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002365 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2366 mask |= IXGBE_EIMS_GPI_SDP1;
2367 switch (adapter->hw.mac.type) {
2368 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002369 mask |= IXGBE_EIMS_GPI_SDP1;
2370 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002371 case ixgbe_mac_X540:
2372 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002373 mask |= IXGBE_EIMS_MAILBOX;
2374 break;
2375 default:
2376 break;
2377 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002378
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002379 if (adapter->hw.mac.type == ixgbe_mac_X540)
2380 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002381
Alexander Duyck2c4af692011-07-15 07:29:55 +00002382 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2383 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2384 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002385
Alexander Duyck2c4af692011-07-15 07:29:55 +00002386 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2387 if (queues)
2388 ixgbe_irq_enable_queues(adapter, ~0);
2389 if (flush)
2390 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002391}
2392
Alexander Duyck2c4af692011-07-15 07:29:55 +00002393static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002394{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002395 struct ixgbe_adapter *adapter = data;
2396 struct ixgbe_hw *hw = &adapter->hw;
2397 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002398
Alexander Duyck2c4af692011-07-15 07:29:55 +00002399 /*
2400 * Workaround for Silicon errata. Use clear-by-write instead
2401 * of clear-by-read. Reading with EICS will return the
2402 * interrupt causes without clearing, which later be done
2403 * with the write to EICR.
2404 */
2405 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2406 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002407
Alexander Duyck2c4af692011-07-15 07:29:55 +00002408 if (eicr & IXGBE_EICR_LSC)
2409 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002410
Alexander Duyck2c4af692011-07-15 07:29:55 +00002411 if (eicr & IXGBE_EICR_MAILBOX)
2412 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002413
Alexander Duyck2c4af692011-07-15 07:29:55 +00002414 switch (hw->mac.type) {
2415 case ixgbe_mac_82599EB:
2416 case ixgbe_mac_X540:
2417 if (eicr & IXGBE_EICR_ECC)
2418 e_info(link, "Received unrecoverable ECC Err, please "
2419 "reboot\n");
2420 /* Handle Flow Director Full threshold interrupt */
2421 if (eicr & IXGBE_EICR_FLOW_DIR) {
2422 int reinit_count = 0;
2423 int i;
2424 for (i = 0; i < adapter->num_tx_queues; i++) {
2425 struct ixgbe_ring *ring = adapter->tx_ring[i];
2426 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2427 &ring->state))
2428 reinit_count++;
2429 }
2430 if (reinit_count) {
2431 /* no more flow director interrupts until after init */
2432 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2433 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2434 ixgbe_service_event_schedule(adapter);
2435 }
2436 }
2437 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002438 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002439 break;
2440 default:
2441 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002442 }
2443
Alexander Duyck2c4af692011-07-15 07:29:55 +00002444 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002445
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002446 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2447 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002448
Alexander Duyck2c4af692011-07-15 07:29:55 +00002449 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002450 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002451 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002452
Alexander Duyck2c4af692011-07-15 07:29:55 +00002453 return IRQ_HANDLED;
2454}
2455
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002456static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002457{
2458 struct ixgbe_q_vector *q_vector = data;
2459
Auke Kok9a799d72007-09-15 14:07:45 -07002460 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002461
2462 if (q_vector->rx.ring || q_vector->tx.ring)
2463 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002464
2465 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002466}
2467
Auke Kok9a799d72007-09-15 14:07:45 -07002468/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002469 * ixgbe_poll - NAPI Rx polling callback
2470 * @napi: structure for representing this polling device
2471 * @budget: how many packets driver is allowed to clean
2472 *
2473 * This function is used for legacy and MSI, NAPI mode
2474 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002475int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002476{
2477 struct ixgbe_q_vector *q_vector =
2478 container_of(napi, struct ixgbe_q_vector, napi);
2479 struct ixgbe_adapter *adapter = q_vector->adapter;
2480 struct ixgbe_ring *ring;
2481 int per_ring_budget;
2482 bool clean_complete = true;
2483
2484#ifdef CONFIG_IXGBE_DCA
2485 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2486 ixgbe_update_dca(q_vector);
2487#endif
2488
2489 ixgbe_for_each_ring(ring, q_vector->tx)
2490 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2491
2492 /* attempt to distribute budget to each queue fairly, but don't allow
2493 * the budget to go below 1 because we'll exit polling */
2494 if (q_vector->rx.count > 1)
2495 per_ring_budget = max(budget/q_vector->rx.count, 1);
2496 else
2497 per_ring_budget = budget;
2498
2499 ixgbe_for_each_ring(ring, q_vector->rx)
2500 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2501 per_ring_budget);
2502
2503 /* If all work not completed, return budget and keep polling */
2504 if (!clean_complete)
2505 return budget;
2506
2507 /* all work done, exit the polling mode */
2508 napi_complete(napi);
2509 if (adapter->rx_itr_setting & 1)
2510 ixgbe_set_itr(q_vector);
2511 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2512 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2513
2514 return 0;
2515}
2516
2517/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002518 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2519 * @adapter: board private structure
2520 *
2521 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2522 * interrupts from the kernel.
2523 **/
2524static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2525{
2526 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002527 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002528 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002530 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002531 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002532 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002533
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002534 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002535 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002536 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002537 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002538 } else if (q_vector->rx.ring) {
2539 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2540 "%s-%s-%d", netdev->name, "rx", ri++);
2541 } else if (q_vector->tx.ring) {
2542 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2543 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002544 } else {
2545 /* skip this unused q_vector */
2546 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002547 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002548 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2549 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002550 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002551 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002552 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 goto free_queue_irqs;
2554 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002555 /* If Flow Director is enabled, set interrupt affinity */
2556 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2557 /* assign the mask for this irq */
2558 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002559 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002560 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002561 }
2562
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002563 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002564 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002566 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567 goto free_queue_irqs;
2568 }
2569
2570 return 0;
2571
2572free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002573 while (vector) {
2574 vector--;
2575 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2576 NULL);
2577 free_irq(adapter->msix_entries[vector].vector,
2578 adapter->q_vector[vector]);
2579 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002580 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2581 pci_disable_msix(adapter->pdev);
2582 kfree(adapter->msix_entries);
2583 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584 return err;
2585}
2586
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002587/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002588 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002589 * @irq: interrupt number
2590 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002591 **/
2592static irqreturn_t ixgbe_intr(int irq, void *data)
2593{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002594 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002595 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002596 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002597 u32 eicr;
2598
Don Skidmore54037502009-02-21 15:42:56 -08002599 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002600 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002601 * before the read of EICR.
2602 */
2603 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2604
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002605 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002606 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002607 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002608 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002609 /*
2610 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002611 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002612 * have disabled interrupts due to EIAM
2613 * finish the workaround of silicon errata on 82598. Unmask
2614 * the interrupt that we masked before the EICR read.
2615 */
2616 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2617 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002618 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002619 }
Auke Kok9a799d72007-09-15 14:07:45 -07002620
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002621 if (eicr & IXGBE_EICR_LSC)
2622 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002623
Alexander Duyckbd508172010-11-16 19:27:03 -08002624 switch (hw->mac.type) {
2625 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002626 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002627 /* Fall through */
2628 case ixgbe_mac_X540:
2629 if (eicr & IXGBE_EICR_ECC)
2630 e_info(link, "Received unrecoverable ECC err, please "
2631 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002632 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002633 break;
2634 default:
2635 break;
2636 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002637
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002638 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002639 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2640 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002641
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002642 /* would disable interrupts here but EIAM disabled it */
2643 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002644
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002645 /*
2646 * re-enable link(maybe) and non-queue interrupts, no flush.
2647 * ixgbe_poll will re-enable the queue interrupts
2648 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002649 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2650 ixgbe_irq_enable(adapter, false, false);
2651
Auke Kok9a799d72007-09-15 14:07:45 -07002652 return IRQ_HANDLED;
2653}
2654
2655/**
2656 * ixgbe_request_irq - initialize interrupts
2657 * @adapter: board private structure
2658 *
2659 * Attempts to configure interrupts using the best available
2660 * capabilities of the hardware and kernel.
2661 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002662static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002663{
2664 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002666
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002667 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002668 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002669 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002670 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002671 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002672 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002673 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002674 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002675
Alexander Duyckde88eee2012-02-08 07:49:59 +00002676 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002677 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002678
Auke Kok9a799d72007-09-15 14:07:45 -07002679 return err;
2680}
2681
2682static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2683{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002684 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002685
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002686 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002687 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002688 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002689 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002690
2691 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2692 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2693 struct msix_entry *entry = &adapter->msix_entries[vector];
2694
2695 /* free only the irqs that were actually requested */
2696 if (!q_vector->rx.ring && !q_vector->tx.ring)
2697 continue;
2698
2699 /* clear the affinity_mask in the IRQ descriptor */
2700 irq_set_affinity_hint(entry->vector, NULL);
2701
2702 free_irq(entry->vector, q_vector);
2703 }
2704
2705 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002706}
2707
2708/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002709 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2710 * @adapter: board private structure
2711 **/
2712static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2713{
Alexander Duyckbd508172010-11-16 19:27:03 -08002714 switch (adapter->hw.mac.type) {
2715 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002716 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002717 break;
2718 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002719 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002720 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2721 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002722 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002723 break;
2724 default:
2725 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002726 }
2727 IXGBE_WRITE_FLUSH(&adapter->hw);
2728 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002729 int vector;
2730
2731 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2732 synchronize_irq(adapter->msix_entries[vector].vector);
2733
2734 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002735 } else {
2736 synchronize_irq(adapter->pdev->irq);
2737 }
2738}
2739
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002740/**
Auke Kok9a799d72007-09-15 14:07:45 -07002741 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2742 *
2743 **/
2744static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2745{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002746 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002747
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002748 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002749
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002750 ixgbe_set_ivar(adapter, 0, 0, 0);
2751 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002752
Emil Tantilov396e7992010-07-01 20:05:12 +00002753 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002754}
2755
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002756/**
2757 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2758 * @adapter: board private structure
2759 * @ring: structure containing ring specific data
2760 *
2761 * Configure the Tx descriptor ring after a reset.
2762 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002763void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2764 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002765{
2766 struct ixgbe_hw *hw = &adapter->hw;
2767 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002768 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002769 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002770 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002771
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002772 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002773 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002774 IXGBE_WRITE_FLUSH(hw);
2775
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002776 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002777 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002778 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2779 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2780 ring->count * sizeof(union ixgbe_adv_tx_desc));
2781 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2782 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002783 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002784
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002785 /*
2786 * set WTHRESH to encourage burst writeback, it should not be set
2787 * higher than 1 when ITR is 0 as it could cause false TX hangs
2788 *
2789 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2790 * to or less than the number of on chip descriptors, which is
2791 * currently 40.
2792 */
Alexander Duycke954b372012-02-08 07:49:38 +00002793 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002794 txdctl |= (1 << 16); /* WTHRESH = 1 */
2795 else
2796 txdctl |= (8 << 16); /* WTHRESH = 8 */
2797
Alexander Duycke954b372012-02-08 07:49:38 +00002798 /*
2799 * Setting PTHRESH to 32 both improves performance
2800 * and avoids a TX hang with DFP enabled
2801 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002802 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2803 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002804
2805 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002806 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002807 ring->atr_sample_rate = adapter->atr_sample_rate;
2808 ring->atr_count = 0;
2809 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2810 } else {
2811 ring->atr_sample_rate = 0;
2812 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002813
John Fastabendc84d3242010-11-16 19:27:12 -08002814 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2815
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002816 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002817 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2818
2819 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2820 if (hw->mac.type == ixgbe_mac_82598EB &&
2821 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2822 return;
2823
2824 /* poll to verify queue is enabled */
2825 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002826 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002827 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2828 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2829 if (!wait_loop)
2830 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002831}
2832
Alexander Duyck120ff942010-08-19 13:34:50 +00002833static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2834{
2835 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002836 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002837 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002838
2839 if (hw->mac.type == ixgbe_mac_82598EB)
2840 return;
2841
2842 /* disable the arbiter while setting MTQC */
2843 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2844 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2845 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2846
2847 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002848 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2849 mtqc = IXGBE_MTQC_VT_ENA;
2850 if (tcs > 4)
2851 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2852 else if (tcs > 1)
2853 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2854 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2855 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002856 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002857 mtqc |= IXGBE_MTQC_64VF;
2858 } else {
2859 if (tcs > 4)
2860 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2861 else if (tcs > 1)
2862 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2863 else
2864 mtqc = IXGBE_MTQC_64Q_1PB;
2865 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002866
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002867 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002868
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002869 /* Enable Security TX Buffer IFG for multiple pb */
2870 if (tcs) {
2871 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2872 sectx |= IXGBE_SECTX_DCB;
2873 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002874 }
2875
2876 /* re-enable the arbiter */
2877 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2878 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2879}
2880
Auke Kok9a799d72007-09-15 14:07:45 -07002881/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002882 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002883 * @adapter: board private structure
2884 *
2885 * Configure the Tx unit of the MAC after a reset.
2886 **/
2887static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2888{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002889 struct ixgbe_hw *hw = &adapter->hw;
2890 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002891 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002892
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002893 ixgbe_setup_mtqc(adapter);
2894
2895 if (hw->mac.type != ixgbe_mac_82598EB) {
2896 /* DMATXCTL.EN must be before Tx queues are enabled */
2897 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2898 dmatxctl |= IXGBE_DMATXCTL_TE;
2899 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2900 }
2901
Auke Kok9a799d72007-09-15 14:07:45 -07002902 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002903 for (i = 0; i < adapter->num_tx_queues; i++)
2904 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002905}
2906
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002907static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2908 struct ixgbe_ring *ring)
2909{
2910 struct ixgbe_hw *hw = &adapter->hw;
2911 u8 reg_idx = ring->reg_idx;
2912 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2913
2914 srrctl |= IXGBE_SRRCTL_DROP_EN;
2915
2916 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2917}
2918
2919static void ixgbe_disable_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
2931#ifdef CONFIG_IXGBE_DCB
2932void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2933#else
2934static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2935#endif
2936{
2937 int i;
2938 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2939
2940 if (adapter->ixgbe_ieee_pfc)
2941 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2942
2943 /*
2944 * We should set the drop enable bit if:
2945 * SR-IOV is enabled
2946 * or
2947 * Number of Rx queues > 1 and flow control is disabled
2948 *
2949 * This allows us to avoid head of line blocking for security
2950 * and performance reasons.
2951 */
2952 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2953 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2954 for (i = 0; i < adapter->num_rx_queues; i++)
2955 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2956 } else {
2957 for (i = 0; i < adapter->num_rx_queues; i++)
2958 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2959 }
2960}
2961
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002962#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002963
Yi Zoua6616b42009-08-06 13:05:23 +00002964static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002965 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002966{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002967 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002968 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002969 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002970
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002971 if (hw->mac.type == ixgbe_mac_82598EB) {
2972 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2973
2974 /*
2975 * if VMDq is not active we must program one srrctl register
2976 * per RSS queue since we have enabled RDRXCTL.MVMEN
2977 */
2978 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002979 }
2980
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002981 /* configure header buffer length, needed for RSC */
2982 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002983
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002984 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00002985 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002986
2987 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00002988 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002989
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002990 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002991}
2992
Alexander Duyck05abb122010-08-19 13:35:41 +00002993static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002994{
Alexander Duyck05abb122010-08-19 13:35:41 +00002995 struct ixgbe_hw *hw = &adapter->hw;
2996 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002997 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2998 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002999 u32 mrqc = 0, reta = 0;
3000 u32 rxcsum;
3001 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003002 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003003
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003004 /*
3005 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3006 * make full use of any rings they may have. We will use the
3007 * PSRTYPE register to control how many rings we use within the PF.
3008 */
3009 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3010 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003011
Alexander Duyck05abb122010-08-19 13:35:41 +00003012 /* Fill out hash function seeds */
3013 for (i = 0; i < 10; i++)
3014 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003015
Alexander Duyck05abb122010-08-19 13:35:41 +00003016 /* Fill out redirection table */
3017 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003018 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003019 j = 0;
3020 /* reta = 4-byte sliding window of
3021 * 0x00..(indices-1)(indices-1)00..etc. */
3022 reta = (reta << 8) | (j * 0x11);
3023 if ((i & 3) == 3)
3024 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3025 }
3026
3027 /* Disable indicating checksum in descriptor, enables RSS hash */
3028 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3029 rxcsum |= IXGBE_RXCSUM_PCSD;
3030 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3031
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003032 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003033 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003034 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003035 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003036 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003037
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003038 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3039 if (tcs > 4)
3040 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3041 else if (tcs > 1)
3042 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3043 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3044 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3045 else
3046 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3047 } else {
3048 if (tcs > 4)
3049 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3050 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003051 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3052 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003053 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003054 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003055 }
3056
Alexander Duyck05abb122010-08-19 13:35:41 +00003057 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003058 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3059 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3060 IXGBE_MRQC_RSS_FIELD_IPV6 |
3061 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003062
Alexander Duyckef6afc02012-02-08 07:51:53 +00003063 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3064 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3065 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3066 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3067
Alexander Duyck05abb122010-08-19 13:35:41 +00003068 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003069}
3070
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003071/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003072 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3073 * @adapter: address of board private structure
3074 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003075 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003076static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003077 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003078{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003079 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003080 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003081 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003082
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003083 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003084 return;
3085
Alexander Duyck73670962010-08-19 13:38:34 +00003086 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003087 rscctrl |= IXGBE_RSCCTL_RSCEN;
3088 /*
3089 * we must limit the number of descriptors so that the
3090 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003091 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003092 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003093 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003094 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003095}
3096
Alexander Duyck9e10e042010-08-19 13:40:06 +00003097#define IXGBE_MAX_RX_DESC_POLL 10
3098static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3099 struct ixgbe_ring *ring)
3100{
3101 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003102 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3103 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003104 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003105
3106 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3107 if (hw->mac.type == ixgbe_mac_82598EB &&
3108 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3109 return;
3110
3111 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003112 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003113 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3114 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3115
3116 if (!wait_loop) {
3117 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3118 "the polling period\n", reg_idx);
3119 }
3120}
3121
Yi Zou2d39d572011-01-06 14:29:56 +00003122void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3123 struct ixgbe_ring *ring)
3124{
3125 struct ixgbe_hw *hw = &adapter->hw;
3126 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3127 u32 rxdctl;
3128 u8 reg_idx = ring->reg_idx;
3129
3130 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3131 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3132
3133 /* write value back with RXDCTL.ENABLE bit cleared */
3134 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3135
3136 if (hw->mac.type == ixgbe_mac_82598EB &&
3137 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3138 return;
3139
3140 /* the hardware may take up to 100us to really disable the rx queue */
3141 do {
3142 udelay(10);
3143 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3144 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3145
3146 if (!wait_loop) {
3147 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3148 "the polling period\n", reg_idx);
3149 }
3150}
3151
Alexander Duyck84418e32010-08-19 13:40:54 +00003152void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3153 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003154{
3155 struct ixgbe_hw *hw = &adapter->hw;
3156 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003157 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003158 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003159
Alexander Duyck9e10e042010-08-19 13:40:06 +00003160 /* disable queue to avoid issues while updating state */
3161 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003162 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003163
Alexander Duyckacd37172010-08-19 13:36:05 +00003164 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3165 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3166 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3167 ring->count * sizeof(union ixgbe_adv_rx_desc));
3168 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3169 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003170 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003171
3172 ixgbe_configure_srrctl(adapter, ring);
3173 ixgbe_configure_rscctl(adapter, ring);
3174
3175 if (hw->mac.type == ixgbe_mac_82598EB) {
3176 /*
3177 * enable cache line friendly hardware writes:
3178 * PTHRESH=32 descriptors (half the internal cache),
3179 * this also removes ugly rx_no_buffer_count increment
3180 * HTHRESH=4 descriptors (to minimize latency on fetch)
3181 * WTHRESH=8 burst writeback up to two cache lines
3182 */
3183 rxdctl &= ~0x3FFFFF;
3184 rxdctl |= 0x080420;
3185 }
3186
3187 /* enable receive descriptor ring */
3188 rxdctl |= IXGBE_RXDCTL_ENABLE;
3189 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3190
3191 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003192 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003193}
3194
Alexander Duyck48654522010-08-19 13:36:27 +00003195static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3196{
3197 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003198 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003199 int p;
3200
3201 /* PSRTYPE must be initialized in non 82598 adapters */
3202 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003203 IXGBE_PSRTYPE_UDPHDR |
3204 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003205 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003206 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003207
3208 if (hw->mac.type == ixgbe_mac_82598EB)
3209 return;
3210
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003211 if (rss_i > 3)
3212 psrtype |= 2 << 29;
3213 else if (rss_i > 1)
3214 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003215
3216 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003217 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003218 psrtype);
3219}
3220
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003221static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3222{
3223 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003224 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003225 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003226 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003227
3228 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3229 return;
3230
3231 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003232 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3233 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003234 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003235 vmdctl |= IXGBE_VT_CTL_REPLEN;
3236 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003237
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003238 vf_shift = VMDQ_P(0) % 32;
3239 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003240
3241 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003242 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3243 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3244 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3245 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Greg Rose9b735982012-11-08 02:41:35 +00003246 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3247 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003248
3249 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003250 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003251
3252 /*
3253 * Set up VF register offsets for selected VT Mode,
3254 * i.e. 32 or 64 VFs for SR-IOV
3255 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003256 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3257 case IXGBE_82599_VMDQ_8Q_MASK:
3258 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3259 break;
3260 case IXGBE_82599_VMDQ_4Q_MASK:
3261 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3262 break;
3263 default:
3264 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3265 break;
3266 }
3267
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003268 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3269
Alexander Duyck435b19f2012-05-18 06:34:08 +00003270
Greg Rosea985b6c32010-11-18 03:02:52 +00003271 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003272 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003273 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003274 /* For VFs that have spoof checking turned off */
3275 for (i = 0; i < adapter->num_vfs; i++) {
3276 if (!adapter->vfinfo[i].spoofchk_enabled)
3277 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3278 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003279}
3280
Alexander Duyck477de6e2010-08-19 13:38:11 +00003281static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003282{
Auke Kok9a799d72007-09-15 14:07:45 -07003283 struct ixgbe_hw *hw = &adapter->hw;
3284 struct net_device *netdev = adapter->netdev;
3285 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003286 struct ixgbe_ring *rx_ring;
3287 int i;
3288 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003289
Alexander Duyck477de6e2010-08-19 13:38:11 +00003290#ifdef IXGBE_FCOE
3291 /* adjust max frame to be able to do baby jumbo for FCoE */
3292 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3293 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3294 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3295
3296#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003297
3298 /* adjust max frame to be at least the size of a standard frame */
3299 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3300 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3301
Alexander Duyck477de6e2010-08-19 13:38:11 +00003302 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3303 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3304 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3305 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3306
3307 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003308 }
3309
Auke Kok9a799d72007-09-15 14:07:45 -07003310 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003311 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3312 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003313 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3314
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003315 /*
3316 * Setup the HW Rx Head and Tail Descriptor Pointers and
3317 * the Base and Length of the Rx Descriptor Ring
3318 */
Auke Kok9a799d72007-09-15 14:07:45 -07003319 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003320 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003321 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3322 set_ring_rsc_enabled(rx_ring);
3323 else
3324 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003325 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003326}
3327
Alexander Duyck73670962010-08-19 13:38:34 +00003328static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3329{
3330 struct ixgbe_hw *hw = &adapter->hw;
3331 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3332
3333 switch (hw->mac.type) {
3334 case ixgbe_mac_82598EB:
3335 /*
3336 * For VMDq support of different descriptor types or
3337 * buffer sizes through the use of multiple SRRCTL
3338 * registers, RDRXCTL.MVMEN must be set to 1
3339 *
3340 * also, the manual doesn't mention it clearly but DCA hints
3341 * will only use queue 0's tags unless this bit is set. Side
3342 * effects of setting this bit are only that SRRCTL must be
3343 * fully programmed [0..15]
3344 */
3345 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3346 break;
3347 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003348 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003349 /* Disable RSC for ACK packets */
3350 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3351 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3352 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3353 /* hardware requires some bits to be set by default */
3354 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3355 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3356 break;
3357 default:
3358 /* We should do nothing since we don't know this hardware */
3359 return;
3360 }
3361
3362 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3363}
3364
Alexander Duyck477de6e2010-08-19 13:38:11 +00003365/**
3366 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3367 * @adapter: board private structure
3368 *
3369 * Configure the Rx unit of the MAC after a reset.
3370 **/
3371static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3372{
3373 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003374 int i;
3375 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003376
3377 /* disable receives while setting up the descriptors */
3378 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3379 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3380
3381 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003382 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003383
Alexander Duyck9e10e042010-08-19 13:40:06 +00003384 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003385 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003386
Alexander Duyck477de6e2010-08-19 13:38:11 +00003387 /* set_rx_buffer_len must be called before ring initialization */
3388 ixgbe_set_rx_buffer_len(adapter);
3389
3390 /*
3391 * Setup the HW Rx Head and Tail Descriptor Pointers and
3392 * the Base and Length of the Rx Descriptor Ring
3393 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003394 for (i = 0; i < adapter->num_rx_queues; i++)
3395 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003396
Alexander Duyck9e10e042010-08-19 13:40:06 +00003397 /* disable drop enable for 82598 parts */
3398 if (hw->mac.type == ixgbe_mac_82598EB)
3399 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3400
3401 /* enable all receives */
3402 rxctrl |= IXGBE_RXCTRL_RXEN;
3403 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003404}
3405
Jiri Pirko8e586132011-12-08 19:52:37 -05003406static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003407{
3408 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003409 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003410
3411 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003412 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003413 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003414
3415 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003416}
3417
Jiri Pirko8e586132011-12-08 19:52:37 -05003418static int ixgbe_vlan_rx_kill_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
Auke Kok9a799d72007-09-15 14:07:45 -07003423 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003424 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003425 clear_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
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003430/**
3431 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3432 * @adapter: driver data
3433 */
3434static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3435{
3436 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003437 u32 vlnctrl;
3438
3439 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3440 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3441 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3442}
3443
3444/**
3445 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3446 * @adapter: driver data
3447 */
3448static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3449{
3450 struct ixgbe_hw *hw = &adapter->hw;
3451 u32 vlnctrl;
3452
3453 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3454 vlnctrl |= IXGBE_VLNCTRL_VFE;
3455 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3456 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3457}
3458
3459/**
3460 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3461 * @adapter: driver data
3462 */
3463static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3464{
3465 struct ixgbe_hw *hw = &adapter->hw;
3466 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003467 int i, j;
3468
3469 switch (hw->mac.type) {
3470 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003471 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3472 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003473 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3474 break;
3475 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003476 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003477 for (i = 0; i < adapter->num_rx_queues; i++) {
3478 j = adapter->rx_ring[i]->reg_idx;
3479 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3480 vlnctrl &= ~IXGBE_RXDCTL_VME;
3481 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3482 }
3483 break;
3484 default:
3485 break;
3486 }
3487}
3488
3489/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003490 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003491 * @adapter: driver data
3492 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003493static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003494{
3495 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003496 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003497 int i, j;
3498
3499 switch (hw->mac.type) {
3500 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003501 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3502 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003503 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3504 break;
3505 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003506 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003507 for (i = 0; i < adapter->num_rx_queues; i++) {
3508 j = adapter->rx_ring[i]->reg_idx;
3509 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3510 vlnctrl |= IXGBE_RXDCTL_VME;
3511 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3512 }
3513 break;
3514 default:
3515 break;
3516 }
3517}
3518
Auke Kok9a799d72007-09-15 14:07:45 -07003519static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3520{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003521 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003522
Jesse Grossf62bbb52010-10-20 13:56:10 +00003523 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3524
3525 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3526 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003527}
3528
3529/**
Alexander Duyck28500622010-06-15 09:25:48 +00003530 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3531 * @netdev: network interface device structure
3532 *
3533 * Writes unicast address list to the RAR table.
3534 * Returns: -ENOMEM on failure/insufficient address space
3535 * 0 on no addresses written
3536 * X on writing X addresses to the RAR table
3537 **/
3538static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3539{
3540 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3541 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003542 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003543 int count = 0;
3544
John Fastabend95447462012-05-31 12:42:26 +00003545 /* In SR-IOV mode significantly less RAR entries are available */
3546 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3547 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3548
Alexander Duyck28500622010-06-15 09:25:48 +00003549 /* return ENOMEM indicating insufficient memory for addresses */
3550 if (netdev_uc_count(netdev) > rar_entries)
3551 return -ENOMEM;
3552
John Fastabend95447462012-05-31 12:42:26 +00003553 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003554 struct netdev_hw_addr *ha;
3555 /* return error if we do not support writing to RAR table */
3556 if (!hw->mac.ops.set_rar)
3557 return -ENOMEM;
3558
3559 netdev_for_each_uc_addr(ha, netdev) {
3560 if (!rar_entries)
3561 break;
3562 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003563 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003564 count++;
3565 }
3566 }
3567 /* write the addresses in reverse order to avoid write combining */
3568 for (; rar_entries > 0 ; rar_entries--)
3569 hw->mac.ops.clear_rar(hw, rar_entries);
3570
3571 return count;
3572}
3573
3574/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003575 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003576 * @netdev: network interface device structure
3577 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003578 * The set_rx_method entry point is called whenever the unicast/multicast
3579 * address list or the network interface flags are updated. This routine is
3580 * responsible for configuring the hardware for proper unicast, multicast and
3581 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003582 **/
Greg Rose7f870472010-01-09 02:25:29 +00003583void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003584{
3585 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3586 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003587 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3588 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003589
3590 /* Check for Promiscuous and All Multicast modes */
3591
3592 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3593
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003594 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003595 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003596 fctrl |= IXGBE_FCTRL_BAM;
3597 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3598 fctrl |= IXGBE_FCTRL_PMCF;
3599
Alexander Duyck28500622010-06-15 09:25:48 +00003600 /* clear the bits we are changing the status of */
3601 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3602
Auke Kok9a799d72007-09-15 14:07:45 -07003603 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003604 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003605 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003606 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003607 /* don't hardware filter vlans in promisc mode */
3608 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003609 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003610 if (netdev->flags & IFF_ALLMULTI) {
3611 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003612 vmolr |= IXGBE_VMOLR_MPE;
3613 } else {
3614 /*
3615 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003616 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003617 * that we can at least receive multicast traffic
3618 */
3619 hw->mac.ops.update_mc_addr_list(hw, netdev);
3620 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003621 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003622 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003623 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003624 }
3625
3626 /*
3627 * Write addresses to available RAR registers, if there is not
3628 * sufficient space to store all the addresses then enable
3629 * unicast promiscuous mode
3630 */
3631 count = ixgbe_write_uc_addr_list(netdev);
3632 if (count < 0) {
3633 fctrl |= IXGBE_FCTRL_UPE;
3634 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003635 }
3636
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003637 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003638 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003639
3640 if (hw->mac.type != ixgbe_mac_82598EB) {
3641 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003642 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3643 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003644 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003645 }
3646
Ben Greear3f2d1c02012-03-08 08:28:41 +00003647 /* This is useful for sniffing bad packets. */
3648 if (adapter->netdev->features & NETIF_F_RXALL) {
3649 /* UPE and MPE will be handled by normal PROMISC logic
3650 * in e1000e_set_rx_mode */
3651 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3652 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3653 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3654
3655 fctrl &= ~(IXGBE_FCTRL_DPF);
3656 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3657 }
3658
Auke Kok9a799d72007-09-15 14:07:45 -07003659 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003660
3661 if (netdev->features & NETIF_F_HW_VLAN_RX)
3662 ixgbe_vlan_strip_enable(adapter);
3663 else
3664 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003665}
3666
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003667static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3668{
3669 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003670
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003671 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3672 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003673}
3674
3675static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3676{
3677 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003678
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003679 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3680 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003681}
3682
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003683#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003684/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003685 * ixgbe_configure_dcb - Configure DCB hardware
3686 * @adapter: ixgbe adapter struct
3687 *
3688 * This is called by the driver on open to configure the DCB hardware.
3689 * This is also called by the gennetlink interface when reconfiguring
3690 * the DCB state.
3691 */
3692static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3693{
3694 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003695 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003696
Alexander Duyck67ebd792010-08-19 13:34:04 +00003697 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3698 if (hw->mac.type == ixgbe_mac_82598EB)
3699 netif_set_gso_max_size(adapter->netdev, 65536);
3700 return;
3701 }
3702
3703 if (hw->mac.type == ixgbe_mac_82598EB)
3704 netif_set_gso_max_size(adapter->netdev, 32768);
3705
John Fastabendb1208182011-10-15 05:00:10 +00003706#ifdef IXGBE_FCOE
3707 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3708 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3709#endif
3710
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003711 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003712 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003713 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3714 DCB_TX_CONFIG);
3715 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3716 DCB_RX_CONFIG);
3717 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003718 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3719 ixgbe_dcb_hw_ets(&adapter->hw,
3720 adapter->ixgbe_ieee_ets,
3721 max_frame);
3722 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3723 adapter->ixgbe_ieee_pfc->pfc_en,
3724 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003725 }
John Fastabend8187cd42011-02-23 05:58:08 +00003726
3727 /* Enable RSS Hash per TC */
3728 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003729 u32 msb = 0;
3730 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003731
Alexander Duyckd411a932012-06-30 00:14:01 +00003732 while (rss_i) {
3733 msb++;
3734 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003735 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003736
Alexander Duyck4ae63732012-06-22 06:46:33 +00003737 /* write msb to all 8 TCs in one write */
3738 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003739 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003740}
John Fastabend9da712d2011-08-23 03:14:22 +00003741#endif
3742
3743/* Additional bittime to account for IXGBE framing */
3744#define IXGBE_ETH_FRAMING 20
3745
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003746/**
John Fastabend9da712d2011-08-23 03:14:22 +00003747 * ixgbe_hpbthresh - calculate high water mark for flow control
3748 *
3749 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003750 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003751 */
3752static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3753{
3754 struct ixgbe_hw *hw = &adapter->hw;
3755 struct net_device *dev = adapter->netdev;
3756 int link, tc, kb, marker;
3757 u32 dv_id, rx_pba;
3758
3759 /* Calculate max LAN frame size */
3760 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3761
3762#ifdef IXGBE_FCOE
3763 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003764 if ((dev->features & NETIF_F_FCOE_MTU) &&
3765 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3766 (pb == ixgbe_fcoe_get_tc(adapter)))
3767 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003768
3769#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003770 /* Calculate delay value for device */
3771 switch (hw->mac.type) {
3772 case ixgbe_mac_X540:
3773 dv_id = IXGBE_DV_X540(link, tc);
3774 break;
3775 default:
3776 dv_id = IXGBE_DV(link, tc);
3777 break;
3778 }
3779
3780 /* Loopback switch introduces additional latency */
3781 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3782 dv_id += IXGBE_B2BT(tc);
3783
3784 /* Delay value is calculated in bit times convert to KB */
3785 kb = IXGBE_BT2KB(dv_id);
3786 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3787
3788 marker = rx_pba - kb;
3789
3790 /* It is possible that the packet buffer is not large enough
3791 * to provide required headroom. In this case throw an error
3792 * to user and a do the best we can.
3793 */
3794 if (marker < 0) {
3795 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3796 "headroom to support flow control."
3797 "Decrease MTU or number of traffic classes\n", pb);
3798 marker = tc + 1;
3799 }
3800
3801 return marker;
3802}
3803
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003804/**
John Fastabend9da712d2011-08-23 03:14:22 +00003805 * ixgbe_lpbthresh - calculate low water mark for for flow control
3806 *
3807 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003808 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003809 */
3810static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3811{
3812 struct ixgbe_hw *hw = &adapter->hw;
3813 struct net_device *dev = adapter->netdev;
3814 int tc;
3815 u32 dv_id;
3816
3817 /* Calculate max LAN frame size */
3818 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3819
3820 /* Calculate delay value for device */
3821 switch (hw->mac.type) {
3822 case ixgbe_mac_X540:
3823 dv_id = IXGBE_LOW_DV_X540(tc);
3824 break;
3825 default:
3826 dv_id = IXGBE_LOW_DV(tc);
3827 break;
3828 }
3829
3830 /* Delay value is calculated in bit times convert to KB */
3831 return IXGBE_BT2KB(dv_id);
3832}
3833
3834/*
3835 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3836 */
3837static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3838{
3839 struct ixgbe_hw *hw = &adapter->hw;
3840 int num_tc = netdev_get_num_tc(adapter->netdev);
3841 int i;
3842
3843 if (!num_tc)
3844 num_tc = 1;
3845
3846 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3847
3848 for (i = 0; i < num_tc; i++) {
3849 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3850
3851 /* Low water marks must not be larger than high water marks */
3852 if (hw->fc.low_water > hw->fc.high_water[i])
3853 hw->fc.low_water = 0;
3854 }
3855}
John Fastabend80605c652011-05-02 12:34:10 +00003856
3857static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3858{
John Fastabend80605c652011-05-02 12:34:10 +00003859 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003860 int hdrm;
3861 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003862
3863 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3864 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003865 hdrm = 32 << adapter->fdir_pballoc;
3866 else
3867 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003868
Alexander Duyckf7e10272011-07-21 00:40:35 +00003869 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003870 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003871}
3872
Alexander Duycke4911d52011-05-11 07:18:52 +00003873static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3874{
3875 struct ixgbe_hw *hw = &adapter->hw;
3876 struct hlist_node *node, *node2;
3877 struct ixgbe_fdir_filter *filter;
3878
3879 spin_lock(&adapter->fdir_perfect_lock);
3880
3881 if (!hlist_empty(&adapter->fdir_filter_list))
3882 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3883
3884 hlist_for_each_entry_safe(filter, node, node2,
3885 &adapter->fdir_filter_list, fdir_node) {
3886 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003887 &filter->filter,
3888 filter->sw_idx,
3889 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3890 IXGBE_FDIR_DROP_QUEUE :
3891 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003892 }
3893
3894 spin_unlock(&adapter->fdir_perfect_lock);
3895}
3896
Auke Kok9a799d72007-09-15 14:07:45 -07003897static void ixgbe_configure(struct ixgbe_adapter *adapter)
3898{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003899 struct ixgbe_hw *hw = &adapter->hw;
3900
John Fastabend80605c652011-05-02 12:34:10 +00003901 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003902#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003903 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003904#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00003905 /*
3906 * We must restore virtualization before VLANs or else
3907 * the VLVF registers will not be populated
3908 */
3909 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003910
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003911 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003912 ixgbe_restore_vlan(adapter);
3913
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003914 switch (hw->mac.type) {
3915 case ixgbe_mac_82599EB:
3916 case ixgbe_mac_X540:
3917 hw->mac.ops.disable_rx_buff(hw);
3918 break;
3919 default:
3920 break;
3921 }
3922
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003923 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003924 ixgbe_init_fdir_signature_82599(&adapter->hw,
3925 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003926 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3927 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3928 adapter->fdir_pballoc);
3929 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003930 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003931
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003932 switch (hw->mac.type) {
3933 case ixgbe_mac_82599EB:
3934 case ixgbe_mac_X540:
3935 hw->mac.ops.enable_rx_buff(hw);
3936 break;
3937 default:
3938 break;
3939 }
3940
Alexander Duyck7c8ae652012-05-05 05:32:47 +00003941#ifdef IXGBE_FCOE
3942 /* configure FCoE L2 filters, redirection table, and Rx control */
3943 ixgbe_configure_fcoe(adapter);
3944
3945#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07003946 ixgbe_configure_tx(adapter);
3947 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003948}
3949
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003950static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3951{
3952 switch (hw->phy.type) {
3953 case ixgbe_phy_sfp_avago:
3954 case ixgbe_phy_sfp_ftl:
3955 case ixgbe_phy_sfp_intel:
3956 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003957 case ixgbe_phy_sfp_passive_tyco:
3958 case ixgbe_phy_sfp_passive_unknown:
3959 case ixgbe_phy_sfp_active_unknown:
3960 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003961 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003962 case ixgbe_phy_nl:
3963 if (hw->mac.type == ixgbe_mac_82598EB)
3964 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003965 default:
3966 return false;
3967 }
3968}
3969
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003970/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003971 * ixgbe_sfp_link_config - set up SFP+ link
3972 * @adapter: pointer to private adapter struct
3973 **/
3974static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3975{
Alexander Duyck70864002011-04-27 09:13:56 +00003976 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003977 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003978 * is that an SFP was inserted/removed after the reset
3979 * but before SFP detection was enabled. As such the best
3980 * solution is to just start searching as soon as we start
3981 */
3982 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3983 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003984
Alexander Duyck70864002011-04-27 09:13:56 +00003985 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003986}
3987
3988/**
3989 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003990 * @hw: pointer to private hardware struct
3991 *
3992 * Returns 0 on success, negative on failure
3993 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003994static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003995{
3996 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003997 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003998 u32 ret = IXGBE_ERR_LINK_SETUP;
3999
4000 if (hw->mac.ops.check_link)
4001 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
4002
4003 if (ret)
4004 goto link_cfg_out;
4005
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00004006 autoneg = hw->phy.autoneg_advertised;
4007 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00004008 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
4009 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004010 if (ret)
4011 goto link_cfg_out;
4012
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004013 if (hw->mac.ops.setup_link)
4014 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004015link_cfg_out:
4016 return ret;
4017}
4018
Alexander Duycka34bcff2010-08-19 13:39:20 +00004019static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004020{
Auke Kok9a799d72007-09-15 14:07:45 -07004021 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004022 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004023
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004024 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004025 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4026 IXGBE_GPIE_OCD;
4027 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004028 /*
4029 * use EIAM to auto-mask when MSI-X interrupt is asserted
4030 * this saves a register write for every interrupt
4031 */
4032 switch (hw->mac.type) {
4033 case ixgbe_mac_82598EB:
4034 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4035 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004036 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004037 case ixgbe_mac_X540:
4038 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004039 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4040 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4041 break;
4042 }
4043 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004044 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4045 * specifically only auto mask tx and rx interrupts */
4046 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004047 }
4048
Alexander Duycka34bcff2010-08-19 13:39:20 +00004049 /* XXX: to interrupt immediately for EICS writes, enable this */
4050 /* gpie |= IXGBE_GPIE_EIMEN; */
4051
4052 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4053 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004054
4055 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4056 case IXGBE_82599_VMDQ_8Q_MASK:
4057 gpie |= IXGBE_GPIE_VTMODE_16;
4058 break;
4059 case IXGBE_82599_VMDQ_4Q_MASK:
4060 gpie |= IXGBE_GPIE_VTMODE_32;
4061 break;
4062 default:
4063 gpie |= IXGBE_GPIE_VTMODE_64;
4064 break;
4065 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004066 }
4067
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004068 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004069 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4070 switch (adapter->hw.mac.type) {
4071 case ixgbe_mac_82599EB:
4072 gpie |= IXGBE_SDP0_GPIEN;
4073 break;
4074 case ixgbe_mac_X540:
4075 gpie |= IXGBE_EIMS_TS;
4076 break;
4077 default:
4078 break;
4079 }
4080 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004081
Alexander Duycka34bcff2010-08-19 13:39:20 +00004082 /* Enable fan failure interrupt */
4083 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004084 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004085
Don Skidmore2698b202011-04-13 07:01:52 +00004086 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004087 gpie |= IXGBE_SDP1_GPIEN;
4088 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004089 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004090
4091 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4092}
4093
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004094static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004095{
4096 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004097 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004098 u32 ctrl_ext;
4099
4100 ixgbe_get_hw_control(adapter);
4101 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004102
Auke Kok9a799d72007-09-15 14:07:45 -07004103 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4104 ixgbe_configure_msix(adapter);
4105 else
4106 ixgbe_configure_msi_and_legacy(adapter);
4107
Emil Tantilovec74a472012-09-20 03:33:56 +00004108 /* enable the optics for 82599 SFP+ fiber */
4109 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004110 hw->mac.ops.enable_tx_laser(hw);
4111
Auke Kok9a799d72007-09-15 14:07:45 -07004112 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004113 ixgbe_napi_enable_all(adapter);
4114
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004115 if (ixgbe_is_sfp(hw)) {
4116 ixgbe_sfp_link_config(adapter);
4117 } else {
4118 err = ixgbe_non_sfp_link_config(hw);
4119 if (err)
4120 e_err(probe, "link_config FAILED %d\n", err);
4121 }
4122
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004123 /* clear any pending interrupts, may auto mask */
4124 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004125 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004126
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004127 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004128 * If this adapter has a fan, check to see if we had a failure
4129 * before we enabled the interrupt.
4130 */
4131 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4132 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4133 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004134 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004135 }
4136
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004137 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004138 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004139
Auke Kok9a799d72007-09-15 14:07:45 -07004140 /* bring the link up in the watchdog, this could race with our first
4141 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004142 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4143 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004144 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004145
4146 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4147 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4148 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4149 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004150}
4151
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004152void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4153{
4154 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004155 /* put off any impending NetWatchDogTimeout */
4156 adapter->netdev->trans_start = jiffies;
4157
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004158 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004159 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004160 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004161 /*
4162 * If SR-IOV enabled then wait a bit before bringing the adapter
4163 * back up to give the VFs time to respond to the reset. The
4164 * two second wait is based upon the watchdog timer cycle in
4165 * the VF driver.
4166 */
4167 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4168 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004169 ixgbe_up(adapter);
4170 clear_bit(__IXGBE_RESETTING, &adapter->state);
4171}
4172
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004173void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004174{
4175 /* hardware has been reset, we need to reload some things */
4176 ixgbe_configure(adapter);
4177
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004178 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004179}
4180
4181void ixgbe_reset(struct ixgbe_adapter *adapter)
4182{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004183 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004184 int err;
4185
Alexander Duyck70864002011-04-27 09:13:56 +00004186 /* lock SFP init bit to prevent race conditions with the watchdog */
4187 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4188 usleep_range(1000, 2000);
4189
4190 /* clear all SFP and link config related flags while holding SFP_INIT */
4191 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4192 IXGBE_FLAG2_SFP_NEEDS_RESET);
4193 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4194
Don Skidmore8ca783a2009-05-26 20:40:47 -07004195 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004196 switch (err) {
4197 case 0:
4198 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004199 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004200 break;
4201 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004202 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004203 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004204 case IXGBE_ERR_EEPROM_VERSION:
4205 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004206 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004207 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004208 "your hardware. If you are experiencing problems "
4209 "please contact your Intel or hardware "
4210 "representative who provided you with this "
4211 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004212 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004213 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004214 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004215 }
Auke Kok9a799d72007-09-15 14:07:45 -07004216
Alexander Duyck70864002011-04-27 09:13:56 +00004217 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4218
Auke Kok9a799d72007-09-15 14:07:45 -07004219 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004220 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004221
4222 /* update SAN MAC vmdq pool selection */
4223 if (hw->mac.san_mac_rar_index)
4224 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004225
Jacob Keller1a71ab22012-08-25 03:54:19 +00004226 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4227 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004228}
4229
Auke Kok9a799d72007-09-15 14:07:45 -07004230/**
4231 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004232 * @rx_ring: ring to free buffers from
4233 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004234static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004235{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004236 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004237 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004238 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004239
Alexander Duyck84418e32010-08-19 13:40:54 +00004240 /* ring already cleared, nothing to do */
4241 if (!rx_ring->rx_buffer_info)
4242 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004243
Alexander Duyck84418e32010-08-19 13:40:54 +00004244 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004245 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004246 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004247
Alexander Duyckf8003262012-03-03 02:35:52 +00004248 rx_buffer = &rx_ring->rx_buffer_info[i];
4249 if (rx_buffer->skb) {
4250 struct sk_buff *skb = rx_buffer->skb;
4251 if (IXGBE_CB(skb)->page_released) {
4252 dma_unmap_page(dev,
4253 IXGBE_CB(skb)->dma,
4254 ixgbe_rx_bufsz(rx_ring),
4255 DMA_FROM_DEVICE);
4256 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004257 }
4258 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004259 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004260 rx_buffer->skb = NULL;
4261 if (rx_buffer->dma)
4262 dma_unmap_page(dev, rx_buffer->dma,
4263 ixgbe_rx_pg_size(rx_ring),
4264 DMA_FROM_DEVICE);
4265 rx_buffer->dma = 0;
4266 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004267 __free_pages(rx_buffer->page,
4268 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004269 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004270 }
4271
4272 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4273 memset(rx_ring->rx_buffer_info, 0, size);
4274
4275 /* Zero out the descriptor ring */
4276 memset(rx_ring->desc, 0, rx_ring->size);
4277
Alexander Duyckf8003262012-03-03 02:35:52 +00004278 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004279 rx_ring->next_to_clean = 0;
4280 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004281}
4282
4283/**
4284 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004285 * @tx_ring: ring to be cleaned
4286 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004287static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004288{
4289 struct ixgbe_tx_buffer *tx_buffer_info;
4290 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004291 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004292
Alexander Duyck84418e32010-08-19 13:40:54 +00004293 /* ring already cleared, nothing to do */
4294 if (!tx_ring->tx_buffer_info)
4295 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004296
Alexander Duyck84418e32010-08-19 13:40:54 +00004297 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004298 for (i = 0; i < tx_ring->count; i++) {
4299 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004300 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004301 }
4302
John Fastabenddad8a3b2012-04-23 12:22:39 +00004303 netdev_tx_reset_queue(txring_txq(tx_ring));
4304
Auke Kok9a799d72007-09-15 14:07:45 -07004305 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4306 memset(tx_ring->tx_buffer_info, 0, size);
4307
4308 /* Zero out the descriptor ring */
4309 memset(tx_ring->desc, 0, tx_ring->size);
4310
4311 tx_ring->next_to_use = 0;
4312 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004313}
4314
4315/**
Auke Kok9a799d72007-09-15 14:07:45 -07004316 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4317 * @adapter: board private structure
4318 **/
4319static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4320{
4321 int i;
4322
4323 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004324 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004325}
4326
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004327/**
4328 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4329 * @adapter: board private structure
4330 **/
4331static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4332{
4333 int i;
4334
4335 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004336 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004337}
4338
Alexander Duycke4911d52011-05-11 07:18:52 +00004339static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4340{
4341 struct hlist_node *node, *node2;
4342 struct ixgbe_fdir_filter *filter;
4343
4344 spin_lock(&adapter->fdir_perfect_lock);
4345
4346 hlist_for_each_entry_safe(filter, node, node2,
4347 &adapter->fdir_filter_list, fdir_node) {
4348 hlist_del(&filter->fdir_node);
4349 kfree(filter);
4350 }
4351 adapter->fdir_filter_count = 0;
4352
4353 spin_unlock(&adapter->fdir_perfect_lock);
4354}
4355
Auke Kok9a799d72007-09-15 14:07:45 -07004356void ixgbe_down(struct ixgbe_adapter *adapter)
4357{
4358 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004359 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004360 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004361 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004362
4363 /* signal that we are down to the interrupt handler */
4364 set_bit(__IXGBE_DOWN, &adapter->state);
4365
4366 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004367 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4368 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004369
Yi Zou2d39d572011-01-06 14:29:56 +00004370 /* disable all enabled rx queues */
4371 for (i = 0; i < adapter->num_rx_queues; i++)
4372 /* this call also flushes the previous write */
4373 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4374
Don Skidmore032b4322011-03-18 09:32:53 +00004375 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004376
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004377 netif_tx_stop_all_queues(netdev);
4378
Alexander Duyck70864002011-04-27 09:13:56 +00004379 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004380 netif_carrier_off(netdev);
4381 netif_tx_disable(netdev);
4382
4383 ixgbe_irq_disable(adapter);
4384
4385 ixgbe_napi_disable_all(adapter);
4386
Alexander Duyckd034acf2011-04-27 09:25:34 +00004387 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4388 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004389 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4390
4391 del_timer_sync(&adapter->service_timer);
4392
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004393 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004394 /* Clear EITR Select mapping */
4395 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4396
4397 /* Mark all the VFs as inactive */
4398 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004399 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004400
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004401 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004402 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004403
Auke Kok9a799d72007-09-15 14:07:45 -07004404 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004405 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004406 }
4407
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004408 /* disable transmits in the hardware now that interrupts are off */
4409 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004410 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004411 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004412 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004413
4414 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004415 switch (hw->mac.type) {
4416 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004417 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004418 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004419 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4420 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004421 break;
4422 default:
4423 break;
4424 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004425
Paul Larson6f4a0e42008-06-24 17:00:56 -07004426 if (!pci_channel_offline(adapter->pdev))
4427 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004428
Emil Tantilovec74a472012-09-20 03:33:56 +00004429 /* power down the optics for 82599 SFP+ fiber */
4430 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004431 hw->mac.ops.disable_tx_laser(hw);
4432
Auke Kok9a799d72007-09-15 14:07:45 -07004433 ixgbe_clean_all_tx_rings(adapter);
4434 ixgbe_clean_all_rx_rings(adapter);
4435
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004436#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004437 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004438 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004439#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004440}
4441
Auke Kok9a799d72007-09-15 14:07:45 -07004442/**
Auke Kok9a799d72007-09-15 14:07:45 -07004443 * ixgbe_tx_timeout - Respond to a Tx Hang
4444 * @netdev: network interface device structure
4445 **/
4446static void ixgbe_tx_timeout(struct net_device *netdev)
4447{
4448 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4449
4450 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004451 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004452}
4453
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004454/**
Auke Kok9a799d72007-09-15 14:07:45 -07004455 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4456 * @adapter: board private structure to initialize
4457 *
4458 * ixgbe_sw_init initializes the Adapter private data structure.
4459 * Fields are initialized based on PCI device information and
4460 * OS network device settings (MTU size).
4461 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05004462static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004463{
4464 struct ixgbe_hw *hw = &adapter->hw;
4465 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004466 unsigned int rss;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004467 u32 fwsm;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004468#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004469 int j;
4470 struct tc_configuration *tc;
4471#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004472
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004473 /* PCI config space info */
4474
4475 hw->vendor_id = pdev->vendor;
4476 hw->device_id = pdev->device;
4477 hw->revision_id = pdev->revision;
4478 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4479 hw->subsystem_device_id = pdev->subsystem_device;
4480
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004481 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004482 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004483 adapter->ring_feature[RING_F_RSS].limit = rss;
Alexander Duyckbd508172010-11-16 19:27:03 -08004484 switch (hw->mac.type) {
4485 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004486 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4487 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004488 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004489 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004490 case ixgbe_mac_X540:
Jacob Kellercb6d0f52012-12-04 06:03:14 +00004491 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
4492 if (fwsm & IXGBE_FWSM_TS_ENABLED)
4493 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Jacob Keller4f51bf72011-08-20 04:49:45 +00004494 case ixgbe_mac_82599EB:
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004495 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004496 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4497 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004498 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4499 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004500 /* Flow Director hash filters enabled */
Alexander Duyck45b9f502011-01-06 14:29:59 +00004501 adapter->atr_sample_rate = 20;
Alexander Duyckc0876632012-05-10 00:01:46 +00004502 adapter->ring_feature[RING_F_FDIR].limit =
Joe Perchese8e9f692010-09-07 21:34:53 +00004503 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004504 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004505#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004506 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4507 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
Yi Zou61a0f422009-12-03 11:32:22 +00004508#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004509 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004510 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004511#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004512#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004513 break;
4514 default:
4515 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004516 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004517
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004518#ifdef IXGBE_FCOE
4519 /* FCoE support exists, always init the FCoE lock */
4520 spin_lock_init(&adapter->fcoe.lock);
4521
4522#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004523 /* n-tuple support exists, always init our spinlock */
4524 spin_lock_init(&adapter->fdir_perfect_lock);
4525
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004526#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004527 switch (hw->mac.type) {
4528 case ixgbe_mac_X540:
4529 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4530 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4531 break;
4532 default:
4533 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4534 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4535 break;
4536 }
4537
Alexander Duyck2f90b862008-11-20 20:52:10 -08004538 /* Configure DCB traffic classes */
4539 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4540 tc = &adapter->dcb_cfg.tc_config[j];
4541 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4542 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4543 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4544 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4545 tc->dcb_pfc = pfc_disabled;
4546 }
John Fastabend4de2a022011-09-27 03:52:01 +00004547
4548 /* Initialize default user to priority mapping, UPx->TC0 */
4549 tc = &adapter->dcb_cfg.tc_config[0];
4550 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4551 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4552
Alexander Duyck2f90b862008-11-20 20:52:10 -08004553 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4554 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004555 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004556 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004557 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004558 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4559 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004560
4561#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004562
4563 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004564 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004565 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004566 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004567 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4568 hw->fc.send_xon = true;
Jacob Kellerdb2adc22012-10-24 07:26:02 +00004569 hw->fc.disable_fc_autoneg =
4570 (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
Auke Kok9a799d72007-09-15 14:07:45 -07004571
Alexander Duyck99d74482012-05-09 08:09:25 +00004572#ifdef CONFIG_PCI_IOV
4573 /* assign number of SR-IOV VFs */
4574 if (hw->mac.type != ixgbe_mac_82598EB)
4575 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4576
4577#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004578 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004579 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004580 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004581
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004582 /* set default ring sizes */
4583 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4584 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4585
Alexander Duyckbd198052011-06-11 01:45:08 +00004586 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004587 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004588
Auke Kok9a799d72007-09-15 14:07:45 -07004589 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004590 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004591 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004592 return -EIO;
4593 }
4594
Auke Kok9a799d72007-09-15 14:07:45 -07004595 set_bit(__IXGBE_DOWN, &adapter->state);
4596
4597 return 0;
4598}
4599
4600/**
4601 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004602 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004603 *
4604 * Return 0 on success, negative on failure
4605 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004606int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004607{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004608 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004609 int orig_node = dev_to_node(dev);
4610 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004611 int size;
4612
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004613 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004614
4615 if (tx_ring->q_vector)
4616 numa_node = tx_ring->q_vector->numa_node;
4617
4618 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004619 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004620 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004621 if (!tx_ring->tx_buffer_info)
4622 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004623
4624 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004625 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004626 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004627
Alexander Duyckde88eee2012-02-08 07:49:59 +00004628 set_dev_node(dev, numa_node);
4629 tx_ring->desc = dma_alloc_coherent(dev,
4630 tx_ring->size,
4631 &tx_ring->dma,
4632 GFP_KERNEL);
4633 set_dev_node(dev, orig_node);
4634 if (!tx_ring->desc)
4635 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4636 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004637 if (!tx_ring->desc)
4638 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004639
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004640 tx_ring->next_to_use = 0;
4641 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004642 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004643
4644err:
4645 vfree(tx_ring->tx_buffer_info);
4646 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004647 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004648 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004649}
4650
4651/**
Alexander Duyck69888672008-09-11 20:05:39 -07004652 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4653 * @adapter: board private structure
4654 *
4655 * If this function returns with an error, then it's possible one or
4656 * more of the rings is populated (while the rest are not). It is the
4657 * callers duty to clean those orphaned rings.
4658 *
4659 * Return 0 on success, negative on failure
4660 **/
4661static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4662{
4663 int i, err = 0;
4664
4665 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004666 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004667 if (!err)
4668 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004669
Emil Tantilov396e7992010-07-01 20:05:12 +00004670 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004671 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004672 }
4673
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004674 return 0;
4675err_setup_tx:
4676 /* rewind the index freeing the rings as we go */
4677 while (i--)
4678 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004679 return err;
4680}
4681
4682/**
Auke Kok9a799d72007-09-15 14:07:45 -07004683 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004684 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004685 *
4686 * Returns 0 on success, negative on failure
4687 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004688int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004689{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004690 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004691 int orig_node = dev_to_node(dev);
4692 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004693 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004694
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004695 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004696
4697 if (rx_ring->q_vector)
4698 numa_node = rx_ring->q_vector->numa_node;
4699
4700 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004701 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004702 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004703 if (!rx_ring->rx_buffer_info)
4704 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004705
Auke Kok9a799d72007-09-15 14:07:45 -07004706 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004707 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4708 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004709
Alexander Duyckde88eee2012-02-08 07:49:59 +00004710 set_dev_node(dev, numa_node);
4711 rx_ring->desc = dma_alloc_coherent(dev,
4712 rx_ring->size,
4713 &rx_ring->dma,
4714 GFP_KERNEL);
4715 set_dev_node(dev, orig_node);
4716 if (!rx_ring->desc)
4717 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4718 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004719 if (!rx_ring->desc)
4720 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004721
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004722 rx_ring->next_to_clean = 0;
4723 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004724
4725 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004726err:
4727 vfree(rx_ring->rx_buffer_info);
4728 rx_ring->rx_buffer_info = NULL;
4729 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004730 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004731}
4732
4733/**
Alexander Duyck69888672008-09-11 20:05:39 -07004734 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4735 * @adapter: board private structure
4736 *
4737 * If this function returns with an error, then it's possible one or
4738 * more of the rings is populated (while the rest are not). It is the
4739 * callers duty to clean those orphaned rings.
4740 *
4741 * Return 0 on success, negative on failure
4742 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004743static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4744{
4745 int i, err = 0;
4746
4747 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004748 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004749 if (!err)
4750 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004751
Emil Tantilov396e7992010-07-01 20:05:12 +00004752 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004753 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004754 }
4755
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004756#ifdef IXGBE_FCOE
4757 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4758 if (!err)
4759#endif
4760 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004761err_setup_rx:
4762 /* rewind the index freeing the rings as we go */
4763 while (i--)
4764 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004765 return err;
4766}
4767
4768/**
Auke Kok9a799d72007-09-15 14:07:45 -07004769 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004770 * @tx_ring: Tx descriptor ring for a specific queue
4771 *
4772 * Free all transmit software resources
4773 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004774void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004775{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004776 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004777
4778 vfree(tx_ring->tx_buffer_info);
4779 tx_ring->tx_buffer_info = NULL;
4780
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004781 /* if not set, then don't free */
4782 if (!tx_ring->desc)
4783 return;
4784
4785 dma_free_coherent(tx_ring->dev, tx_ring->size,
4786 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004787
4788 tx_ring->desc = NULL;
4789}
4790
4791/**
4792 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4793 * @adapter: board private structure
4794 *
4795 * Free all transmit software resources
4796 **/
4797static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4798{
4799 int i;
4800
4801 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004802 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004803 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004804}
4805
4806/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004807 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004808 * @rx_ring: ring to clean the resources from
4809 *
4810 * Free all receive software resources
4811 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004812void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004813{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004814 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004815
4816 vfree(rx_ring->rx_buffer_info);
4817 rx_ring->rx_buffer_info = NULL;
4818
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004819 /* if not set, then don't free */
4820 if (!rx_ring->desc)
4821 return;
4822
4823 dma_free_coherent(rx_ring->dev, rx_ring->size,
4824 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004825
4826 rx_ring->desc = NULL;
4827}
4828
4829/**
4830 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4831 * @adapter: board private structure
4832 *
4833 * Free all receive software resources
4834 **/
4835static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4836{
4837 int i;
4838
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004839#ifdef IXGBE_FCOE
4840 ixgbe_free_fcoe_ddp_resources(adapter);
4841
4842#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004843 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004844 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004845 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004846}
4847
4848/**
Auke Kok9a799d72007-09-15 14:07:45 -07004849 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4850 * @netdev: network interface device structure
4851 * @new_mtu: new value for maximum frame size
4852 *
4853 * Returns 0 on success, negative on failure
4854 **/
4855static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4856{
4857 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4858 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4859
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004860 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004861 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4862 return -EINVAL;
4863
4864 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00004865 * For 82599EB we cannot allow legacy VFs to enable their receive
4866 * paths when MTU greater than 1500 is configured. So display a
4867 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00004868 */
4869 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4870 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4871 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Alexander Duyck872844d2012-08-15 02:10:43 +00004872 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004873
Emil Tantilov396e7992010-07-01 20:05:12 +00004874 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004875
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004876 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004877 netdev->mtu = new_mtu;
4878
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004879 if (netif_running(netdev))
4880 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004881
4882 return 0;
4883}
4884
4885/**
4886 * ixgbe_open - Called when a network interface is made active
4887 * @netdev: network interface device structure
4888 *
4889 * Returns 0 on success, negative value on failure
4890 *
4891 * The open entry point is called when a network interface is made
4892 * active by the system (IFF_UP). At this point all resources needed
4893 * for transmit and receive operations are allocated, the interrupt
4894 * handler is registered with the OS, the watchdog timer is started,
4895 * and the stack is notified that the interface is ready.
4896 **/
4897static int ixgbe_open(struct net_device *netdev)
4898{
4899 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4900 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004901
Auke Kok4bebfaa2008-02-11 09:26:01 -08004902 /* disallow open during test */
4903 if (test_bit(__IXGBE_TESTING, &adapter->state))
4904 return -EBUSY;
4905
Jesse Brandeburg54386462009-04-17 20:44:27 +00004906 netif_carrier_off(netdev);
4907
Auke Kok9a799d72007-09-15 14:07:45 -07004908 /* allocate transmit descriptors */
4909 err = ixgbe_setup_all_tx_resources(adapter);
4910 if (err)
4911 goto err_setup_tx;
4912
Auke Kok9a799d72007-09-15 14:07:45 -07004913 /* allocate receive descriptors */
4914 err = ixgbe_setup_all_rx_resources(adapter);
4915 if (err)
4916 goto err_setup_rx;
4917
4918 ixgbe_configure(adapter);
4919
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004920 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004921 if (err)
4922 goto err_req_irq;
4923
Alexander Duyckac802f52012-07-12 05:52:53 +00004924 /* Notify the stack of the actual queue counts. */
4925 err = netif_set_real_num_tx_queues(netdev,
4926 adapter->num_rx_pools > 1 ? 1 :
4927 adapter->num_tx_queues);
4928 if (err)
4929 goto err_set_queues;
4930
4931
4932 err = netif_set_real_num_rx_queues(netdev,
4933 adapter->num_rx_pools > 1 ? 1 :
4934 adapter->num_rx_queues);
4935 if (err)
4936 goto err_set_queues;
4937
Jacob Keller1a71ab22012-08-25 03:54:19 +00004938 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004939
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004940 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004941
4942 return 0;
4943
Alexander Duyckac802f52012-07-12 05:52:53 +00004944err_set_queues:
4945 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004946err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004947 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004948err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004949 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004950err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07004951 ixgbe_reset(adapter);
4952
4953 return err;
4954}
4955
4956/**
4957 * ixgbe_close - Disables a network interface
4958 * @netdev: network interface device structure
4959 *
4960 * Returns 0, this is not allowed to fail
4961 *
4962 * The close entry point is called when an interface is de-activated
4963 * by the OS. The hardware is still under the drivers control, but
4964 * needs to be disabled. A global MAC reset is issued to stop the
4965 * hardware, and all transmit and receive resources are freed.
4966 **/
4967static int ixgbe_close(struct net_device *netdev)
4968{
4969 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004970
Jacob Keller1a71ab22012-08-25 03:54:19 +00004971 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004972
Auke Kok9a799d72007-09-15 14:07:45 -07004973 ixgbe_down(adapter);
4974 ixgbe_free_irq(adapter);
4975
Alexander Duycke4911d52011-05-11 07:18:52 +00004976 ixgbe_fdir_filter_exit(adapter);
4977
Auke Kok9a799d72007-09-15 14:07:45 -07004978 ixgbe_free_all_tx_resources(adapter);
4979 ixgbe_free_all_rx_resources(adapter);
4980
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004981 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004982
4983 return 0;
4984}
4985
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004986#ifdef CONFIG_PM
4987static int ixgbe_resume(struct pci_dev *pdev)
4988{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004989 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4990 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004991 u32 err;
4992
4993 pci_set_power_state(pdev, PCI_D0);
4994 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004995 /*
4996 * pci_restore_state clears dev->state_saved so call
4997 * pci_save_state to restore it.
4998 */
4999 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005000
5001 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005002 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005003 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005004 return err;
5005 }
5006 pci_set_master(pdev);
5007
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005008 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005009
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005010 ixgbe_reset(adapter);
5011
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005012 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5013
Alexander Duyckac802f52012-07-12 05:52:53 +00005014 rtnl_lock();
5015 err = ixgbe_init_interrupt_scheme(adapter);
5016 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005017 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005018
5019 rtnl_unlock();
5020
5021 if (err)
5022 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005023
5024 netif_device_attach(netdev);
5025
5026 return 0;
5027}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005028#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005029
5030static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005031{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005032 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5033 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005034 struct ixgbe_hw *hw = &adapter->hw;
5035 u32 ctrl, fctrl;
5036 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005037#ifdef CONFIG_PM
5038 int retval = 0;
5039#endif
5040
5041 netif_device_detach(netdev);
5042
5043 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00005044 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005045 ixgbe_down(adapter);
5046 ixgbe_free_irq(adapter);
5047 ixgbe_free_all_tx_resources(adapter);
5048 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00005049 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005050 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005051
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005052 ixgbe_clear_interrupt_scheme(adapter);
5053
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005054#ifdef CONFIG_PM
5055 retval = pci_save_state(pdev);
5056 if (retval)
5057 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005058
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005059#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005060 if (wufc) {
5061 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005062
Emil Tantilovec74a472012-09-20 03:33:56 +00005063 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5064 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005065 hw->mac.ops.enable_tx_laser(hw);
5066
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005067 /* turn on all-multi mode if wake on multicast is enabled */
5068 if (wufc & IXGBE_WUFC_MC) {
5069 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5070 fctrl |= IXGBE_FCTRL_MPE;
5071 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5072 }
5073
5074 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5075 ctrl |= IXGBE_CTRL_GIO_DIS;
5076 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5077
5078 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5079 } else {
5080 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5081 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5082 }
5083
Alexander Duyckbd508172010-11-16 19:27:03 -08005084 switch (hw->mac.type) {
5085 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005086 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005087 break;
5088 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005089 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005090 pci_wake_from_d3(pdev, !!wufc);
5091 break;
5092 default:
5093 break;
5094 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005095
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005096 *enable_wake = !!wufc;
5097
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005098 ixgbe_release_hw_control(adapter);
5099
5100 pci_disable_device(pdev);
5101
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005102 return 0;
5103}
5104
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005105#ifdef CONFIG_PM
5106static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5107{
5108 int retval;
5109 bool wake;
5110
5111 retval = __ixgbe_shutdown(pdev, &wake);
5112 if (retval)
5113 return retval;
5114
5115 if (wake) {
5116 pci_prepare_to_sleep(pdev);
5117 } else {
5118 pci_wake_from_d3(pdev, false);
5119 pci_set_power_state(pdev, PCI_D3hot);
5120 }
5121
5122 return 0;
5123}
5124#endif /* CONFIG_PM */
5125
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005126static void ixgbe_shutdown(struct pci_dev *pdev)
5127{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005128 bool wake;
5129
5130 __ixgbe_shutdown(pdev, &wake);
5131
5132 if (system_state == SYSTEM_POWER_OFF) {
5133 pci_wake_from_d3(pdev, wake);
5134 pci_set_power_state(pdev, PCI_D3hot);
5135 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005136}
5137
5138/**
Auke Kok9a799d72007-09-15 14:07:45 -07005139 * ixgbe_update_stats - Update the board statistics counters.
5140 * @adapter: board private structure
5141 **/
5142void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5143{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005144 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005145 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005146 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005147 u64 total_mpc = 0;
5148 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005149 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5150 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005151 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005152
Don Skidmored08935c2010-06-11 13:20:29 +00005153 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5154 test_bit(__IXGBE_RESETTING, &adapter->state))
5155 return;
5156
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005157 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005158 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005159 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005160 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005161 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5162 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005163 }
5164 adapter->rsc_total_count = rsc_count;
5165 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005166 }
5167
Alexander Duyck5b7da512010-11-16 19:26:50 -08005168 for (i = 0; i < adapter->num_rx_queues; i++) {
5169 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5170 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5171 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5172 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005173 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005174 bytes += rx_ring->stats.bytes;
5175 packets += rx_ring->stats.packets;
5176 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005177 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005178 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5179 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005180 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005181 netdev->stats.rx_bytes = bytes;
5182 netdev->stats.rx_packets = packets;
5183
5184 bytes = 0;
5185 packets = 0;
5186 /* gather some stats to the adapter struct that are per queue */
5187 for (i = 0; i < adapter->num_tx_queues; i++) {
5188 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5189 restart_queue += tx_ring->tx_stats.restart_queue;
5190 tx_busy += tx_ring->tx_stats.tx_busy;
5191 bytes += tx_ring->stats.bytes;
5192 packets += tx_ring->stats.packets;
5193 }
5194 adapter->restart_queue = restart_queue;
5195 adapter->tx_busy = tx_busy;
5196 netdev->stats.tx_bytes = bytes;
5197 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005198
Joe Perches7ca647b2010-09-07 21:35:40 +00005199 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005200
5201 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005202 for (i = 0; i < 8; i++) {
5203 /* for packet buffers not used, the register should read 0 */
5204 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5205 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005206 hwstats->mpc[i] += mpc;
5207 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005208 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5209 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005210 switch (hw->mac.type) {
5211 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005212 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5213 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5214 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005215 hwstats->pxonrxc[i] +=
5216 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005217 break;
5218 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005219 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005220 hwstats->pxonrxc[i] +=
5221 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005222 break;
5223 default:
5224 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005225 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005226 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005227
5228 /*16 register reads */
5229 for (i = 0; i < 16; i++) {
5230 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5231 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5232 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5233 (hw->mac.type == ixgbe_mac_X540)) {
5234 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5235 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5236 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5237 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5238 }
5239 }
5240
Joe Perches7ca647b2010-09-07 21:35:40 +00005241 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005242 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005243 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005244
John Fastabendc84d3242010-11-16 19:27:12 -08005245 ixgbe_update_xoff_received(adapter);
5246
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005247 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005248 switch (hw->mac.type) {
5249 case ixgbe_mac_82598EB:
5250 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005251 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5252 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5253 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5254 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005255 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005256 /* OS2BMC stats are X540 only*/
5257 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5258 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5259 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5260 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5261 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005262 for (i = 0; i < 16; i++)
5263 adapter->hw_rx_no_dma_resources +=
5264 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005265 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005266 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005267 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005268 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005269 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005270 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005271 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005272 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5273 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005274#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005275 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5276 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5277 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5278 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5279 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5280 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005281 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005282 if (adapter->fcoe.ddp_pool) {
5283 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5284 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5285 unsigned int cpu;
5286 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005287 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005288 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5289 noddp += ddp_pool->noddp;
5290 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005291 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005292 hwstats->fcoe_noddp = noddp;
5293 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005294 }
Yi Zou6d455222009-05-13 13:12:16 +00005295#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005296 break;
5297 default:
5298 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005299 }
Auke Kok9a799d72007-09-15 14:07:45 -07005300 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005301 hwstats->bprc += bprc;
5302 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005303 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005304 hwstats->mprc -= bprc;
5305 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5306 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5307 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5308 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5309 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5310 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5311 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5312 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005313 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005314 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005315 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005316 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005317 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5318 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005319 /*
5320 * 82598 errata - tx of flow control packets is included in tx counters
5321 */
5322 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005323 hwstats->gptc -= xon_off_tot;
5324 hwstats->mptc -= xon_off_tot;
5325 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5326 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5327 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5328 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5329 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5330 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5331 hwstats->ptc64 -= xon_off_tot;
5332 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5333 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5334 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5335 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5336 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5337 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005338
5339 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005340 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005341
5342 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005343 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005344 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005345 netdev->stats.rx_length_errors = hwstats->rlec;
5346 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005347 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005348}
5349
5350/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005351 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005352 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005353 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005354static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005355{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005356 struct ixgbe_hw *hw = &adapter->hw;
5357 int i;
5358
Alexander Duyckd034acf2011-04-27 09:25:34 +00005359 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5360 return;
5361
5362 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5363
5364 /* if interface is down do nothing */
5365 if (test_bit(__IXGBE_DOWN, &adapter->state))
5366 return;
5367
5368 /* do nothing if we are not using signature filters */
5369 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5370 return;
5371
5372 adapter->fdir_overflow++;
5373
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005374 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5375 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005376 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005377 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005378 /* re-enable flow director interrupts */
5379 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005380 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005381 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005382 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005383 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005384}
5385
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005386/**
5387 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005388 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005389 *
5390 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005391 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005392 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005393 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005394 */
5395static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5396{
Auke Kok9a799d72007-09-15 14:07:45 -07005397 struct ixgbe_hw *hw = &adapter->hw;
5398 u64 eics = 0;
5399 int i;
5400
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005401 /* If we're down or resetting, just bail */
5402 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5403 test_bit(__IXGBE_RESETTING, &adapter->state))
5404 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005405
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005406 /* Force detection of hung controller */
5407 if (netif_carrier_ok(adapter->netdev)) {
5408 for (i = 0; i < adapter->num_tx_queues; i++)
5409 set_check_for_tx_hang(adapter->tx_ring[i]);
5410 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005411
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005412 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005413 /*
5414 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005415 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005416 * would set *both* EIMS and EICS for any bit in EIAM
5417 */
5418 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5419 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005420 } else {
5421 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005422 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005423 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005424 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005425 eics |= ((u64)1 << i);
5426 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005427 }
5428
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005429 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005430 ixgbe_irq_rearm_queues(adapter, eics);
5431
Alexander Duyckfe49f042009-06-04 16:00:09 +00005432}
5433
5434/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005435 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005436 * @adapter: pointer to the device adapter structure
5437 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005438 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005439static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005440{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005441 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005442 u32 link_speed = adapter->link_speed;
5443 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005444 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005445
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005446 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5447 return;
5448
5449 if (hw->mac.ops.check_link) {
5450 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005451 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005452 /* always assume link is up, if no check link function */
5453 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5454 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005455 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005456
5457 if (adapter->ixgbe_ieee_pfc)
5458 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5459
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005460 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005461 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005462 ixgbe_set_rx_drop_en(adapter);
5463 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005464
5465 if (link_up ||
5466 time_after(jiffies, (adapter->link_check_timeout +
5467 IXGBE_TRY_LINK_TIMEOUT))) {
5468 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5469 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5470 IXGBE_WRITE_FLUSH(hw);
5471 }
5472
5473 adapter->link_up = link_up;
5474 adapter->link_speed = link_speed;
5475}
5476
Alexander Duyck107d3012012-10-02 00:17:03 +00005477static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5478{
5479#ifdef CONFIG_IXGBE_DCB
5480 struct net_device *netdev = adapter->netdev;
5481 struct dcb_app app = {
5482 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5483 .protocol = 0,
5484 };
5485 u8 up = 0;
5486
5487 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5488 up = dcb_ieee_getapp_mask(netdev, &app);
5489
5490 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5491#endif
5492}
5493
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005494/**
5495 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5496 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005497 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005498 **/
5499static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5500{
5501 struct net_device *netdev = adapter->netdev;
5502 struct ixgbe_hw *hw = &adapter->hw;
5503 u32 link_speed = adapter->link_speed;
5504 bool flow_rx, flow_tx;
5505
5506 /* only continue if link was previously down */
5507 if (netif_carrier_ok(netdev))
5508 return;
5509
5510 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5511
5512 switch (hw->mac.type) {
5513 case ixgbe_mac_82598EB: {
5514 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5515 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5516 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5517 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5518 }
5519 break;
5520 case ixgbe_mac_X540:
5521 case ixgbe_mac_82599EB: {
5522 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5523 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5524 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5525 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5526 }
5527 break;
5528 default:
5529 flow_tx = false;
5530 flow_rx = false;
5531 break;
5532 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005533
Jacob Keller6cb562d2012-12-05 07:24:41 +00005534 adapter->last_rx_ptp_check = jiffies;
5535
Jacob Keller1a71ab22012-08-25 03:54:19 +00005536 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5537 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005538
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005539 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5540 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5541 "10 Gbps" :
5542 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5543 "1 Gbps" :
5544 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5545 "100 Mbps" :
5546 "unknown speed"))),
5547 ((flow_rx && flow_tx) ? "RX/TX" :
5548 (flow_rx ? "RX" :
5549 (flow_tx ? "TX" : "None"))));
5550
5551 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005552 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005553
Alexander Duyck107d3012012-10-02 00:17:03 +00005554 /* update the default user priority for VFs */
5555 ixgbe_update_default_up(adapter);
5556
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005557 /* ping all the active vfs to let them know link has changed */
5558 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005559}
5560
5561/**
5562 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5563 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005564 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005565 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005566static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005567{
5568 struct net_device *netdev = adapter->netdev;
5569 struct ixgbe_hw *hw = &adapter->hw;
5570
5571 adapter->link_up = false;
5572 adapter->link_speed = 0;
5573
5574 /* only continue if link was up previously */
5575 if (!netif_carrier_ok(netdev))
5576 return;
5577
5578 /* poll for SFP+ cable when link is down */
5579 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5580 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5581
Jacob Keller1a71ab22012-08-25 03:54:19 +00005582 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5583 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005584
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005585 e_info(drv, "NIC Link is Down\n");
5586 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005587
5588 /* 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_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005594 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005595 **/
5596static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5597{
5598 int i;
5599 int some_tx_pending = 0;
5600
5601 if (!netif_carrier_ok(adapter->netdev)) {
5602 for (i = 0; i < adapter->num_tx_queues; i++) {
5603 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5604 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5605 some_tx_pending = 1;
5606 break;
5607 }
5608 }
5609
5610 if (some_tx_pending) {
5611 /* We've lost link, so the controller stops DMA,
5612 * but we've got queued Tx work that's never going
5613 * to get done, so reset controller to flush Tx.
5614 * (Do the reset outside of interrupt context).
5615 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005616 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005617 }
5618 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005619}
5620
Greg Rosea985b6c32010-11-18 03:02:52 +00005621static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5622{
5623 u32 ssvpc;
5624
Greg Rose0584d992012-08-08 00:00:58 +00005625 /* Do not perform spoof check for 82598 or if not in IOV mode */
5626 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5627 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005628 return;
5629
5630 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5631
5632 /*
5633 * ssvpc register is cleared on read, if zero then no
5634 * spoofed packets in the last interval.
5635 */
5636 if (!ssvpc)
5637 return;
5638
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005639 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005640}
5641
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005642/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005643 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005644 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005645 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005646static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005647{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005648 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005649 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5650 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005651 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005652
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005653 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005654
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005655 if (adapter->link_up)
5656 ixgbe_watchdog_link_is_up(adapter);
5657 else
5658 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005659
Greg Rosea985b6c32010-11-18 03:02:52 +00005660 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005661 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005662
5663 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005664}
5665
Alexander Duyck70864002011-04-27 09:13:56 +00005666/**
5667 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005668 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005669 **/
5670static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5671{
5672 struct ixgbe_hw *hw = &adapter->hw;
5673 s32 err;
5674
5675 /* not searching for SFP so there is nothing to do here */
5676 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5677 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5678 return;
5679
5680 /* someone else is in init, wait until next service event */
5681 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5682 return;
5683
5684 err = hw->phy.ops.identify_sfp(hw);
5685 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5686 goto sfp_out;
5687
5688 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5689 /* If no cable is present, then we need to reset
5690 * the next time we find a good cable. */
5691 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5692 }
5693
5694 /* exit on error */
5695 if (err)
5696 goto sfp_out;
5697
5698 /* exit if reset not needed */
5699 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5700 goto sfp_out;
5701
5702 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5703
5704 /*
5705 * A module may be identified correctly, but the EEPROM may not have
5706 * support for that module. setup_sfp() will fail in that case, so
5707 * we should not allow that module to load.
5708 */
5709 if (hw->mac.type == ixgbe_mac_82598EB)
5710 err = hw->phy.ops.reset(hw);
5711 else
5712 err = hw->mac.ops.setup_sfp(hw);
5713
5714 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5715 goto sfp_out;
5716
5717 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5718 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5719
5720sfp_out:
5721 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5722
5723 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5724 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5725 e_dev_err("failed to initialize because an unsupported "
5726 "SFP+ module type was detected.\n");
5727 e_dev_err("Reload the driver after installing a "
5728 "supported module.\n");
5729 unregister_netdev(adapter->netdev);
5730 }
5731}
5732
5733/**
5734 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005735 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005736 **/
5737static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5738{
5739 struct ixgbe_hw *hw = &adapter->hw;
5740 u32 autoneg;
5741 bool negotiation;
5742
5743 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5744 return;
5745
5746 /* someone else is in init, wait until next service event */
5747 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5748 return;
5749
5750 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5751
5752 autoneg = hw->phy.autoneg_advertised;
5753 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5754 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005755 if (hw->mac.ops.setup_link)
5756 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5757
5758 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5759 adapter->link_check_timeout = jiffies;
5760 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5761}
5762
Greg Rose83c61fa2011-09-07 05:59:35 +00005763#ifdef CONFIG_PCI_IOV
5764static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5765{
5766 int vf;
5767 struct ixgbe_hw *hw = &adapter->hw;
5768 struct net_device *netdev = adapter->netdev;
5769 u32 gpc;
5770 u32 ciaa, ciad;
5771
5772 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5773 if (gpc) /* If incrementing then no need for the check below */
5774 return;
5775 /*
5776 * Check to see if a bad DMA write target from an errant or
5777 * malicious VF has caused a PCIe error. If so then we can
5778 * issue a VFLR to the offending VF(s) and then resume without
5779 * requesting a full slot reset.
5780 */
5781
5782 for (vf = 0; vf < adapter->num_vfs; vf++) {
5783 ciaa = (vf << 16) | 0x80000000;
5784 /* 32 bit read so align, we really want status at offset 6 */
5785 ciaa |= PCI_COMMAND;
5786 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5787 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5788 ciaa &= 0x7FFFFFFF;
5789 /* disable debug mode asap after reading data */
5790 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5791 /* Get the upper 16 bits which will be the PCI status reg */
5792 ciad >>= 16;
5793 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5794 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5795 /* Issue VFLR */
5796 ciaa = (vf << 16) | 0x80000000;
5797 ciaa |= 0xA8;
5798 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5799 ciad = 0x00008000; /* VFLR */
5800 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5801 ciaa &= 0x7FFFFFFF;
5802 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5803 }
5804 }
5805}
5806
5807#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005808/**
5809 * ixgbe_service_timer - Timer Call-back
5810 * @data: pointer to adapter cast into an unsigned long
5811 **/
5812static void ixgbe_service_timer(unsigned long data)
5813{
5814 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5815 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005816 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005817
5818 /* poll faster when waiting for link */
5819 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5820 next_event_offset = HZ / 10;
5821 else
5822 next_event_offset = HZ * 2;
5823
Greg Rose83c61fa2011-09-07 05:59:35 +00005824#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005825 /*
5826 * don't bother with SR-IOV VF DMA hang check if there are
5827 * no VFs or the link is down
5828 */
5829 if (!adapter->num_vfs ||
5830 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5831 goto normal_timer_service;
5832
5833 /* If we have VFs allocated then we must check for DMA hangs */
5834 ixgbe_check_for_bad_vf(adapter);
5835 next_event_offset = HZ / 50;
5836 adapter->timer_event_accumulator++;
5837
5838 if (adapter->timer_event_accumulator >= 100)
5839 adapter->timer_event_accumulator = 0;
5840 else
5841 ready = false;
5842
5843normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005844#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005845 /* Reset the timer */
5846 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5847
Greg Rose83c61fa2011-09-07 05:59:35 +00005848 if (ready)
5849 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005850}
5851
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005852static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5853{
5854 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5855 return;
5856
5857 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5858
5859 /* If we're already down or resetting, just bail */
5860 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5861 test_bit(__IXGBE_RESETTING, &adapter->state))
5862 return;
5863
5864 ixgbe_dump(adapter);
5865 netdev_err(adapter->netdev, "Reset adapter\n");
5866 adapter->tx_timeout_count++;
5867
5868 ixgbe_reinit_locked(adapter);
5869}
5870
Alexander Duyck70864002011-04-27 09:13:56 +00005871/**
5872 * ixgbe_service_task - manages and runs subtasks
5873 * @work: pointer to work_struct containing our data
5874 **/
5875static void ixgbe_service_task(struct work_struct *work)
5876{
5877 struct ixgbe_adapter *adapter = container_of(work,
5878 struct ixgbe_adapter,
5879 service_task);
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005880 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005881 ixgbe_sfp_detection_subtask(adapter);
5882 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005883 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005884 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005885 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005886 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00005887
5888 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) {
5889 ixgbe_ptp_overflow_check(adapter);
5890 ixgbe_ptp_rx_hang(adapter);
5891 }
Alexander Duyck70864002011-04-27 09:13:56 +00005892
5893 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005894}
5895
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005896static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5897 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005898 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005899{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005900 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005901 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005902 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005903
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00005904 if (skb->ip_summed != CHECKSUM_PARTIAL)
5905 return 0;
5906
Alexander Duyck897ab152011-05-27 05:31:47 +00005907 if (!skb_is_gso(skb))
5908 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005909
Alexander Duyck897ab152011-05-27 05:31:47 +00005910 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005911 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005912 if (err)
5913 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005914 }
5915
Alexander Duyck897ab152011-05-27 05:31:47 +00005916 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5917 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5918
Alexander Duyck244e27a2012-02-08 07:51:11 +00005919 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005920 struct iphdr *iph = ip_hdr(skb);
5921 iph->tot_len = 0;
5922 iph->check = 0;
5923 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5924 iph->daddr, 0,
5925 IPPROTO_TCP,
5926 0);
5927 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005928 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5929 IXGBE_TX_FLAGS_CSUM |
5930 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005931 } else if (skb_is_gso_v6(skb)) {
5932 ipv6_hdr(skb)->payload_len = 0;
5933 tcp_hdr(skb)->check =
5934 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5935 &ipv6_hdr(skb)->daddr,
5936 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005937 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5938 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005939 }
5940
Alexander Duyck091a6242012-02-08 07:51:01 +00005941 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005942 l4len = tcp_hdrlen(skb);
5943 *hdr_len = skb_transport_offset(skb) + l4len;
5944
Alexander Duyck091a6242012-02-08 07:51:01 +00005945 /* update gso size and bytecount with header size */
5946 first->gso_segs = skb_shinfo(skb)->gso_segs;
5947 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5948
Alexander Duyckc44f5f52012-10-30 06:01:45 +00005949 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyck897ab152011-05-27 05:31:47 +00005950 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5951 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00005952
5953 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5954 vlan_macip_lens = skb_network_header_len(skb);
5955 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005956 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005957
5958 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005959 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005960
5961 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005962}
5963
Alexander Duyck244e27a2012-02-08 07:51:11 +00005964static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5965 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005966{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005967 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005968 u32 vlan_macip_lens = 0;
5969 u32 mss_l4len_idx = 0;
5970 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005971
Alexander Duyck897ab152011-05-27 05:31:47 +00005972 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck472148c2012-11-07 02:34:28 +00005973 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
5974 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
5975 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00005976 } else {
5977 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005978 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005979 case __constant_htons(ETH_P_IP):
5980 vlan_macip_lens |= skb_network_header_len(skb);
5981 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5982 l4_hdr = ip_hdr(skb)->protocol;
5983 break;
5984 case __constant_htons(ETH_P_IPV6):
5985 vlan_macip_lens |= skb_network_header_len(skb);
5986 l4_hdr = ipv6_hdr(skb)->nexthdr;
5987 break;
5988 default:
5989 if (unlikely(net_ratelimit())) {
5990 dev_warn(tx_ring->dev,
5991 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005992 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005993 }
5994 break;
5995 }
Auke Kok9a799d72007-09-15 14:07:45 -07005996
Alexander Duyck897ab152011-05-27 05:31:47 +00005997 switch (l4_hdr) {
5998 case IPPROTO_TCP:
5999 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6000 mss_l4len_idx = tcp_hdrlen(skb) <<
6001 IXGBE_ADVTXD_L4LEN_SHIFT;
6002 break;
6003 case IPPROTO_SCTP:
6004 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6005 mss_l4len_idx = sizeof(struct sctphdr) <<
6006 IXGBE_ADVTXD_L4LEN_SHIFT;
6007 break;
6008 case IPPROTO_UDP:
6009 mss_l4len_idx = sizeof(struct udphdr) <<
6010 IXGBE_ADVTXD_L4LEN_SHIFT;
6011 break;
6012 default:
6013 if (unlikely(net_ratelimit())) {
6014 dev_warn(tx_ring->dev,
6015 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006016 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006017 }
6018 break;
6019 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006020
6021 /* update TX checksum flag */
6022 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006023 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006024
Alexander Duyck244e27a2012-02-08 07:51:11 +00006025 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006026 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006027 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006028
6029 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6030 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006031}
6032
Alexander Duyck472148c2012-11-07 02:34:28 +00006033#define IXGBE_SET_FLAG(_input, _flag, _result) \
6034 ((_flag <= _result) ? \
6035 ((u32)(_input & _flag) * (_result / _flag)) : \
6036 ((u32)(_input & _flag) / (_flag / _result)))
6037
6038static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006039{
6040 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00006041 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6042 IXGBE_ADVTXD_DCMD_DEXT |
6043 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006044
6045 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00006046 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6047 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006048
Alexander Duyckd3d00232011-07-15 02:31:25 +00006049 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006050 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6051 IXGBE_ADVTXD_DCMD_TSE);
6052
6053 /* set timestamp bit if present */
6054 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6055 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006056
Alexander Duyck62748b72012-07-20 08:09:01 +00006057 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00006058 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00006059
Alexander Duyckd3d00232011-07-15 02:31:25 +00006060 return cmd_type;
6061}
6062
Alexander Duyck729739b2012-02-08 07:51:06 +00006063static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6064 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006065{
Alexander Duyck472148c2012-11-07 02:34:28 +00006066 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006067
6068 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00006069 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6070 IXGBE_TX_FLAGS_CSUM,
6071 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006072
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006073 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00006074 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6075 IXGBE_TX_FLAGS_IPV4,
6076 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006077
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006078 /*
6079 * Check Context must be set if Tx switch is enabled, which it
6080 * always is for case where virtual functions are running
6081 */
Alexander Duyck472148c2012-11-07 02:34:28 +00006082 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
6083 IXGBE_TX_FLAGS_CC,
6084 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006085
Alexander Duyck472148c2012-11-07 02:34:28 +00006086 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006087}
6088
6089#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6090 IXGBE_TXD_CMD_RS)
6091
6092static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006093 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006094 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006095{
Alexander Duyck729739b2012-02-08 07:51:06 +00006096 struct sk_buff *skb = first->skb;
6097 struct ixgbe_tx_buffer *tx_buffer;
6098 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00006099 struct skb_frag_struct *frag;
6100 dma_addr_t dma;
6101 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006102 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00006103 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006104 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006105
Alexander Duyck729739b2012-02-08 07:51:06 +00006106 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6107
Alexander Duyckec718252012-10-30 06:01:55 +00006108 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
6109
6110 size = skb_headlen(skb);
6111 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00006112
Alexander Duyckd3d00232011-07-15 02:31:25 +00006113#ifdef IXGBE_FCOE
6114 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006115 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006116 size -= sizeof(struct fcoe_crc_eof) - data_len;
6117 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006118 } else {
6119 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006120 }
Auke Kok9a799d72007-09-15 14:07:45 -07006121 }
6122
Alexander Duyckd3d00232011-07-15 02:31:25 +00006123#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006124 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006125
Alexander Duyckec718252012-10-30 06:01:55 +00006126 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006127
Alexander Duyckec718252012-10-30 06:01:55 +00006128 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
6129 if (dma_mapping_error(tx_ring->dev, dma))
6130 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006131
Alexander Duyckec718252012-10-30 06:01:55 +00006132 /* record length, and DMA address */
6133 dma_unmap_len_set(tx_buffer, len, size);
6134 dma_unmap_addr_set(tx_buffer, dma, dma);
6135
6136 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6137
Alexander Duyck729739b2012-02-08 07:51:06 +00006138 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006139 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00006140 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006141
Alexander Duyckd3d00232011-07-15 02:31:25 +00006142 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006143 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006144 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006145 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006146 i = 0;
6147 }
Alexander Duyckec718252012-10-30 06:01:55 +00006148 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006149
6150 dma += IXGBE_MAX_DATA_PER_TXD;
6151 size -= IXGBE_MAX_DATA_PER_TXD;
6152
6153 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006154 }
6155
Alexander Duyck729739b2012-02-08 07:51:06 +00006156 if (likely(!data_len))
6157 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006158
Alexander Duyck472148c2012-11-07 02:34:28 +00006159 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006160
Alexander Duyck729739b2012-02-08 07:51:06 +00006161 i++;
6162 tx_desc++;
6163 if (i == tx_ring->count) {
6164 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6165 i = 0;
6166 }
Alexander Duyckec718252012-10-30 06:01:55 +00006167 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006168
Alexander Duyckd3d00232011-07-15 02:31:25 +00006169#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006170 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006171#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006172 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006173#endif
6174 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006175
Alexander Duyck729739b2012-02-08 07:51:06 +00006176 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6177 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07006178
Alexander Duyck729739b2012-02-08 07:51:06 +00006179 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07006180 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006181
Alexander Duyck729739b2012-02-08 07:51:06 +00006182 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00006183 cmd_type |= size | IXGBE_TXD_CMD;
6184 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006185
Alexander Duyck091a6242012-02-08 07:51:01 +00006186 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006187
Alexander Duyckd3d00232011-07-15 02:31:25 +00006188 /* set the timestamp */
6189 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006190
6191 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006192 * Force memory writes to complete before letting h/w know there
6193 * are new descriptors to fetch. (Only applicable for weak-ordered
6194 * memory model archs, such as IA-64).
6195 *
6196 * We also need this memory barrier to make certain all of the
6197 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006198 */
6199 wmb();
6200
Alexander Duyckd3d00232011-07-15 02:31:25 +00006201 /* set next_to_watch value indicating a packet is present */
6202 first->next_to_watch = tx_desc;
6203
Alexander Duyck729739b2012-02-08 07:51:06 +00006204 i++;
6205 if (i == tx_ring->count)
6206 i = 0;
6207
6208 tx_ring->next_to_use = i;
6209
Alexander Duyckd3d00232011-07-15 02:31:25 +00006210 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006211 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006212
6213 return;
6214dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006215 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006216
6217 /* clear dma mappings for failed tx_buffer_info map */
6218 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006219 tx_buffer = &tx_ring->tx_buffer_info[i];
6220 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6221 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006222 break;
6223 if (i == 0)
6224 i = tx_ring->count;
6225 i--;
6226 }
6227
Alexander Duyckd3d00232011-07-15 02:31:25 +00006228 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006229}
6230
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006231static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006232 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006233{
Alexander Duyck69830522011-01-06 14:29:58 +00006234 struct ixgbe_q_vector *q_vector = ring->q_vector;
6235 union ixgbe_atr_hash_dword input = { .dword = 0 };
6236 union ixgbe_atr_hash_dword common = { .dword = 0 };
6237 union {
6238 unsigned char *network;
6239 struct iphdr *ipv4;
6240 struct ipv6hdr *ipv6;
6241 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006242 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006243 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006244
Alexander Duyck69830522011-01-06 14:29:58 +00006245 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6246 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006247 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006248
Alexander Duyck69830522011-01-06 14:29:58 +00006249 /* do nothing if sampling is disabled */
6250 if (!ring->atr_sample_rate)
6251 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006252
Alexander Duyck69830522011-01-06 14:29:58 +00006253 ring->atr_count++;
6254
6255 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006256 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006257
6258 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006259 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006260 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006261 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006262 hdr.ipv4->protocol != IPPROTO_TCP))
6263 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006264
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006265 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006266
Alexander Duyck66f32a82011-06-29 05:43:22 +00006267 /* skip this packet since it is invalid or the socket is closing */
6268 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006269 return;
6270
6271 /* sample on all syn packets or once every atr sample count */
6272 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6273 return;
6274
6275 /* reset sample count */
6276 ring->atr_count = 0;
6277
Alexander Duyck244e27a2012-02-08 07:51:11 +00006278 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006279
6280 /*
6281 * src and dst are inverted, think how the receiver sees them
6282 *
6283 * The input is broken into two sections, a non-compressed section
6284 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6285 * is XORed together and stored in the compressed dword.
6286 */
6287 input.formatted.vlan_id = vlan_id;
6288
6289 /*
6290 * since src port and flex bytes occupy the same word XOR them together
6291 * and write the value to source port portion of compressed dword
6292 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006293 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006294 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6295 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006296 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006297 common.port.dst ^= th->source;
6298
Alexander Duyck244e27a2012-02-08 07:51:11 +00006299 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006300 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6301 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6302 } else {
6303 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6304 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6305 hdr.ipv6->saddr.s6_addr32[1] ^
6306 hdr.ipv6->saddr.s6_addr32[2] ^
6307 hdr.ipv6->saddr.s6_addr32[3] ^
6308 hdr.ipv6->daddr.s6_addr32[0] ^
6309 hdr.ipv6->daddr.s6_addr32[1] ^
6310 hdr.ipv6->daddr.s6_addr32[2] ^
6311 hdr.ipv6->daddr.s6_addr32[3];
6312 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006313
6314 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006315 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6316 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006317}
6318
Alexander Duyck63544e92011-05-27 05:31:42 +00006319static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006320{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006321 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006322 /* Herbert's original patch had:
6323 * smp_mb__after_netif_stop_queue();
6324 * but since that doesn't exist yet, just open code it. */
6325 smp_mb();
6326
6327 /* We need to check again in a case another CPU has just
6328 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006329 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006330 return -EBUSY;
6331
6332 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006333 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006334 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006335 return 0;
6336}
6337
Alexander Duyck82d4e462011-06-11 01:44:58 +00006338static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006339{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006340 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006341 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006342 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006343}
6344
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006345static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6346{
6347 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006348 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6349 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006350#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006351 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006352
John Fastabende5b64632011-03-08 03:44:52 +00006353 if (((protocol == htons(ETH_P_FCOE)) ||
6354 (protocol == htons(ETH_P_FIP))) &&
6355 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckc0876632012-05-10 00:01:46 +00006356 struct ixgbe_ring_feature *f;
6357
6358 f = &adapter->ring_feature[RING_F_FCOE];
6359
6360 while (txq >= f->indices)
6361 txq -= f->indices;
Alexander Duycke4b317e2012-05-05 05:30:53 +00006362 txq += adapter->ring_feature[RING_F_FCOE].offset;
Alexander Duyckc0876632012-05-10 00:01:46 +00006363
John Fastabende5b64632011-03-08 03:44:52 +00006364 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006365 }
6366#endif
6367
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006368 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6369 while (unlikely(txq >= dev->real_num_tx_queues))
6370 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006371 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006372 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006373
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006374 return skb_tx_hash(dev, skb);
6375}
6376
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006377netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006378 struct ixgbe_adapter *adapter,
6379 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006380{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006381 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006382 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006383 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006384#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6385 unsigned short f;
6386#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006387 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006388 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006389 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006390
Alexander Duycka535c302011-05-27 05:31:52 +00006391 /*
6392 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006393 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006394 * + 2 desc gap to keep tail from touching head,
6395 * + 1 desc for context descriptor,
6396 * otherwise try next time
6397 */
6398#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6399 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6400 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6401#else
6402 count += skb_shinfo(skb)->nr_frags;
6403#endif
6404 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6405 tx_ring->tx_stats.tx_busy++;
6406 return NETDEV_TX_BUSY;
6407 }
6408
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006409 /* record the location of the first descriptor for this packet */
6410 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6411 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006412 first->bytecount = skb->len;
6413 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006414
Alexander Duyck66f32a82011-06-29 05:43:22 +00006415 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006416 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006417 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6418 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6419 /* else if it is a SW VLAN check the next protocol and store the tag */
6420 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6421 struct vlan_hdr *vhdr, _vhdr;
6422 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6423 if (!vhdr)
6424 goto out_drop;
6425
6426 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006427 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6428 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006429 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006430 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006431
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006432 skb_tx_timestamp(skb);
6433
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006434 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6435 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6436 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00006437
6438 /* schedule check for Tx timestamp */
6439 adapter->ptp_tx_skb = skb_get(skb);
6440 adapter->ptp_tx_start = jiffies;
6441 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006442 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006443
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006444#ifdef CONFIG_PCI_IOV
6445 /*
6446 * Use the l2switch_enable flag - would be false if the DMA
6447 * Tx switch had been disabled.
6448 */
6449 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00006450 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006451
6452#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006453 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006454 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006455 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6456 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006457 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006458 tx_flags |= (skb->priority & 0x7) <<
6459 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006460 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6461 struct vlan_ethhdr *vhdr;
6462 if (skb_header_cloned(skb) &&
6463 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6464 goto out_drop;
6465 vhdr = (struct vlan_ethhdr *)skb->data;
6466 vhdr->h_vlan_TCI = htons(tx_flags >>
6467 IXGBE_TX_FLAGS_VLAN_SHIFT);
6468 } else {
6469 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6470 }
6471 }
Alexander Duycka535c302011-05-27 05:31:52 +00006472
Alexander Duyck244e27a2012-02-08 07:51:11 +00006473 /* record initial flags and protocol */
6474 first->tx_flags = tx_flags;
6475 first->protocol = protocol;
6476
Yi Zoueacd73f2009-05-13 13:11:06 +00006477#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006478 /* setup tx offload for FCoE */
6479 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006480 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006481 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006482 if (tso < 0)
6483 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006484
Alexander Duyck66f32a82011-06-29 05:43:22 +00006485 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006486 }
Auke Kok9a799d72007-09-15 14:07:45 -07006487
Auke Kok9a799d72007-09-15 14:07:45 -07006488#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006489 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006490 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006491 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006492 else if (!tso)
6493 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006494
6495 /* add the ATR filter if ATR is on */
6496 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006497 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006498
6499#ifdef IXGBE_FCOE
6500xmit_fcoe:
6501#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006502 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006503
6504 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006505
6506 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006507
6508out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006509 dev_kfree_skb_any(first->skb);
6510 first->skb = NULL;
6511
Alexander Duyck897ab152011-05-27 05:31:47 +00006512 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006513}
6514
Alexander Duycka50c29d2012-02-08 07:50:40 +00006515static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6516 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006517{
6518 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006519 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006520
Alexander Duycka50c29d2012-02-08 07:50:40 +00006521 /*
6522 * The minimum packet size for olinfo paylen is 17 so pad the skb
6523 * in order to meet this minimum size requirement.
6524 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006525 if (unlikely(skb->len < 17)) {
6526 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006527 return NETDEV_TX_OK;
6528 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006529 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006530 }
6531
Auke Kok9a799d72007-09-15 14:07:45 -07006532 tx_ring = adapter->tx_ring[skb->queue_mapping];
6533 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6534}
6535
6536/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006537 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006538 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006539 * @p: pointer to an address structure
6540 *
Auke Kok9a799d72007-09-15 14:07:45 -07006541 * Returns 0 on success, negative on failure
6542 **/
6543static int ixgbe_set_mac(struct net_device *netdev, void *p)
6544{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006545 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6546 struct ixgbe_hw *hw = &adapter->hw;
6547 struct sockaddr *addr = p;
6548
6549 if (!is_valid_ether_addr(addr->sa_data))
6550 return -EADDRNOTAVAIL;
6551
6552 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6553 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6554
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006555 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006556
6557 return 0;
6558}
6559
Ben Hutchings6b73e102009-04-29 08:08:58 +00006560static int
6561ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6562{
6563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6564 struct ixgbe_hw *hw = &adapter->hw;
6565 u16 value;
6566 int rc;
6567
6568 if (prtad != hw->phy.mdio.prtad)
6569 return -EINVAL;
6570 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6571 if (!rc)
6572 rc = value;
6573 return rc;
6574}
6575
6576static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6577 u16 addr, u16 value)
6578{
6579 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6580 struct ixgbe_hw *hw = &adapter->hw;
6581
6582 if (prtad != hw->phy.mdio.prtad)
6583 return -EINVAL;
6584 return hw->phy.ops.write_reg(hw, addr, devad, value);
6585}
6586
6587static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6588{
6589 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6590
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006591 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006592 case SIOCSHWTSTAMP:
6593 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006594 default:
6595 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6596 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006597}
6598
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006599/**
6600 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006601 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006602 * @netdev: network interface device structure
6603 *
6604 * Returns non-zero on failure
6605 **/
6606static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6607{
6608 int err = 0;
6609 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006610 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006611
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006612 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006613 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006614 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006615 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006616
6617 /* update SAN MAC vmdq pool selection */
6618 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006619 }
6620 return err;
6621}
6622
6623/**
6624 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006625 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006626 * @netdev: network interface device structure
6627 *
6628 * Returns non-zero on failure
6629 **/
6630static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6631{
6632 int err = 0;
6633 struct ixgbe_adapter *adapter = netdev_priv(dev);
6634 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6635
6636 if (is_valid_ether_addr(mac->san_addr)) {
6637 rtnl_lock();
6638 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6639 rtnl_unlock();
6640 }
6641 return err;
6642}
6643
Auke Kok9a799d72007-09-15 14:07:45 -07006644#ifdef CONFIG_NET_POLL_CONTROLLER
6645/*
6646 * Polling 'interrupt' - used by things like netconsole to send skbs
6647 * without having to re-enable interrupts. It's not called while
6648 * the interrupt routine is executing.
6649 */
6650static void ixgbe_netpoll(struct net_device *netdev)
6651{
6652 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006653 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006654
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006655 /* if interface is down do nothing */
6656 if (test_bit(__IXGBE_DOWN, &adapter->state))
6657 return;
6658
Auke Kok9a799d72007-09-15 14:07:45 -07006659 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006660 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006661 for (i = 0; i < adapter->num_q_vectors; i++)
6662 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006663 } else {
6664 ixgbe_intr(adapter->pdev->irq, netdev);
6665 }
Auke Kok9a799d72007-09-15 14:07:45 -07006666 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006667}
Auke Kok9a799d72007-09-15 14:07:45 -07006668
Alexander Duyck581330b2012-02-08 07:51:47 +00006669#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006670static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6671 struct rtnl_link_stats64 *stats)
6672{
6673 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6674 int i;
6675
Eric Dumazet1a515022010-11-16 19:26:42 -08006676 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006677 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006678 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006679 u64 bytes, packets;
6680 unsigned int start;
6681
Eric Dumazet1a515022010-11-16 19:26:42 -08006682 if (ring) {
6683 do {
6684 start = u64_stats_fetch_begin_bh(&ring->syncp);
6685 packets = ring->stats.packets;
6686 bytes = ring->stats.bytes;
6687 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6688 stats->rx_packets += packets;
6689 stats->rx_bytes += bytes;
6690 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006691 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006692
6693 for (i = 0; i < adapter->num_tx_queues; i++) {
6694 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6695 u64 bytes, packets;
6696 unsigned int start;
6697
6698 if (ring) {
6699 do {
6700 start = u64_stats_fetch_begin_bh(&ring->syncp);
6701 packets = ring->stats.packets;
6702 bytes = ring->stats.bytes;
6703 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6704 stats->tx_packets += packets;
6705 stats->tx_bytes += bytes;
6706 }
6707 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006708 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006709 /* following stats updated by ixgbe_watchdog_task() */
6710 stats->multicast = netdev->stats.multicast;
6711 stats->rx_errors = netdev->stats.rx_errors;
6712 stats->rx_length_errors = netdev->stats.rx_length_errors;
6713 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6714 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6715 return stats;
6716}
6717
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006718#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006719/**
6720 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6721 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006722 * @tc: number of traffic classes currently enabled
6723 *
6724 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6725 * 802.1Q priority maps to a packet buffer that exists.
6726 */
6727static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6728{
6729 struct ixgbe_hw *hw = &adapter->hw;
6730 u32 reg, rsave;
6731 int i;
6732
6733 /* 82598 have a static priority to TC mapping that can not
6734 * be changed so no validation is needed.
6735 */
6736 if (hw->mac.type == ixgbe_mac_82598EB)
6737 return;
6738
6739 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6740 rsave = reg;
6741
6742 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6743 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6744
6745 /* If up2tc is out of bounds default to zero */
6746 if (up2tc > tc)
6747 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6748 }
6749
6750 if (reg != rsave)
6751 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6752
6753 return;
6754}
6755
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006756/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006757 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6758 * @adapter: Pointer to adapter struct
6759 *
6760 * Populate the netdev user priority to tc map
6761 */
6762static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6763{
6764 struct net_device *dev = adapter->netdev;
6765 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6766 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6767 u8 prio;
6768
6769 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6770 u8 tc = 0;
6771
6772 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6773 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6774 else if (ets)
6775 tc = ets->prio_tc[prio];
6776
6777 netdev_set_prio_tc_map(dev, prio, tc);
6778 }
6779}
6780
6781/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006782 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006783 *
6784 * @netdev: net device to configure
6785 * @tc: number of traffic classes to enable
6786 */
6787int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6788{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006789 struct ixgbe_adapter *adapter = netdev_priv(dev);
6790 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006791
John Fastabend8b1c0b22011-05-03 02:26:48 +00006792 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006793 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006794 (hw->mac.type == ixgbe_mac_82598EB &&
6795 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006796 return -EINVAL;
6797
6798 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006799 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006800 * hardware is not flexible enough to do this dynamically.
6801 */
6802 if (netif_running(dev))
6803 ixgbe_close(dev);
6804 ixgbe_clear_interrupt_scheme(adapter);
6805
John Fastabende7589ea2011-07-18 22:38:36 +00006806 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006807 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006808 ixgbe_set_prio_tc_map(adapter);
6809
John Fastabende7589ea2011-07-18 22:38:36 +00006810 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006811
Alexander Duyck943561d2012-05-09 22:14:44 -07006812 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6813 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006814 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006815 }
John Fastabende7589ea2011-07-18 22:38:36 +00006816 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006817 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006818
Alexander Duyck943561d2012-05-09 22:14:44 -07006819 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6820 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006821
6822 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006823
6824 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6825 adapter->dcb_cfg.pfc_mode_enable = false;
6826 }
6827
John Fastabend8b1c0b22011-05-03 02:26:48 +00006828 ixgbe_init_interrupt_scheme(adapter);
6829 ixgbe_validate_rtr(adapter, tc);
6830 if (netif_running(dev))
6831 ixgbe_open(dev);
6832
6833 return 0;
6834}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006835
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006836#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006837void ixgbe_do_reset(struct net_device *netdev)
6838{
6839 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6840
6841 if (netif_running(netdev))
6842 ixgbe_reinit_locked(adapter);
6843 else
6844 ixgbe_reset(adapter);
6845}
6846
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006847static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006848 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006849{
6850 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6851
Don Skidmore082757a2011-07-21 05:55:00 +00006852 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006853 if (!(features & NETIF_F_RXCSUM))
6854 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006855
Alexander Duyck567d2de2012-02-11 07:18:57 +00006856 /* Turn off LRO if not RSC capable */
6857 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6858 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006859
Alexander Duyck567d2de2012-02-11 07:18:57 +00006860 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006861}
6862
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006863static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006864 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006865{
6866 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006867 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006868 bool need_reset = false;
6869
Don Skidmore082757a2011-07-21 05:55:00 +00006870 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006871 if (!(features & NETIF_F_LRO)) {
6872 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006873 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006874 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6875 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6876 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6877 if (adapter->rx_itr_setting == 1 ||
6878 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6879 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6880 need_reset = true;
6881 } else if ((changed ^ features) & NETIF_F_LRO) {
6882 e_info(probe, "rx-usecs set too low, "
6883 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006884 }
6885 }
6886
6887 /*
6888 * Check if Flow Director n-tuple support was enabled or disabled. If
6889 * the state changed, we need to reset.
6890 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006891 switch (features & NETIF_F_NTUPLE) {
6892 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00006893 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006894 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6895 need_reset = true;
6896
Alexander Duyck567d2de2012-02-11 07:18:57 +00006897 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6898 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00006899 break;
6900 default:
6901 /* turn off perfect filters, enable ATR and reset */
6902 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6903 need_reset = true;
6904
6905 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6906
6907 /* We cannot enable ATR if SR-IOV is enabled */
6908 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6909 break;
6910
6911 /* We cannot enable ATR if we have 2 or more traffic classes */
6912 if (netdev_get_num_tc(netdev) > 1)
6913 break;
6914
6915 /* We cannot enable ATR if RSS is disabled */
6916 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6917 break;
6918
6919 /* A sample rate of 0 indicates ATR disabled */
6920 if (!adapter->atr_sample_rate)
6921 break;
6922
6923 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6924 break;
Don Skidmore082757a2011-07-21 05:55:00 +00006925 }
6926
John Fastabend146d4cc2012-05-15 05:59:26 +00006927 if (features & NETIF_F_HW_VLAN_RX)
6928 ixgbe_vlan_strip_enable(adapter);
6929 else
6930 ixgbe_vlan_strip_disable(adapter);
6931
Ben Greear3f2d1c02012-03-08 08:28:41 +00006932 if (changed & NETIF_F_RXALL)
6933 need_reset = true;
6934
Alexander Duyck567d2de2012-02-11 07:18:57 +00006935 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006936 if (need_reset)
6937 ixgbe_do_reset(netdev);
6938
6939 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006940}
6941
stephen hemmingeredc7d572012-10-01 12:32:33 +00006942static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006943 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006944 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006945 u16 flags)
6946{
6947 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00006948 int err;
6949
6950 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6951 return -EOPNOTSUPP;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006952
John Fastabendb1ac1ef2012-11-01 05:00:44 +00006953 /* Hardware does not support aging addresses so if a
6954 * ndm_state is given only allow permanent addresses
6955 */
6956 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006957 pr_info("%s: FDB only supports static addresses\n",
6958 ixgbe_driver_name);
6959 return -EINVAL;
6960 }
6961
Ben Hutchings46acc462012-11-01 09:11:11 +00006962 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00006963 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6964
6965 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006966 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006967 else
John Fastabend95447462012-05-31 12:42:26 +00006968 err = -ENOMEM;
6969 } else if (is_multicast_ether_addr(addr)) {
6970 err = dev_mc_add_excl(dev, addr);
6971 } else {
6972 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006973 }
6974
6975 /* Only return duplicate errors if NLM_F_EXCL is set */
6976 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6977 err = 0;
6978
6979 return err;
6980}
6981
6982static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6983 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006984 const unsigned char *addr)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006985{
6986 struct ixgbe_adapter *adapter = netdev_priv(dev);
6987 int err = -EOPNOTSUPP;
6988
6989 if (ndm->ndm_state & NUD_PERMANENT) {
6990 pr_info("%s: FDB only supports static addresses\n",
6991 ixgbe_driver_name);
6992 return -EINVAL;
6993 }
6994
6995 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6996 if (is_unicast_ether_addr(addr))
6997 err = dev_uc_del(dev, addr);
6998 else if (is_multicast_ether_addr(addr))
6999 err = dev_mc_del(dev, addr);
7000 else
7001 err = -EINVAL;
7002 }
7003
7004 return err;
7005}
7006
7007static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7008 struct netlink_callback *cb,
7009 struct net_device *dev,
7010 int idx)
7011{
7012 struct ixgbe_adapter *adapter = netdev_priv(dev);
7013
7014 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7015 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7016
7017 return idx;
7018}
7019
John Fastabend815cccb2012-10-24 08:13:09 +00007020static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7021 struct nlmsghdr *nlh)
7022{
7023 struct ixgbe_adapter *adapter = netdev_priv(dev);
7024 struct nlattr *attr, *br_spec;
7025 int rem;
7026
7027 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7028 return -EOPNOTSUPP;
7029
7030 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7031
7032 nla_for_each_nested(attr, br_spec, rem) {
7033 __u16 mode;
7034 u32 reg = 0;
7035
7036 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7037 continue;
7038
7039 mode = nla_get_u16(attr);
Greg Rose9b735982012-11-08 02:41:35 +00007040 if (mode == BRIDGE_MODE_VEPA) {
John Fastabend815cccb2012-10-24 08:13:09 +00007041 reg = 0;
Greg Rose9b735982012-11-08 02:41:35 +00007042 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7043 } else if (mode == BRIDGE_MODE_VEB) {
John Fastabend815cccb2012-10-24 08:13:09 +00007044 reg = IXGBE_PFDTXGSWC_VT_LBEN;
Greg Rose9b735982012-11-08 02:41:35 +00007045 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7046 } else
John Fastabend815cccb2012-10-24 08:13:09 +00007047 return -EINVAL;
7048
7049 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7050
7051 e_info(drv, "enabling bridge mode: %s\n",
7052 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7053 }
7054
7055 return 0;
7056}
7057
7058static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7059 struct net_device *dev)
7060{
7061 struct ixgbe_adapter *adapter = netdev_priv(dev);
7062 u16 mode;
7063
7064 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7065 return 0;
7066
Greg Rose9b735982012-11-08 02:41:35 +00007067 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
John Fastabend815cccb2012-10-24 08:13:09 +00007068 mode = BRIDGE_MODE_VEB;
7069 else
7070 mode = BRIDGE_MODE_VEPA;
7071
7072 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7073}
7074
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007075static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007076 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007077 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007078 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007079 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007080 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007081 .ndo_validate_addr = eth_validate_addr,
7082 .ndo_set_mac_address = ixgbe_set_mac,
7083 .ndo_change_mtu = ixgbe_change_mtu,
7084 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007085 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7086 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007087 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007088 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7089 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7090 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007091 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007092 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007093 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007094#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007095 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007096#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007097#ifdef CONFIG_NET_POLL_CONTROLLER
7098 .ndo_poll_controller = ixgbe_netpoll,
7099#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007100#ifdef IXGBE_FCOE
7101 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007102 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007103 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007104 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7105 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007106 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007107 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007108#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007109 .ndo_set_features = ixgbe_set_features,
7110 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007111 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7112 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7113 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
John Fastabend815cccb2012-10-24 08:13:09 +00007114 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7115 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007116};
7117
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007118/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007119 * ixgbe_wol_supported - Check whether device supports WoL
7120 * @hw: hw specific details
7121 * @device_id: the device ID
7122 * @subdev_id: the subsystem device ID
7123 *
7124 * This function is used by probe and ethtool to determine
7125 * which devices have WoL support
7126 *
7127 **/
7128int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7129 u16 subdevice_id)
7130{
7131 struct ixgbe_hw *hw = &adapter->hw;
7132 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7133 int is_wol_supported = 0;
7134
7135 switch (device_id) {
7136 case IXGBE_DEV_ID_82599_SFP:
7137 /* Only these subdevices could supports WOL */
7138 switch (subdevice_id) {
7139 case IXGBE_SUBDEV_ID_82599_560FLR:
7140 /* only support first port */
7141 if (hw->bus.func != 0)
7142 break;
7143 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007144 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007145 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007146 is_wol_supported = 1;
7147 break;
7148 }
7149 break;
7150 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7151 /* All except this subdevice support WOL */
7152 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7153 is_wol_supported = 1;
7154 break;
7155 case IXGBE_DEV_ID_82599_KX4:
7156 is_wol_supported = 1;
7157 break;
7158 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007159 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007160 /* check eeprom to see if enabled wol */
7161 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7162 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7163 (hw->bus.func == 0))) {
7164 is_wol_supported = 1;
7165 }
7166 break;
7167 }
7168
7169 return is_wol_supported;
7170}
7171
7172/**
Auke Kok9a799d72007-09-15 14:07:45 -07007173 * ixgbe_probe - Device Initialization Routine
7174 * @pdev: PCI device information struct
7175 * @ent: entry in ixgbe_pci_tbl
7176 *
7177 * Returns 0 on success, negative on failure
7178 *
7179 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7180 * The OS initialization, configuring of the adapter private structure,
7181 * and a hardware reset occur.
7182 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00007183static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007184{
7185 struct net_device *netdev;
7186 struct ixgbe_adapter *adapter = NULL;
7187 struct ixgbe_hw *hw;
7188 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007189 static int cards_found;
7190 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007191 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007192 unsigned int indices = num_possible_cpus();
John Fastabend3f4a6f02012-06-05 05:58:52 +00007193 unsigned int dcb_max = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00007194#ifdef IXGBE_FCOE
7195 u16 device_caps;
7196#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007197 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007198
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007199 /* Catch broken hardware that put the wrong VF device ID in
7200 * the PCIe SR-IOV capability.
7201 */
7202 if (pdev->is_virtfn) {
7203 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7204 pci_name(pdev), pdev->vendor, pdev->device);
7205 return -EINVAL;
7206 }
7207
gouji-new9ce77662009-05-06 10:44:45 +00007208 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007209 if (err)
7210 return err;
7211
Nick Nunley1b507732010-04-27 13:10:27 +00007212 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7213 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007214 pci_using_dac = 1;
7215 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007216 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007217 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007218 err = dma_set_coherent_mask(&pdev->dev,
7219 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007220 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007221 dev_err(&pdev->dev,
7222 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007223 goto err_dma;
7224 }
7225 }
7226 pci_using_dac = 0;
7227 }
7228
gouji-new9ce77662009-05-06 10:44:45 +00007229 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007230 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007231 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007232 dev_err(&pdev->dev,
7233 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007234 goto err_pci_reg;
7235 }
7236
Frans Pop19d5afd2009-10-02 10:04:12 -07007237 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007238
Auke Kok9a799d72007-09-15 14:07:45 -07007239 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007240 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007241
John Fastabende901acd2011-04-26 07:26:08 +00007242#ifdef CONFIG_IXGBE_DCB
John Fastabend3f4a6f02012-06-05 05:58:52 +00007243 if (ii->mac == ixgbe_mac_82598EB)
7244 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7245 IXGBE_MAX_RSS_INDICES);
7246 else
7247 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7248 IXGBE_MAX_FDIR_INDICES);
John Fastabende901acd2011-04-26 07:26:08 +00007249#endif
7250
John Fastabendc85a2612010-02-25 23:15:21 +00007251 if (ii->mac == ixgbe_mac_82598EB)
7252 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7253 else
7254 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7255
John Fastabende901acd2011-04-26 07:26:08 +00007256#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007257 indices += min_t(unsigned int, num_possible_cpus(),
7258 IXGBE_MAX_FCOE_INDICES);
7259#endif
John Fastabend3f4a6f02012-06-05 05:58:52 +00007260 indices = max_t(unsigned int, dcb_max, indices);
John Fastabendc85a2612010-02-25 23:15:21 +00007261 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007262 if (!netdev) {
7263 err = -ENOMEM;
7264 goto err_alloc_etherdev;
7265 }
7266
Auke Kok9a799d72007-09-15 14:07:45 -07007267 SET_NETDEV_DEV(netdev, &pdev->dev);
7268
Auke Kok9a799d72007-09-15 14:07:45 -07007269 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007270 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007271
7272 adapter->netdev = netdev;
7273 adapter->pdev = pdev;
7274 hw = &adapter->hw;
7275 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007276 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007277
Jeff Kirsher05857982008-09-11 19:57:00 -07007278 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007279 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007280 if (!hw->hw_addr) {
7281 err = -EIO;
7282 goto err_ioremap;
7283 }
7284
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007285 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007286 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007287 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007288 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007289
Auke Kok9a799d72007-09-15 14:07:45 -07007290 adapter->bd_number = cards_found;
7291
Auke Kok9a799d72007-09-15 14:07:45 -07007292 /* Setup hw api */
7293 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007294 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007295
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007296 /* EEPROM */
7297 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7298 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7299 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7300 if (!(eec & (1 << 8)))
7301 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7302
7303 /* PHY */
7304 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007305 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007306 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7307 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7308 hw->phy.mdio.mmds = 0;
7309 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7310 hw->phy.mdio.dev = netdev;
7311 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7312 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007313
Don Skidmore8ca783a2009-05-26 20:40:47 -07007314 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007315
7316 /* setup the private structure */
7317 err = ixgbe_sw_init(adapter);
7318 if (err)
7319 goto err_sw_init;
7320
Don Skidmoree86bff02010-02-11 04:14:08 +00007321 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007322 switch (adapter->hw.mac.type) {
7323 case ixgbe_mac_82599EB:
7324 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007325 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007326 break;
7327 default:
7328 break;
7329 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007330
Don Skidmorebf069c92009-05-07 10:39:54 +00007331 /*
7332 * If there is a fan on this device and it has failed log the
7333 * failure.
7334 */
7335 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7336 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7337 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007338 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007339 }
7340
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007341 if (allow_unsupported_sfp)
7342 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7343
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007344 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007345 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007346 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007347 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007348 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7349 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007350 err = 0;
7351 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007352 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007353 "module type was detected.\n");
7354 e_dev_err("Reload the driver after installing a supported "
7355 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007356 goto err_sw_init;
7357 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007358 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007359 goto err_sw_init;
7360 }
7361
Alexander Duyck99d74482012-05-09 08:09:25 +00007362#ifdef CONFIG_PCI_IOV
7363 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007364
Alexander Duyck99d74482012-05-09 08:09:25 +00007365#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007366 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007367 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007368 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007369 NETIF_F_HW_VLAN_TX |
7370 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007371 NETIF_F_HW_VLAN_FILTER |
7372 NETIF_F_TSO |
7373 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007374 NETIF_F_RXHASH |
7375 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007376
Don Skidmore082757a2011-07-21 05:55:00 +00007377 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007378
Don Skidmore58be7662011-04-12 09:42:11 +00007379 switch (adapter->hw.mac.type) {
7380 case ixgbe_mac_82599EB:
7381 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007382 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007383 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7384 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007385 break;
7386 default:
7387 break;
7388 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007389
Ben Greear3f2d1c02012-03-08 08:28:41 +00007390 netdev->hw_features |= NETIF_F_RXALL;
7391
Jeff Kirsherad31c402008-06-05 04:05:30 -07007392 netdev->vlan_features |= NETIF_F_TSO;
7393 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007394 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007395 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007396 netdev->vlan_features |= NETIF_F_SG;
7397
Jiri Pirko01789342011-08-16 06:29:00 +00007398 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007399 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007400
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007401#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007402 netdev->dcbnl_ops = &dcbnl_ops;
7403#endif
7404
Yi Zoueacd73f2009-05-13 13:11:06 +00007405#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007406 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007407 if (hw->mac.ops.get_device_caps) {
7408 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007409 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7410 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007411 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007412
7413 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7414
Alexander Duycka58915c2012-05-25 06:38:18 +00007415 netdev->features |= NETIF_F_FSO |
7416 NETIF_F_FCOE_CRC;
7417
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007418 netdev->vlan_features |= NETIF_F_FSO |
7419 NETIF_F_FCOE_CRC |
7420 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007421 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007422#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007423 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007424 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007425 netdev->vlan_features |= NETIF_F_HIGHDMA;
7426 }
Auke Kok9a799d72007-09-15 14:07:45 -07007427
Don Skidmore082757a2011-07-21 05:55:00 +00007428 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7429 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007430 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007431 netdev->features |= NETIF_F_LRO;
7432
Auke Kok9a799d72007-09-15 14:07:45 -07007433 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007434 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007435 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007436 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007437 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007438 }
7439
7440 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007441
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00007442 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007443 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007444 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007445 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007446 }
7447
Alexander Duyck70864002011-04-27 09:13:56 +00007448 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007449 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007450
Alexander Duyck70864002011-04-27 09:13:56 +00007451 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7452 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007453
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007454 err = ixgbe_init_interrupt_scheme(adapter);
7455 if (err)
7456 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007457
Jacob Keller8e2813f2012-04-21 06:05:40 +00007458 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007459 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007460 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7461 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007462 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007463
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007464 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7465
Emil Tantilov15e52092011-09-29 05:01:29 +00007466 /* save off EEPROM version number */
7467 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7468 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7469
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007470 /* pick up the PCI bus settings for reporting later */
7471 hw->mac.ops.get_bus_info(hw);
7472
Auke Kok9a799d72007-09-15 14:07:45 -07007473 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007474 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007475 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7476 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007477 "Unknown"),
7478 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7479 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7480 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7481 "Unknown"),
7482 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007483
7484 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7485 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007486 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007487 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007488 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007489 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007490 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007491 else
Don Skidmore289700db2010-12-03 03:32:58 +00007492 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7493 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007494
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007495 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007496 e_dev_warn("PCI-Express bandwidth available for this card is "
7497 "not sufficient for optimal performance.\n");
7498 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7499 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007500 }
7501
Auke Kok9a799d72007-09-15 14:07:45 -07007502 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007503 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007504 if (err == IXGBE_ERR_EEPROM_VERSION) {
7505 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007506 e_dev_warn("This device is a pre-production adapter/LOM. "
7507 "Please be aware there may be issues associated "
7508 "with your hardware. If you are experiencing "
7509 "problems please contact your Intel or hardware "
7510 "representative who provided you with this "
7511 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007512 }
Auke Kok9a799d72007-09-15 14:07:45 -07007513 strcpy(netdev->name, "eth%d");
7514 err = register_netdev(netdev);
7515 if (err)
7516 goto err_register;
7517
Emil Tantilovec74a472012-09-20 03:33:56 +00007518 /* power down the optics for 82599 SFP+ fiber */
7519 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007520 hw->mac.ops.disable_tx_laser(hw);
7521
Jesse Brandeburg54386462009-04-17 20:44:27 +00007522 /* carrier off reporting is important to ethtool even BEFORE open */
7523 netif_carrier_off(netdev);
7524
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007525#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007526 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007527 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007528 ixgbe_setup_dca(adapter);
7529 }
7530#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007531 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007532 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007533 for (i = 0; i < adapter->num_vfs; i++)
7534 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7535 }
7536
Jacob Keller2466dd92011-09-08 03:50:54 +00007537 /* firmware requires driver version to be 0xFFFFFFFF
7538 * since os does not support feature
7539 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007540 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007541 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7542 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007543
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007544 /* add san mac addr to netdev */
7545 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007546
Neerav Parikhea818752012-01-04 20:23:40 +00007547 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007548 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007549
Don Skidmore12109822012-05-04 06:07:08 +00007550#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007551 if (ixgbe_sysfs_init(adapter))
7552 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007553#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007554
Catherine Sullivan00949162012-08-10 01:59:10 +00007555#ifdef CONFIG_DEBUG_FS
7556 ixgbe_dbg_adapter_init(adapter);
7557#endif /* CONFIG_DEBUG_FS */
7558
Auke Kok9a799d72007-09-15 14:07:45 -07007559 return 0;
7560
7561err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007562 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007563 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007564err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007565 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007566 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007567 iounmap(hw->hw_addr);
7568err_ioremap:
7569 free_netdev(netdev);
7570err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007571 pci_release_selected_regions(pdev,
7572 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007573err_pci_reg:
7574err_dma:
7575 pci_disable_device(pdev);
7576 return err;
7577}
7578
7579/**
7580 * ixgbe_remove - Device Removal Routine
7581 * @pdev: PCI device information struct
7582 *
7583 * ixgbe_remove is called by the PCI subsystem to alert the driver
7584 * that it should release a PCI device. The could be caused by a
7585 * Hot-Plug event, or because the driver is going to be removed from
7586 * memory.
7587 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007588static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007589{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007590 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7591 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007592
Catherine Sullivan00949162012-08-10 01:59:10 +00007593#ifdef CONFIG_DEBUG_FS
7594 ixgbe_dbg_adapter_exit(adapter);
7595#endif /*CONFIG_DEBUG_FS */
7596
Auke Kok9a799d72007-09-15 14:07:45 -07007597 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007598 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007599
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007600
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007601#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007602 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7603 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7604 dca_remove_requester(&pdev->dev);
7605 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7606 }
7607
7608#endif
Don Skidmore12109822012-05-04 06:07:08 +00007609#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007610 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007611#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007612
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007613 /* remove the added san mac */
7614 ixgbe_del_sanmac_netdev(netdev);
7615
Donald Skidmorec4900be2008-11-20 21:11:42 -08007616 if (netdev->reg_state == NETREG_REGISTERED)
7617 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007618
Alexander Duyck92971272012-05-23 02:58:40 +00007619 ixgbe_disable_sriov(adapter);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007620
Alexander Duyck7a921c92009-05-06 10:43:28 +00007621 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007622
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007623 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007624
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007625#ifdef CONFIG_DCB
7626 kfree(adapter->ixgbe_ieee_pfc);
7627 kfree(adapter->ixgbe_ieee_ets);
7628
7629#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007630 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007631 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007632 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007633
Emil Tantilov849c4542010-06-03 16:53:41 +00007634 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007635
Auke Kok9a799d72007-09-15 14:07:45 -07007636 free_netdev(netdev);
7637
Frans Pop19d5afd2009-10-02 10:04:12 -07007638 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007639
Auke Kok9a799d72007-09-15 14:07:45 -07007640 pci_disable_device(pdev);
7641}
7642
7643/**
7644 * ixgbe_io_error_detected - called when PCI error is detected
7645 * @pdev: Pointer to PCI device
7646 * @state: The current pci connection state
7647 *
7648 * This function is called after a PCI bus error affecting
7649 * this device has been detected.
7650 */
7651static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007652 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007653{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007654 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7655 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007656
Greg Rose83c61fa2011-09-07 05:59:35 +00007657#ifdef CONFIG_PCI_IOV
7658 struct pci_dev *bdev, *vfdev;
7659 u32 dw0, dw1, dw2, dw3;
7660 int vf, pos;
7661 u16 req_id, pf_func;
7662
7663 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7664 adapter->num_vfs == 0)
7665 goto skip_bad_vf_detection;
7666
7667 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007668 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007669 bdev = bdev->bus->self;
7670
7671 if (!bdev)
7672 goto skip_bad_vf_detection;
7673
7674 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7675 if (!pos)
7676 goto skip_bad_vf_detection;
7677
7678 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7679 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7680 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7681 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7682
7683 req_id = dw1 >> 16;
7684 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7685 if (!(req_id & 0x0080))
7686 goto skip_bad_vf_detection;
7687
7688 pf_func = req_id & 0x01;
7689 if ((pf_func & 1) == (pdev->devfn & 1)) {
7690 unsigned int device_id;
7691
7692 vf = (req_id & 0x7F) >> 1;
7693 e_dev_err("VF %d has caused a PCIe error\n", vf);
7694 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7695 "%8.8x\tdw3: %8.8x\n",
7696 dw0, dw1, dw2, dw3);
7697 switch (adapter->hw.mac.type) {
7698 case ixgbe_mac_82599EB:
7699 device_id = IXGBE_82599_VF_DEVICE_ID;
7700 break;
7701 case ixgbe_mac_X540:
7702 device_id = IXGBE_X540_VF_DEVICE_ID;
7703 break;
7704 default:
7705 device_id = 0;
7706 break;
7707 }
7708
7709 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007710 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007711 while (vfdev) {
7712 if (vfdev->devfn == (req_id & 0xFF))
7713 break;
Jon Mason36e90312012-07-19 21:02:09 +00007714 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007715 device_id, vfdev);
7716 }
7717 /*
7718 * There's a slim chance the VF could have been hot plugged,
7719 * so if it is no longer present we don't need to issue the
7720 * VFLR. Just clean up the AER in that case.
7721 */
7722 if (vfdev) {
7723 e_dev_err("Issuing VFLR to VF %d\n", vf);
7724 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7725 }
7726
7727 pci_cleanup_aer_uncorrect_error_status(pdev);
7728 }
7729
7730 /*
7731 * Even though the error may have occurred on the other port
7732 * we still need to increment the vf error reference count for
7733 * both ports because the I/O resume function will be called
7734 * for both of them.
7735 */
7736 adapter->vferr_refcount++;
7737
7738 return PCI_ERS_RESULT_RECOVERED;
7739
7740skip_bad_vf_detection:
7741#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007742 netif_device_detach(netdev);
7743
Breno Leitao3044b8d2009-05-06 10:44:26 +00007744 if (state == pci_channel_io_perm_failure)
7745 return PCI_ERS_RESULT_DISCONNECT;
7746
Auke Kok9a799d72007-09-15 14:07:45 -07007747 if (netif_running(netdev))
7748 ixgbe_down(adapter);
7749 pci_disable_device(pdev);
7750
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007751 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007752 return PCI_ERS_RESULT_NEED_RESET;
7753}
7754
7755/**
7756 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7757 * @pdev: Pointer to PCI device
7758 *
7759 * Restart the card from scratch, as if from a cold-boot.
7760 */
7761static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7762{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007763 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007764 pci_ers_result_t result;
7765 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007766
gouji-new9ce77662009-05-06 10:44:45 +00007767 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007768 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007769 result = PCI_ERS_RESULT_DISCONNECT;
7770 } else {
7771 pci_set_master(pdev);
7772 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007773 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007774
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007775 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007776
7777 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007778 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007779 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007780 }
Auke Kok9a799d72007-09-15 14:07:45 -07007781
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007782 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7783 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007784 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7785 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007786 /* non-fatal, continue */
7787 }
Auke Kok9a799d72007-09-15 14:07:45 -07007788
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007789 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007790}
7791
7792/**
7793 * ixgbe_io_resume - called when traffic can start flowing again.
7794 * @pdev: Pointer to PCI device
7795 *
7796 * This callback is called when the error recovery driver tells us that
7797 * its OK to resume normal operation.
7798 */
7799static void ixgbe_io_resume(struct pci_dev *pdev)
7800{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007801 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7802 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007803
Greg Rose83c61fa2011-09-07 05:59:35 +00007804#ifdef CONFIG_PCI_IOV
7805 if (adapter->vferr_refcount) {
7806 e_info(drv, "Resuming after VF err\n");
7807 adapter->vferr_refcount--;
7808 return;
7809 }
7810
7811#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007812 if (netif_running(netdev))
7813 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007814
7815 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007816}
7817
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007818static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007819 .error_detected = ixgbe_io_error_detected,
7820 .slot_reset = ixgbe_io_slot_reset,
7821 .resume = ixgbe_io_resume,
7822};
7823
7824static struct pci_driver ixgbe_driver = {
7825 .name = ixgbe_driver_name,
7826 .id_table = ixgbe_pci_tbl,
7827 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05007828 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -07007829#ifdef CONFIG_PM
7830 .suspend = ixgbe_suspend,
7831 .resume = ixgbe_resume,
7832#endif
7833 .shutdown = ixgbe_shutdown,
7834 .err_handler = &ixgbe_err_handler
7835};
7836
7837/**
7838 * ixgbe_init_module - Driver Registration Routine
7839 *
7840 * ixgbe_init_module is the first routine called when the driver is
7841 * loaded. All it does is register with the PCI subsystem.
7842 **/
7843static int __init ixgbe_init_module(void)
7844{
7845 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007846 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007847 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007848
Catherine Sullivan00949162012-08-10 01:59:10 +00007849#ifdef CONFIG_DEBUG_FS
7850 ixgbe_dbg_init();
7851#endif /* CONFIG_DEBUG_FS */
7852
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007853#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007854 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007855#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007856
Auke Kok9a799d72007-09-15 14:07:45 -07007857 ret = pci_register_driver(&ixgbe_driver);
7858 return ret;
7859}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007860
Auke Kok9a799d72007-09-15 14:07:45 -07007861module_init(ixgbe_init_module);
7862
7863/**
7864 * ixgbe_exit_module - Driver Exit Cleanup Routine
7865 *
7866 * ixgbe_exit_module is called just before the driver is removed
7867 * from memory.
7868 **/
7869static void __exit ixgbe_exit_module(void)
7870{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007871#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007872 dca_unregister_notify(&dca_notifier);
7873#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007874 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00007875
7876#ifdef CONFIG_DEBUG_FS
7877 ixgbe_dbg_exit();
7878#endif /* CONFIG_DEBUG_FS */
7879
Eric Dumazet1a515022010-11-16 19:26:42 -08007880 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007881}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007882
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007883#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007884static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007885 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007886{
7887 int ret_val;
7888
7889 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007890 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007891
7892 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7893}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007894
Alexander Duyckb4533682009-03-31 21:32:42 +00007895#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007896
Auke Kok9a799d72007-09-15 14:07:45 -07007897module_exit(ixgbe_exit_module);
7898
7899/* ixgbe_main.c */