blob: 9a88e01216bb3cd57db6b1c08c20ea43025e0997 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000047#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000049#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070050
51#include "ixgbe.h"
52#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000053#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000054#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070055
56char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070057static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000058 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000059#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000060char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000062#else
63static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
65#endif
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000066#define MAJ 3
Don Skidmoreeef45602012-04-28 03:29:22 +000067#define MIN 9
68#define BUILD 15
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000069#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000070 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070071const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000072static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000073 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070074
75static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070076 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000077 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080078 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070079};
80
81/* ixgbe_pci_tbl - PCI Device ID Table
82 *
83 * Wildcard entries (PCI_ANY_ID) should come last
84 * Last entry must be all 0s
85 *
86 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
87 * Class, Class Mask, private data (not used) }
88 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000089static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700119 /* required last entry */
120 {0, }
121};
122MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
123
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400124#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800125static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000126 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800127static struct notifier_block dca_notifier = {
128 .notifier_call = ixgbe_notify_dca,
129 .next = NULL,
130 .priority = 0
131};
132#endif
133
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000134#ifdef CONFIG_PCI_IOV
135static unsigned int max_vfs;
136module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000137MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000138 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000139#endif /* CONFIG_PCI_IOV */
140
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000141static unsigned int allow_unsupported_sfp;
142module_param(allow_unsupported_sfp, uint, 0);
143MODULE_PARM_DESC(allow_unsupported_sfp,
144 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
145
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000146#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
147static int debug = -1;
148module_param(debug, int, 0);
149MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
150
Auke Kok9a799d72007-09-15 14:07:45 -0700151MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
152MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
153MODULE_LICENSE("GPL");
154MODULE_VERSION(DRV_VERSION);
155
Alexander Duyck70864002011-04-27 09:13:56 +0000156static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
157{
158 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
159 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
160 schedule_work(&adapter->service_task);
161}
162
163static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
164{
165 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
166
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000167 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000168 smp_mb__before_clear_bit();
169 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
170}
171
Taku Izumidcd79ae2010-04-27 14:39:53 +0000172struct ixgbe_reg_info {
173 u32 ofs;
174 char *name;
175};
176
177static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
178
179 /* General Registers */
180 {IXGBE_CTRL, "CTRL"},
181 {IXGBE_STATUS, "STATUS"},
182 {IXGBE_CTRL_EXT, "CTRL_EXT"},
183
184 /* Interrupt Registers */
185 {IXGBE_EICR, "EICR"},
186
187 /* RX Registers */
188 {IXGBE_SRRCTL(0), "SRRCTL"},
189 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
190 {IXGBE_RDLEN(0), "RDLEN"},
191 {IXGBE_RDH(0), "RDH"},
192 {IXGBE_RDT(0), "RDT"},
193 {IXGBE_RXDCTL(0), "RXDCTL"},
194 {IXGBE_RDBAL(0), "RDBAL"},
195 {IXGBE_RDBAH(0), "RDBAH"},
196
197 /* TX Registers */
198 {IXGBE_TDBAL(0), "TDBAL"},
199 {IXGBE_TDBAH(0), "TDBAH"},
200 {IXGBE_TDLEN(0), "TDLEN"},
201 {IXGBE_TDH(0), "TDH"},
202 {IXGBE_TDT(0), "TDT"},
203 {IXGBE_TXDCTL(0), "TXDCTL"},
204
205 /* List Terminator */
206 {}
207};
208
209
210/*
211 * ixgbe_regdump - register printout routine
212 */
213static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
214{
215 int i = 0, j = 0;
216 char rname[16];
217 u32 regs[64];
218
219 switch (reginfo->ofs) {
220 case IXGBE_SRRCTL(0):
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
223 break;
224 case IXGBE_DCA_RXCTRL(0):
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
227 break;
228 case IXGBE_RDLEN(0):
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
231 break;
232 case IXGBE_RDH(0):
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
235 break;
236 case IXGBE_RDT(0):
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
239 break;
240 case IXGBE_RXDCTL(0):
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
243 break;
244 case IXGBE_RDBAL(0):
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
247 break;
248 case IXGBE_RDBAH(0):
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
251 break;
252 case IXGBE_TDBAL(0):
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
255 break;
256 case IXGBE_TDBAH(0):
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
259 break;
260 case IXGBE_TDLEN(0):
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
263 break;
264 case IXGBE_TDH(0):
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
267 break;
268 case IXGBE_TDT(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
271 break;
272 case IXGBE_TXDCTL(0):
273 for (i = 0; i < 64; i++)
274 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
275 break;
276 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000277 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 IXGBE_READ_REG(hw, reginfo->ofs));
279 return;
280 }
281
282 for (i = 0; i < 8; i++) {
283 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000284 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000285 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000286 pr_cont(" %08x", regs[i*8+j]);
287 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000288 }
289
290}
291
292/*
293 * ixgbe_dump - Print registers, tx-rings and rx-rings
294 */
295static void ixgbe_dump(struct ixgbe_adapter *adapter)
296{
297 struct net_device *netdev = adapter->netdev;
298 struct ixgbe_hw *hw = &adapter->hw;
299 struct ixgbe_reg_info *reginfo;
300 int n = 0;
301 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000302 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000303 union ixgbe_adv_tx_desc *tx_desc;
304 struct my_u0 { u64 a; u64 b; } *u0;
305 struct ixgbe_ring *rx_ring;
306 union ixgbe_adv_rx_desc *rx_desc;
307 struct ixgbe_rx_buffer *rx_buffer_info;
308 u32 staterr;
309 int i = 0;
310
311 if (!netif_msg_hw(adapter))
312 return;
313
314 /* Print netdevice Info */
315 if (netdev) {
316 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000317 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000318 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000319 pr_info("%-15s %016lX %016lX %016lX\n",
320 netdev->name,
321 netdev->state,
322 netdev->trans_start,
323 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000324 }
325
326 /* Print Registers */
327 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000328 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000329 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
330 reginfo->name; reginfo++) {
331 ixgbe_regdump(hw, reginfo);
332 }
333
334 /* Print TX Ring Summary */
335 if (!netdev || !netif_running(netdev))
336 goto exit;
337
338 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000339 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000340 for (n = 0; n < adapter->num_tx_queues; n++) {
341 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000342 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000343 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000344 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000345 (u64)dma_unmap_addr(tx_buffer, dma),
346 dma_unmap_len(tx_buffer, len),
347 tx_buffer->next_to_watch,
348 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000349 }
350
351 /* Print TX Rings */
352 if (!netif_msg_tx_done(adapter))
353 goto rx_ring_summary;
354
355 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
356
357 /* Transmit Descriptor Formats
358 *
359 * Advanced Transmit Descriptor
360 * +--------------------------------------------------------------+
361 * 0 | Buffer Address [63:0] |
362 * +--------------------------------------------------------------+
363 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
364 * +--------------------------------------------------------------+
365 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
366 */
367
368 for (n = 0; n < adapter->num_tx_queues; n++) {
369 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000370 pr_info("------------------------------------\n");
371 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
372 pr_info("------------------------------------\n");
373 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000374 "[PlPOIdStDDt Ln] [bi->dma ] "
375 "leng ntw timestamp bi->skb\n");
376
377 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000378 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000379 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000380 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000381 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000382 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000383 le64_to_cpu(u0->a),
384 le64_to_cpu(u0->b),
Alexander Duyck729739b2012-02-08 07:51:06 +0000385 (u64)dma_unmap_addr(tx_buffer, dma),
386 dma_unmap_len(tx_buffer, len),
387 tx_buffer->next_to_watch,
388 (u64)tx_buffer->time_stamp,
389 tx_buffer->skb);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000390 if (i == tx_ring->next_to_use &&
391 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000392 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000393 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000394 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000395 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000396 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000397 else
Joe Perchesc7689572010-09-07 21:35:17 +0000398 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000399
400 if (netif_msg_pktdata(adapter) &&
Emil Tantilov9c50c032012-07-26 01:21:24 +0000401 tx_buffer->skb)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000402 print_hex_dump(KERN_INFO, "",
403 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000404 tx_buffer->skb->data,
Alexander Duyck729739b2012-02-08 07:51:06 +0000405 dma_unmap_len(tx_buffer, len),
406 true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000407 }
408 }
409
410 /* Print RX Rings Summary */
411rx_ring_summary:
412 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000413 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000414 for (n = 0; n < adapter->num_rx_queues; n++) {
415 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000416 pr_info("%5d %5X %5X\n",
417 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000418 }
419
420 /* Print RX Rings */
421 if (!netif_msg_rx_status(adapter))
422 goto exit;
423
424 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
425
426 /* Advanced Receive Descriptor (Read) Format
427 * 63 1 0
428 * +-----------------------------------------------------+
429 * 0 | Packet Buffer Address [63:1] |A0/NSE|
430 * +----------------------------------------------+------+
431 * 8 | Header Buffer Address [63:1] | DD |
432 * +-----------------------------------------------------+
433 *
434 *
435 * Advanced Receive Descriptor (Write-Back) Format
436 *
437 * 63 48 47 32 31 30 21 20 16 15 4 3 0
438 * +------------------------------------------------------+
439 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
440 * | Checksum Ident | | | | Type | Type |
441 * +------------------------------------------------------+
442 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
443 * +------------------------------------------------------+
444 * 63 48 47 32 31 20 19 0
445 */
446 for (n = 0; n < adapter->num_rx_queues; n++) {
447 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000448 pr_info("------------------------------------\n");
449 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
450 pr_info("------------------------------------\n");
451 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000452 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
453 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000454 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000455 "[vl er S cks ln] ---------------- [bi->skb] "
456 "<-- Adv Rx Write-Back format\n");
457
458 for (i = 0; i < rx_ring->count; i++) {
459 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000460 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000461 u0 = (struct my_u0 *)rx_desc;
462 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
463 if (staterr & IXGBE_RXD_STAT_DD) {
464 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000465 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000466 "%016llX ---------------- %p", i,
467 le64_to_cpu(u0->a),
468 le64_to_cpu(u0->b),
469 rx_buffer_info->skb);
470 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000471 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000472 "%016llX %016llX %p", i,
473 le64_to_cpu(u0->a),
474 le64_to_cpu(u0->b),
475 (u64)rx_buffer_info->dma,
476 rx_buffer_info->skb);
477
Emil Tantilov9c50c032012-07-26 01:21:24 +0000478 if (netif_msg_pktdata(adapter) &&
479 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000480 print_hex_dump(KERN_INFO, "",
481 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000482 page_address(rx_buffer_info->page) +
483 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000484 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000485 }
486 }
487
488 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000489 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000490 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000491 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000492 else
Joe Perchesc7689572010-09-07 21:35:17 +0000493 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000494
495 }
496 }
497
498exit:
499 return;
500}
501
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800502static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
503{
504 u32 ctrl_ext;
505
506 /* Let firmware take over control of h/w */
507 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
508 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000509 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800510}
511
512static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
513{
514 u32 ctrl_ext;
515
516 /* Let firmware know the driver has taken over */
517 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
518 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000519 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800520}
Auke Kok9a799d72007-09-15 14:07:45 -0700521
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000522/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000523 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
524 * @adapter: pointer to adapter struct
525 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
526 * @queue: queue to map the corresponding interrupt to
527 * @msix_vector: the vector to map to the corresponding queue
528 *
529 */
530static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000531 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700532{
533 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000534 struct ixgbe_hw *hw = &adapter->hw;
535 switch (hw->mac.type) {
536 case ixgbe_mac_82598EB:
537 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
538 if (direction == -1)
539 direction = 0;
540 index = (((direction * 64) + queue) >> 2) & 0x1F;
541 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
542 ivar &= ~(0xFF << (8 * (queue & 0x3)));
543 ivar |= (msix_vector << (8 * (queue & 0x3)));
544 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
545 break;
546 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800547 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000548 if (direction == -1) {
549 /* other causes */
550 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
551 index = ((queue & 1) * 8);
552 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
553 ivar &= ~(0xFF << index);
554 ivar |= (msix_vector << index);
555 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
556 break;
557 } else {
558 /* tx or rx causes */
559 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
560 index = ((16 * (queue & 1)) + (8 * direction));
561 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
562 ivar &= ~(0xFF << index);
563 ivar |= (msix_vector << index);
564 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
565 break;
566 }
567 default:
568 break;
569 }
Auke Kok9a799d72007-09-15 14:07:45 -0700570}
571
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000573 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000574{
575 u32 mask;
576
Alexander Duyckbd508172010-11-16 19:27:03 -0800577 switch (adapter->hw.mac.type) {
578 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000579 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
580 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800581 break;
582 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800583 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000584 mask = (qmask & 0xFFFFFFFF);
585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
586 mask = (qmask >> 32);
587 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800588 break;
589 default:
590 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000591 }
592}
593
Alexander Duyck729739b2012-02-08 07:51:06 +0000594void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
595 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000596{
Alexander Duyck729739b2012-02-08 07:51:06 +0000597 if (tx_buffer->skb) {
598 dev_kfree_skb_any(tx_buffer->skb);
599 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000600 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000601 dma_unmap_addr(tx_buffer, dma),
602 dma_unmap_len(tx_buffer, len),
603 DMA_TO_DEVICE);
604 } else if (dma_unmap_len(tx_buffer, len)) {
605 dma_unmap_page(ring->dev,
606 dma_unmap_addr(tx_buffer, dma),
607 dma_unmap_len(tx_buffer, len),
608 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000609 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000610 tx_buffer->next_to_watch = NULL;
611 tx_buffer->skb = NULL;
612 dma_unmap_len_set(tx_buffer, len, 0);
613 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700614}
615
Alexander Duyck943561d2012-05-09 22:14:44 -0700616static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
617{
618 struct ixgbe_hw *hw = &adapter->hw;
619 struct ixgbe_hw_stats *hwstats = &adapter->stats;
620 int i;
621 u32 data;
622
623 if ((hw->fc.current_mode != ixgbe_fc_full) &&
624 (hw->fc.current_mode != ixgbe_fc_rx_pause))
625 return;
626
627 switch (hw->mac.type) {
628 case ixgbe_mac_82598EB:
629 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
630 break;
631 default:
632 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
633 }
634 hwstats->lxoffrxc += data;
635
636 /* refill credits (no tx hang) if we received xoff */
637 if (!data)
638 return;
639
640 for (i = 0; i < adapter->num_tx_queues; i++)
641 clear_bit(__IXGBE_HANG_CHECK_ARMED,
642 &adapter->tx_ring[i]->state);
643}
644
John Fastabendc84d3242010-11-16 19:27:12 -0800645static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700646{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700647 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800648 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800649 u32 xoff[8] = {0};
650 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700651 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700652
Alexander Duyck943561d2012-05-09 22:14:44 -0700653 if (adapter->ixgbe_ieee_pfc)
654 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800655
Alexander Duyck943561d2012-05-09 22:14:44 -0700656 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
657 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800658 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700659 }
John Fastabendc84d3242010-11-16 19:27:12 -0800660
661 /* update stats for each tc, only valid with PFC enabled */
662 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
663 switch (hw->mac.type) {
664 case ixgbe_mac_82598EB:
665 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
666 break;
667 default:
668 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
669 }
670 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700671 }
672
John Fastabendc84d3242010-11-16 19:27:12 -0800673 /* disarm tx queues that have received xoff frames */
674 for (i = 0; i < adapter->num_tx_queues; i++) {
675 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000676 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800677
678 if (xoff[tc])
679 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
680 }
681}
682
683static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
684{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000685 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800686}
687
688static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
689{
690 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
691 struct ixgbe_hw *hw = &adapter->hw;
692
693 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
694 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
695
696 if (head != tail)
697 return (head < tail) ?
698 tail - head : (tail + ring->count - head);
699
700 return 0;
701}
702
703static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
704{
705 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
706 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
707 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
708 bool ret = false;
709
710 clear_check_for_tx_hang(tx_ring);
711
712 /*
713 * Check for a hung queue, but be thorough. This verifies
714 * that a transmit has been completed since the previous
715 * check AND there is at least one packet pending. The
716 * ARMED bit is set to indicate a potential hang. The
717 * bit is cleared if a pause frame is received to remove
718 * false hang detection due to PFC or 802.3x frames. By
719 * requiring this to fail twice we avoid races with
720 * pfc clearing the ARMED bit and conditions where we
721 * run the check_tx_hang logic with a transmit completion
722 * pending but without time to complete it yet.
723 */
724 if ((tx_done_old == tx_done) && tx_pending) {
725 /* make sure it is true for two checks in a row */
726 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
727 &tx_ring->state);
728 } else {
729 /* update completed stats and continue */
730 tx_ring->tx_stats.tx_done_old = tx_done;
731 /* reset the countdown */
732 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
733 }
734
735 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700736}
737
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000738/**
739 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
740 * @adapter: driver private struct
741 **/
742static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
743{
744
745 /* Do the reset outside of interrupt context */
746 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
747 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
748 ixgbe_service_event_schedule(adapter);
749 }
750}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700751
Auke Kok9a799d72007-09-15 14:07:45 -0700752/**
753 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000754 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700755 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700756 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000757static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000758 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700759{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000760 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000761 struct ixgbe_tx_buffer *tx_buffer;
762 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700763 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000764 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000765 unsigned int i = tx_ring->next_to_clean;
766
767 if (test_bit(__IXGBE_DOWN, &adapter->state))
768 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700769
Alexander Duyckd3d00232011-07-15 02:31:25 +0000770 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000771 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000772 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800773
Alexander Duyck729739b2012-02-08 07:51:06 +0000774 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000775 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700776
Alexander Duyckd3d00232011-07-15 02:31:25 +0000777 /* if next_to_watch is not set then there is no work pending */
778 if (!eop_desc)
779 break;
780
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000781 /* prevent any other reads prior to eop_desc */
782 rmb();
783
Alexander Duyckd3d00232011-07-15 02:31:25 +0000784 /* if DD is not set pending work has not been completed */
785 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
786 break;
787
Alexander Duyckd3d00232011-07-15 02:31:25 +0000788 /* clear next_to_watch to prevent false hangs */
789 tx_buffer->next_to_watch = NULL;
790
Alexander Duyck091a6242012-02-08 07:51:01 +0000791 /* update the statistics for this packet */
792 total_bytes += tx_buffer->bytecount;
793 total_packets += tx_buffer->gso_segs;
794
Jacob Keller3a6a4ed2012-05-01 05:24:58 +0000795#ifdef CONFIG_IXGBE_PTP
Jacob Keller0ede4a62012-05-22 06:08:32 +0000796 if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP))
797 ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +0000798#endif
Jacob Keller0ede4a62012-05-22 06:08:32 +0000799
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000800 /* free the skb */
801 dev_kfree_skb_any(tx_buffer->skb);
802
Alexander Duyck729739b2012-02-08 07:51:06 +0000803 /* unmap skb header data */
804 dma_unmap_single(tx_ring->dev,
805 dma_unmap_addr(tx_buffer, dma),
806 dma_unmap_len(tx_buffer, len),
807 DMA_TO_DEVICE);
808
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000809 /* clear tx_buffer data */
810 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000811 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000812
Alexander Duyck729739b2012-02-08 07:51:06 +0000813 /* unmap remaining buffers */
814 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000815 tx_buffer++;
816 tx_desc++;
817 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000818 if (unlikely(!i)) {
819 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000820 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000821 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000822 }
823
Alexander Duyck729739b2012-02-08 07:51:06 +0000824 /* unmap any remaining paged data */
825 if (dma_unmap_len(tx_buffer, len)) {
826 dma_unmap_page(tx_ring->dev,
827 dma_unmap_addr(tx_buffer, dma),
828 dma_unmap_len(tx_buffer, len),
829 DMA_TO_DEVICE);
830 dma_unmap_len_set(tx_buffer, len, 0);
831 }
832 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800833
Alexander Duyck729739b2012-02-08 07:51:06 +0000834 /* move us one more past the eop_desc for start of next pkt */
835 tx_buffer++;
836 tx_desc++;
837 i++;
838 if (unlikely(!i)) {
839 i -= tx_ring->count;
840 tx_buffer = tx_ring->tx_buffer_info;
841 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
842 }
843
844 /* issue prefetch for next Tx descriptor */
845 prefetch(tx_desc);
846
847 /* update budget accounting */
848 budget--;
849 } while (likely(budget));
850
851 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700852 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000853 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800854 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000855 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000856 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000857 q_vector->tx.total_bytes += total_bytes;
858 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800859
John Fastabendc84d3242010-11-16 19:27:12 -0800860 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800861 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800862 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800863 e_err(drv, "Detected Tx Unit Hang\n"
864 " Tx Queue <%d>\n"
865 " TDH, TDT <%x>, <%x>\n"
866 " next_to_use <%x>\n"
867 " next_to_clean <%x>\n"
868 "tx_buffer_info[next_to_clean]\n"
869 " time_stamp <%lx>\n"
870 " jiffies <%lx>\n",
871 tx_ring->queue_index,
872 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
873 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000874 tx_ring->next_to_use, i,
875 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800876
877 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
878
879 e_info(probe,
880 "tx hang %d detected on queue %d, resetting adapter\n",
881 adapter->tx_timeout_count + 1, tx_ring->queue_index);
882
883 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000884 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800885
886 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000887 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800888 }
Auke Kok9a799d72007-09-15 14:07:45 -0700889
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000890 netdev_tx_completed_queue(txring_txq(tx_ring),
891 total_packets, total_bytes);
892
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800893#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000894 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000895 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800896 /* Make sure that anybody stopping the queue after this
897 * sees the new next_to_clean.
898 */
899 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000900 if (__netif_subqueue_stopped(tx_ring->netdev,
901 tx_ring->queue_index)
902 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
903 netif_wake_subqueue(tx_ring->netdev,
904 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800905 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800906 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800907 }
Auke Kok9a799d72007-09-15 14:07:45 -0700908
Alexander Duyck59224552011-08-31 00:01:06 +0000909 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700910}
911
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400912#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800913static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800914 struct ixgbe_ring *tx_ring,
915 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800916{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000917 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000918 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
919 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800920
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800921 switch (hw->mac.type) {
922 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000923 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800924 break;
925 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800926 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000927 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
928 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
929 break;
930 default:
931 /* for unknown hardware do not write register */
932 return;
933 }
934
935 /*
936 * We can enable relaxed ordering for reads, but not writes when
937 * DCA is enabled. This is due to a known issue in some chipsets
938 * which will cause the DCA tag to be cleared.
939 */
940 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
941 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
942 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
943
944 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
945}
946
947static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
948 struct ixgbe_ring *rx_ring,
949 int cpu)
950{
951 struct ixgbe_hw *hw = &adapter->hw;
952 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
953 u8 reg_idx = rx_ring->reg_idx;
954
955
956 switch (hw->mac.type) {
957 case ixgbe_mac_82599EB:
958 case ixgbe_mac_X540:
959 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800960 break;
961 default:
962 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800963 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000964
965 /*
966 * We can enable relaxed ordering for reads, but not writes when
967 * DCA is enabled. This is due to a known issue in some chipsets
968 * which will cause the DCA tag to be cleared.
969 */
970 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
971 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
972 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
973
974 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800975}
976
977static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
978{
979 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000980 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800981 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800982
983 if (q_vector->cpu == cpu)
984 goto out_no_update;
985
Alexander Duycka5579282012-02-08 07:50:04 +0000986 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000987 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800988
Alexander Duycka5579282012-02-08 07:50:04 +0000989 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000990 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800991
992 q_vector->cpu = cpu;
993out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800994 put_cpu();
995}
996
997static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
998{
999 int i;
1000
1001 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1002 return;
1003
Alexander Duycke35ec122009-05-21 13:07:12 +00001004 /* always use CB2 mode, difference is masked in the CB driver */
1005 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1006
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001007 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001008 adapter->q_vector[i]->cpu = -1;
1009 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001010 }
1011}
1012
1013static int __ixgbe_notify_dca(struct device *dev, void *data)
1014{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001015 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001016 unsigned long event = *(unsigned long *)data;
1017
Don Skidmore2a72c312011-07-20 02:27:05 +00001018 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001019 return 0;
1020
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001021 switch (event) {
1022 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001023 /* if we're already enabled, don't do it again */
1024 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1025 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001026 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001027 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001028 ixgbe_setup_dca(adapter);
1029 break;
1030 }
1031 /* Fall Through since DCA is disabled. */
1032 case DCA_PROVIDER_REMOVE:
1033 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1034 dca_remove_requester(dev);
1035 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1036 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1037 }
1038 break;
1039 }
1040
Denis V. Lunev652f0932008-03-27 14:39:17 +03001041 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001042}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001043
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001044#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001045static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1046 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001047 struct sk_buff *skb)
1048{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001049 if (ring->netdev->features & NETIF_F_RXHASH)
1050 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001051}
1052
Alexander Duyckf8003262012-03-03 02:35:52 +00001053#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001054/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001055 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001056 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001057 * @rx_desc: advanced rx descriptor
1058 *
1059 * Returns : true if it is FCoE pkt
1060 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001061static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001062 union ixgbe_adv_rx_desc *rx_desc)
1063{
1064 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1065
Alexander Duyck57efd442012-06-25 21:54:46 +00001066 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001067 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1068 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1069 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1070}
1071
Alexander Duyckf8003262012-03-03 02:35:52 +00001072#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001073/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001074 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001075 * @ring: structure containing ring specific data
1076 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001077 * @skb: skb currently being received and modified
1078 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001079static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001080 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001081 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001082{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001083 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001084
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001085 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001086 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001087 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001088
1089 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001090 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1091 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001092 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001093 return;
1094 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001095
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001096 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001097 return;
1098
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001099 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001100 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001101
1102 /*
1103 * 82599 errata, UDP frames with a 0 checksum can be marked as
1104 * checksum errors.
1105 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001106 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1107 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001108 return;
1109
Alexander Duyck8a0da212012-01-31 02:59:49 +00001110 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001111 return;
1112 }
1113
Auke Kok9a799d72007-09-15 14:07:45 -07001114 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001115 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001116}
1117
Alexander Duyck84ea2592010-11-16 19:26:49 -08001118static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001119{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001120 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001121
1122 /* update next to alloc since we have filled the ring */
1123 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001124 /*
1125 * Force memory writes to complete before letting h/w
1126 * know there are new descriptors to fetch. (Only
1127 * applicable for weak-ordered memory model archs,
1128 * such as IA-64).
1129 */
1130 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001131 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001132}
1133
Alexander Duyckf990b792012-01-31 02:59:34 +00001134static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1135 struct ixgbe_rx_buffer *bi)
1136{
1137 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001138 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001139
Alexander Duyckf8003262012-03-03 02:35:52 +00001140 /* since we are recycling buffers we should seldom need to alloc */
1141 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001142 return true;
1143
Alexander Duyckf8003262012-03-03 02:35:52 +00001144 /* alloc new page for storage */
1145 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001146 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1147 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001148 if (unlikely(!page)) {
1149 rx_ring->rx_stats.alloc_rx_page_failed++;
1150 return false;
1151 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001152 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001153 }
1154
Alexander Duyckf8003262012-03-03 02:35:52 +00001155 /* map page for use */
1156 dma = dma_map_page(rx_ring->dev, page, 0,
1157 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001158
Alexander Duyckf8003262012-03-03 02:35:52 +00001159 /*
1160 * if mapping failed free memory back to system since
1161 * there isn't much point in holding memory we can't use
1162 */
1163 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001164 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001165 bi->page = NULL;
1166
Alexander Duyckf990b792012-01-31 02:59:34 +00001167 rx_ring->rx_stats.alloc_rx_page_failed++;
1168 return false;
1169 }
1170
Alexander Duyckf8003262012-03-03 02:35:52 +00001171 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001172 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001173
Alexander Duyckf990b792012-01-31 02:59:34 +00001174 return true;
1175}
1176
Auke Kok9a799d72007-09-15 14:07:45 -07001177/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001178 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001179 * @rx_ring: ring to place buffers on
1180 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001181 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001182void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001183{
Auke Kok9a799d72007-09-15 14:07:45 -07001184 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001185 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001186 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001187
Alexander Duyckf8003262012-03-03 02:35:52 +00001188 /* nothing to do */
1189 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001190 return;
1191
Alexander Duycke4f74022012-01-31 02:59:44 +00001192 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001193 bi = &rx_ring->rx_buffer_info[i];
1194 i -= rx_ring->count;
1195
Alexander Duyckf8003262012-03-03 02:35:52 +00001196 do {
1197 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001198 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001199
Alexander Duyckf8003262012-03-03 02:35:52 +00001200 /*
1201 * Refresh the desc even if buffer_addrs didn't change
1202 * because each write-back erases this info.
1203 */
1204 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001205
Alexander Duyckf990b792012-01-31 02:59:34 +00001206 rx_desc++;
1207 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001208 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001209 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001210 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001211 bi = rx_ring->rx_buffer_info;
1212 i -= rx_ring->count;
1213 }
1214
1215 /* clear the hdr_addr for the next_to_use descriptor */
1216 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001217
1218 cleaned_count--;
1219 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001220
Alexander Duyckf990b792012-01-31 02:59:34 +00001221 i += rx_ring->count;
1222
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001223 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001224 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001225}
1226
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001227/**
1228 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1229 * @data: pointer to the start of the headers
1230 * @max_len: total length of section to find headers in
1231 *
1232 * This function is meant to determine the length of headers that will
1233 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1234 * motivation of doing this is to only perform one pull for IPv4 TCP
1235 * packets so that we can do basic things like calculating the gso_size
1236 * based on the average data per packet.
1237 **/
1238static unsigned int ixgbe_get_headlen(unsigned char *data,
1239 unsigned int max_len)
1240{
1241 union {
1242 unsigned char *network;
1243 /* l2 headers */
1244 struct ethhdr *eth;
1245 struct vlan_hdr *vlan;
1246 /* l3 headers */
1247 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001248 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001249 } hdr;
1250 __be16 protocol;
1251 u8 nexthdr = 0; /* default to not TCP */
1252 u8 hlen;
1253
1254 /* this should never happen, but better safe than sorry */
1255 if (max_len < ETH_HLEN)
1256 return max_len;
1257
1258 /* initialize network frame pointer */
1259 hdr.network = data;
1260
1261 /* set first protocol and move network header forward */
1262 protocol = hdr.eth->h_proto;
1263 hdr.network += ETH_HLEN;
1264
1265 /* handle any vlan tag if present */
1266 if (protocol == __constant_htons(ETH_P_8021Q)) {
1267 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1268 return max_len;
1269
1270 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1271 hdr.network += VLAN_HLEN;
1272 }
1273
1274 /* handle L3 protocols */
1275 if (protocol == __constant_htons(ETH_P_IP)) {
1276 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1277 return max_len;
1278
1279 /* access ihl as a u8 to avoid unaligned access on ia64 */
1280 hlen = (hdr.network[0] & 0x0F) << 2;
1281
1282 /* verify hlen meets minimum size requirements */
1283 if (hlen < sizeof(struct iphdr))
1284 return hdr.network - data;
1285
1286 /* record next protocol */
1287 nexthdr = hdr.ipv4->protocol;
1288 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001289 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1290 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1291 return max_len;
1292
1293 /* record next protocol */
1294 nexthdr = hdr.ipv6->nexthdr;
1295 hdr.network += sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001296#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001297 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1298 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1299 return max_len;
1300 hdr.network += FCOE_HEADER_LEN;
1301#endif
1302 } else {
1303 return hdr.network - data;
1304 }
1305
Alexander Duycka048b402012-05-24 08:26:29 +00001306 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001307 if (nexthdr == IPPROTO_TCP) {
1308 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1309 return max_len;
1310
1311 /* access doff as a u8 to avoid unaligned access on ia64 */
1312 hlen = (hdr.network[12] & 0xF0) >> 2;
1313
1314 /* verify hlen meets minimum size requirements */
1315 if (hlen < sizeof(struct tcphdr))
1316 return hdr.network - data;
1317
1318 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001319 } else if (nexthdr == IPPROTO_UDP) {
1320 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1321 return max_len;
1322
1323 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001324 }
1325
1326 /*
1327 * If everything has gone correctly hdr.network should be the
1328 * data section of the packet and will be the end of the header.
1329 * If not then it probably represents the end of the last recognized
1330 * header.
1331 */
1332 if ((hdr.network - data) < max_len)
1333 return hdr.network - data;
1334 else
1335 return max_len;
1336}
1337
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001338static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1339 struct sk_buff *skb)
1340{
Alexander Duyckf8003262012-03-03 02:35:52 +00001341 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001342
1343 /* set gso_size to avoid messing up TCP MSS */
1344 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1345 IXGBE_CB(skb)->append_cnt);
1346}
1347
1348static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1349 struct sk_buff *skb)
1350{
1351 /* if append_cnt is 0 then frame is not RSC */
1352 if (!IXGBE_CB(skb)->append_cnt)
1353 return;
1354
1355 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1356 rx_ring->rx_stats.rsc_flush++;
1357
1358 ixgbe_set_rsc_gso_size(rx_ring, skb);
1359
1360 /* gso_size is computed using append_cnt so always clear it last */
1361 IXGBE_CB(skb)->append_cnt = 0;
1362}
1363
Alexander Duyck8a0da212012-01-31 02:59:49 +00001364/**
1365 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1366 * @rx_ring: rx descriptor ring packet is being transacted on
1367 * @rx_desc: pointer to the EOP Rx descriptor
1368 * @skb: pointer to current skb being populated
1369 *
1370 * This function checks the ring, descriptor, and packet information in
1371 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1372 * other fields within the skb.
1373 **/
1374static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1375 union ixgbe_adv_rx_desc *rx_desc,
1376 struct sk_buff *skb)
1377{
John Fastabend43e95f12012-05-15 06:12:17 +00001378 struct net_device *dev = rx_ring->netdev;
1379
Alexander Duyck8a0da212012-01-31 02:59:49 +00001380 ixgbe_update_rsc_stats(rx_ring, skb);
1381
1382 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1383
1384 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1385
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001386#ifdef CONFIG_IXGBE_PTP
Jacob Keller1d1a79b2012-05-22 06:18:08 +00001387 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001388#endif
1389
John Fastabend43e95f12012-05-15 06:12:17 +00001390 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1391 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001392 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1393 __vlan_hwaccel_put_tag(skb, vid);
1394 }
1395
1396 skb_record_rx_queue(skb, rx_ring->queue_index);
1397
John Fastabend43e95f12012-05-15 06:12:17 +00001398 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001399}
1400
1401static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1402 struct sk_buff *skb)
1403{
1404 struct ixgbe_adapter *adapter = q_vector->adapter;
1405
1406 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1407 napi_gro_receive(&q_vector->napi, skb);
1408 else
1409 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001410}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001411
Alexander Duyckf8003262012-03-03 02:35:52 +00001412/**
1413 * ixgbe_is_non_eop - process handling of non-EOP buffers
1414 * @rx_ring: Rx ring being processed
1415 * @rx_desc: Rx descriptor for current buffer
1416 * @skb: Current socket buffer containing buffer in progress
1417 *
1418 * This function updates next to clean. If the buffer is an EOP buffer
1419 * this function exits returning false, otherwise it will place the
1420 * sk_buff in the next buffer to be chained and return true indicating
1421 * that this is in fact a non-EOP buffer.
1422 **/
1423static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1424 union ixgbe_adv_rx_desc *rx_desc,
1425 struct sk_buff *skb)
1426{
1427 u32 ntc = rx_ring->next_to_clean + 1;
1428
1429 /* fetch, update, and store next to clean */
1430 ntc = (ntc < rx_ring->count) ? ntc : 0;
1431 rx_ring->next_to_clean = ntc;
1432
1433 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1434
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001435 /* update RSC append count if present */
1436 if (ring_is_rsc_enabled(rx_ring)) {
1437 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1438 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1439
1440 if (unlikely(rsc_enabled)) {
1441 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1442
1443 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1444 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1445
1446 /* update ntc based on RSC value */
1447 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1448 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1449 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1450 }
1451 }
1452
1453 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001454 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1455 return false;
1456
Alexander Duyckf8003262012-03-03 02:35:52 +00001457 /* place skb in next buffer to be received */
1458 rx_ring->rx_buffer_info[ntc].skb = skb;
1459 rx_ring->rx_stats.non_eop_descs++;
1460
1461 return true;
1462}
1463
1464/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001465 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1466 * @rx_ring: rx descriptor ring packet is being transacted on
1467 * @skb: pointer to current skb being adjusted
1468 *
1469 * This function is an ixgbe specific version of __pskb_pull_tail. The
1470 * main difference between this version and the original function is that
1471 * this function can make several assumptions about the state of things
1472 * that allow for significant optimizations versus the standard function.
1473 * As a result we can do things like drop a frag and maintain an accurate
1474 * truesize for the skb.
1475 */
1476static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1477 struct sk_buff *skb)
1478{
1479 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1480 unsigned char *va;
1481 unsigned int pull_len;
1482
1483 /*
1484 * it is valid to use page_address instead of kmap since we are
1485 * working with pages allocated out of the lomem pool per
1486 * alloc_page(GFP_ATOMIC)
1487 */
1488 va = skb_frag_address(frag);
1489
1490 /*
1491 * we need the header to contain the greater of either ETH_HLEN or
1492 * 60 bytes if the skb->len is less than 60 for skb_pad.
1493 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001494 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001495
1496 /* align pull length to size of long to optimize memcpy performance */
1497 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1498
1499 /* update all of the pointers */
1500 skb_frag_size_sub(frag, pull_len);
1501 frag->page_offset += pull_len;
1502 skb->data_len -= pull_len;
1503 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001504}
1505
1506/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001507 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1508 * @rx_ring: rx descriptor ring packet is being transacted on
1509 * @skb: pointer to current skb being updated
1510 *
1511 * This function provides a basic DMA sync up for the first fragment of an
1512 * skb. The reason for doing this is that the first fragment cannot be
1513 * unmapped until we have reached the end of packet descriptor for a buffer
1514 * chain.
1515 */
1516static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1517 struct sk_buff *skb)
1518{
1519 /* if the page was released unmap it, else just sync our portion */
1520 if (unlikely(IXGBE_CB(skb)->page_released)) {
1521 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1522 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1523 IXGBE_CB(skb)->page_released = false;
1524 } else {
1525 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1526
1527 dma_sync_single_range_for_cpu(rx_ring->dev,
1528 IXGBE_CB(skb)->dma,
1529 frag->page_offset,
1530 ixgbe_rx_bufsz(rx_ring),
1531 DMA_FROM_DEVICE);
1532 }
1533 IXGBE_CB(skb)->dma = 0;
1534}
1535
1536/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001537 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1538 * @rx_ring: rx descriptor ring packet is being transacted on
1539 * @rx_desc: pointer to the EOP Rx descriptor
1540 * @skb: pointer to current skb being fixed
1541 *
1542 * Check for corrupted packet headers caused by senders on the local L2
1543 * embedded NIC switch not setting up their Tx Descriptors right. These
1544 * should be very rare.
1545 *
1546 * Also address the case where we are pulling data in on pages only
1547 * and as such no data is present in the skb header.
1548 *
1549 * In addition if skb is not at least 60 bytes we need to pad it so that
1550 * it is large enough to qualify as a valid Ethernet frame.
1551 *
1552 * Returns true if an error was encountered and skb was freed.
1553 **/
1554static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1555 union ixgbe_adv_rx_desc *rx_desc,
1556 struct sk_buff *skb)
1557{
Alexander Duyckf8003262012-03-03 02:35:52 +00001558 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001559
1560 /* verify that the packet does not have any known errors */
1561 if (unlikely(ixgbe_test_staterr(rx_desc,
1562 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1563 !(netdev->features & NETIF_F_RXALL))) {
1564 dev_kfree_skb_any(skb);
1565 return true;
1566 }
1567
Alexander Duyck19861ce2012-07-20 08:08:33 +00001568 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001569 if (skb_is_nonlinear(skb))
1570 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001571
Alexander Duyck57efd442012-06-25 21:54:46 +00001572#ifdef IXGBE_FCOE
1573 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1574 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1575 return false;
1576
1577#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001578 /* if skb_pad returns an error the skb was freed */
1579 if (unlikely(skb->len < 60)) {
1580 int pad_len = 60 - skb->len;
1581
1582 if (skb_pad(skb, pad_len))
1583 return true;
1584 __skb_put(skb, pad_len);
1585 }
1586
1587 return false;
1588}
1589
1590/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1592 * @rx_ring: rx descriptor ring to store buffers on
1593 * @old_buff: donor buffer to have page reused
1594 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001595 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001596 **/
1597static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1598 struct ixgbe_rx_buffer *old_buff)
1599{
1600 struct ixgbe_rx_buffer *new_buff;
1601 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001602
1603 new_buff = &rx_ring->rx_buffer_info[nta];
1604
1605 /* update, and store next to alloc */
1606 nta++;
1607 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1608
1609 /* transfer page from old buffer to new buffer */
1610 new_buff->page = old_buff->page;
1611 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001612 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001613
1614 /* sync the buffer for use by the device */
1615 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001616 new_buff->page_offset,
1617 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001618 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001619}
1620
1621/**
1622 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1623 * @rx_ring: rx descriptor ring to transact packets on
1624 * @rx_buffer: buffer containing page to add
1625 * @rx_desc: descriptor containing length of buffer written by hardware
1626 * @skb: sk_buff to place the data into
1627 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001628 * This function will add the data contained in rx_buffer->page to the skb.
1629 * This is done either through a direct copy if the data in the buffer is
1630 * less than the skb header size, otherwise it will just attach the page as
1631 * a frag to the skb.
1632 *
1633 * The function will then update the page offset if necessary and return
1634 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001635 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001636static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001637 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001638 union ixgbe_adv_rx_desc *rx_desc,
1639 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001640{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001641 struct page *page = rx_buffer->page;
1642 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001643#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001644 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001645#else
1646 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1647 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1648 ixgbe_rx_bufsz(rx_ring);
1649#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001650
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001651 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1652 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1653
1654 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1655
1656 /* we can reuse buffer as-is, just make sure it is local */
1657 if (likely(page_to_nid(page) == numa_node_id()))
1658 return true;
1659
1660 /* this page cannot be reused so discard it */
1661 put_page(page);
1662 return false;
1663 }
1664
Alexander Duyck0549ae22012-07-20 08:08:18 +00001665 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1666 rx_buffer->page_offset, size, truesize);
1667
Alexander Duyck09816fb2012-07-20 08:08:23 +00001668 /* avoid re-using remote pages */
1669 if (unlikely(page_to_nid(page) != numa_node_id()))
1670 return false;
1671
1672#if (PAGE_SIZE < 8192)
1673 /* if we are only owner of page we can reuse it */
1674 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001675 return false;
1676
1677 /* flip page offset to other buffer */
1678 rx_buffer->page_offset ^= truesize;
1679
Alexander Duyck09816fb2012-07-20 08:08:23 +00001680 /*
1681 * since we are the only owner of the page and we need to
1682 * increment it, just set the value to 2 in order to avoid
1683 * an unecessary locked operation
1684 */
1685 atomic_set(&page->_count, 2);
1686#else
1687 /* move offset up to the next cache line */
1688 rx_buffer->page_offset += truesize;
1689
1690 if (rx_buffer->page_offset > last_offset)
1691 return false;
1692
Alexander Duyck0549ae22012-07-20 08:08:18 +00001693 /* bump ref count on page before it is given to the stack */
1694 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001695#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001696
1697 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001698}
1699
Alexander Duyck18806c92012-07-20 08:08:44 +00001700static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1701 union ixgbe_adv_rx_desc *rx_desc)
1702{
1703 struct ixgbe_rx_buffer *rx_buffer;
1704 struct sk_buff *skb;
1705 struct page *page;
1706
1707 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1708 page = rx_buffer->page;
1709 prefetchw(page);
1710
1711 skb = rx_buffer->skb;
1712
1713 if (likely(!skb)) {
1714 void *page_addr = page_address(page) +
1715 rx_buffer->page_offset;
1716
1717 /* prefetch first cache line of first page */
1718 prefetch(page_addr);
1719#if L1_CACHE_BYTES < 128
1720 prefetch(page_addr + L1_CACHE_BYTES);
1721#endif
1722
1723 /* allocate a skb to store the frags */
1724 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1725 IXGBE_RX_HDR_SIZE);
1726 if (unlikely(!skb)) {
1727 rx_ring->rx_stats.alloc_rx_buff_failed++;
1728 return NULL;
1729 }
1730
1731 /*
1732 * we will be copying header into skb->data in
1733 * pskb_may_pull so it is in our interest to prefetch
1734 * it now to avoid a possible cache miss
1735 */
1736 prefetchw(skb->data);
1737
1738 /*
1739 * Delay unmapping of the first packet. It carries the
1740 * header information, HW may still access the header
1741 * after the writeback. Only unmap it when EOP is
1742 * reached
1743 */
1744 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1745 goto dma_sync;
1746
1747 IXGBE_CB(skb)->dma = rx_buffer->dma;
1748 } else {
1749 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1750 ixgbe_dma_sync_frag(rx_ring, skb);
1751
1752dma_sync:
1753 /* we are reusing so sync this buffer for CPU use */
1754 dma_sync_single_range_for_cpu(rx_ring->dev,
1755 rx_buffer->dma,
1756 rx_buffer->page_offset,
1757 ixgbe_rx_bufsz(rx_ring),
1758 DMA_FROM_DEVICE);
1759 }
1760
1761 /* pull page into skb */
1762 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1763 /* hand second half of page back to the ring */
1764 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1765 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1766 /* the page has been released from the ring */
1767 IXGBE_CB(skb)->page_released = true;
1768 } else {
1769 /* we are not reusing the buffer so unmap it */
1770 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1771 ixgbe_rx_pg_size(rx_ring),
1772 DMA_FROM_DEVICE);
1773 }
1774
1775 /* clear contents of buffer_info */
1776 rx_buffer->skb = NULL;
1777 rx_buffer->dma = 0;
1778 rx_buffer->page = NULL;
1779
1780 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001781}
1782
1783/**
1784 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1785 * @q_vector: structure containing interrupt and ring information
1786 * @rx_ring: rx descriptor ring to transact packets on
1787 * @budget: Total limit on number of packets to process
1788 *
1789 * This function provides a "bounce buffer" approach to Rx interrupt
1790 * processing. The advantage to this is that on systems that have
1791 * expensive overhead for IOMMU access this provides a means of avoiding
1792 * it by maintaining the mapping of the page to the syste.
1793 *
1794 * Returns true if all work is completed without reaching budget
1795 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001796static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001797 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001798 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001799{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001800 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001801#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001802 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001803 int ddp_bytes;
1804 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001805#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001806 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001807
Alexander Duyckf8003262012-03-03 02:35:52 +00001808 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001809 union ixgbe_adv_rx_desc *rx_desc;
1810 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001811
Alexander Duyckf8003262012-03-03 02:35:52 +00001812 /* return some buffers to hardware, one at a time is too slow */
1813 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1814 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1815 cleaned_count = 0;
1816 }
Auke Kok9a799d72007-09-15 14:07:45 -07001817
Alexander Duyck18806c92012-07-20 08:08:44 +00001818 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001819
Alexander Duyckf8003262012-03-03 02:35:52 +00001820 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1821 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001822
Alexander Duyckf8003262012-03-03 02:35:52 +00001823 /*
1824 * This memory barrier is needed to keep us from reading
1825 * any other fields out of the rx_desc until we know the
1826 * RXD_STAT_DD bit is set
1827 */
1828 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001829
Alexander Duyck18806c92012-07-20 08:08:44 +00001830 /* retrieve a buffer from the ring */
1831 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001832
Alexander Duyck18806c92012-07-20 08:08:44 +00001833 /* exit if we failed to retrieve a buffer */
1834 if (!skb)
1835 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001836
Auke Kok9a799d72007-09-15 14:07:45 -07001837 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001838
Alexander Duyckf8003262012-03-03 02:35:52 +00001839 /* place incomplete frames back on ring for completion */
1840 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1841 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001842
Alexander Duyckf8003262012-03-03 02:35:52 +00001843 /* verify the packet layout is correct */
1844 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1845 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001846
1847 /* probably a little skewed due to removing CRC */
1848 total_rx_bytes += skb->len;
1849 total_rx_packets++;
1850
Alexander Duyck8a0da212012-01-31 02:59:49 +00001851 /* populate checksum, timestamp, VLAN, and protocol */
1852 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1853
Yi Zou332d4a72009-05-13 13:11:53 +00001854#ifdef IXGBE_FCOE
1855 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001856 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001857 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001858 /* include DDPed FCoE data */
1859 if (ddp_bytes > 0) {
1860 if (!mss) {
1861 mss = rx_ring->netdev->mtu -
1862 sizeof(struct fcoe_hdr) -
1863 sizeof(struct fc_frame_header) -
1864 sizeof(struct fcoe_crc_eof);
1865 if (mss > 512)
1866 mss &= ~511;
1867 }
1868 total_rx_bytes += ddp_bytes;
1869 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1870 mss);
1871 }
David S. Miller823dcd22011-08-20 10:39:12 -07001872 if (!ddp_bytes) {
1873 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001874 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001875 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001876 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001877
Yi Zou332d4a72009-05-13 13:11:53 +00001878#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001879 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001880
Alexander Duyckf8003262012-03-03 02:35:52 +00001881 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001882 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001883 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001884
Alexander Duyckc267fc12010-11-16 19:27:00 -08001885 u64_stats_update_begin(&rx_ring->syncp);
1886 rx_ring->stats.packets += total_rx_packets;
1887 rx_ring->stats.bytes += total_rx_bytes;
1888 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001889 q_vector->rx.total_packets += total_rx_packets;
1890 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001891
Alexander Duyckf8003262012-03-03 02:35:52 +00001892 if (cleaned_count)
1893 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1894
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001895 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001896}
1897
Auke Kok9a799d72007-09-15 14:07:45 -07001898/**
1899 * ixgbe_configure_msix - Configure MSI-X hardware
1900 * @adapter: board private structure
1901 *
1902 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1903 * interrupts.
1904 **/
1905static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1906{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001907 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001908 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001909 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001910
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001911 /* Populate MSIX to EITR Select */
1912 if (adapter->num_vfs > 32) {
1913 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1914 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1915 }
1916
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001917 /*
1918 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001919 * corresponding register.
1920 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001921 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001922 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001923 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001924
Alexander Duycka5579282012-02-08 07:50:04 +00001925 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001926 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001927
Alexander Duycka5579282012-02-08 07:50:04 +00001928 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001929 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001930
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001931 if (q_vector->tx.ring && !q_vector->rx.ring) {
1932 /* tx only vector */
1933 if (adapter->tx_itr_setting == 1)
1934 q_vector->itr = IXGBE_10K_ITR;
1935 else
1936 q_vector->itr = adapter->tx_itr_setting;
1937 } else {
1938 /* rx or rx/tx vector */
1939 if (adapter->rx_itr_setting == 1)
1940 q_vector->itr = IXGBE_20K_ITR;
1941 else
1942 q_vector->itr = adapter->rx_itr_setting;
1943 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001944
Alexander Duyckfe49f042009-06-04 16:00:09 +00001945 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001946 }
1947
Alexander Duyckbd508172010-11-16 19:27:03 -08001948 switch (adapter->hw.mac.type) {
1949 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001950 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001951 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001952 break;
1953 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001954 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001955 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001956 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001957 default:
1958 break;
1959 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001960 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001961
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001962 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001963 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001964 mask &= ~(IXGBE_EIMS_OTHER |
1965 IXGBE_EIMS_MAILBOX |
1966 IXGBE_EIMS_LSC);
1967
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001968 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001969}
1970
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001971enum latency_range {
1972 lowest_latency = 0,
1973 low_latency = 1,
1974 bulk_latency = 2,
1975 latency_invalid = 255
1976};
1977
1978/**
1979 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001980 * @q_vector: structure containing interrupt and ring information
1981 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001982 *
1983 * Stores a new ITR value based on packets and byte
1984 * counts during the last interrupt. The advantage of per interrupt
1985 * computation is faster updates and more accurate ITR for the current
1986 * traffic pattern. Constants in this function were computed
1987 * based on theoretical maximum wire speed and thresholds were set based
1988 * on testing data as well as attempting to minimize response time
1989 * while increasing bulk throughput.
1990 * this functionality is controlled by the InterruptThrottleRate module
1991 * parameter (see ixgbe_param.c)
1992 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001993static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1994 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001995{
Alexander Duyckbd198052011-06-11 01:45:08 +00001996 int bytes = ring_container->total_bytes;
1997 int packets = ring_container->total_packets;
1998 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001999 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002000 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002001
2002 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002003 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002004
2005 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002006 * 0-10MB/s lowest (100000 ints/s)
2007 * 10-20MB/s low (20000 ints/s)
2008 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002009 */
2010 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002011 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002012 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2013
2014 switch (itr_setting) {
2015 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002016 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002017 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002018 break;
2019 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002020 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002021 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002022 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002023 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002024 break;
2025 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002026 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002027 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002028 break;
2029 }
2030
Alexander Duyckbd198052011-06-11 01:45:08 +00002031 /* clear work counters since we have the values we need */
2032 ring_container->total_bytes = 0;
2033 ring_container->total_packets = 0;
2034
2035 /* write updated itr to ring container */
2036 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002037}
2038
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002039/**
2040 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002041 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002042 *
2043 * This function is made to be called by ethtool and by the driver
2044 * when it needs to update EITR registers at runtime. Hardware
2045 * specific quirks/differences are taken care of here.
2046 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002047void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002048{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002049 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002050 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002051 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002052 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002053
Alexander Duyckbd508172010-11-16 19:27:03 -08002054 switch (adapter->hw.mac.type) {
2055 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002056 /* must write high and low 16 bits to reset counter */
2057 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002058 break;
2059 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002060 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002061 /*
2062 * set the WDIS bit to not clear the timer bits and cause an
2063 * immediate assertion of the interrupt
2064 */
2065 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002066 break;
2067 default:
2068 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002069 }
2070 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2071}
2072
Alexander Duyckbd198052011-06-11 01:45:08 +00002073static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002074{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002075 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002076 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002077
Alexander Duyckbd198052011-06-11 01:45:08 +00002078 ixgbe_update_itr(q_vector, &q_vector->tx);
2079 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002080
Alexander Duyck08c88332011-06-11 01:45:03 +00002081 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002082
2083 switch (current_itr) {
2084 /* counts and packets in update_itr are dependent on these numbers */
2085 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002086 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002087 break;
2088 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002089 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002090 break;
2091 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002092 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002093 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002094 default:
2095 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002096 }
2097
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002098 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002099 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002100 new_itr = (10 * new_itr * q_vector->itr) /
2101 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002102
Alexander Duyckbd198052011-06-11 01:45:08 +00002103 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002104 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002105
2106 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002107 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002108}
2109
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002110/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002111 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002112 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002113 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002114static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002115{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002116 struct ixgbe_hw *hw = &adapter->hw;
2117 u32 eicr = adapter->interrupt_event;
2118
Alexander Duyckf0f97782011-04-22 04:08:09 +00002119 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002120 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002121
Alexander Duyckf0f97782011-04-22 04:08:09 +00002122 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2123 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2124 return;
2125
2126 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2127
Joe Perches7ca647b2010-09-07 21:35:40 +00002128 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002129 case IXGBE_DEV_ID_82599_T3_LOM:
2130 /*
2131 * Since the warning interrupt is for both ports
2132 * we don't have to check if:
2133 * - This interrupt wasn't for our port.
2134 * - We may have missed the interrupt so always have to
2135 * check if we got a LSC
2136 */
2137 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2138 !(eicr & IXGBE_EICR_LSC))
2139 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002140
Alexander Duyckf0f97782011-04-22 04:08:09 +00002141 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2142 u32 autoneg;
2143 bool link_up = false;
2144
Joe Perches7ca647b2010-09-07 21:35:40 +00002145 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2146
Alexander Duyckf0f97782011-04-22 04:08:09 +00002147 if (link_up)
2148 return;
2149 }
2150
2151 /* Check if this is not due to overtemp */
2152 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2153 return;
2154
2155 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002156 default:
2157 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2158 return;
2159 break;
2160 }
2161 e_crit(drv,
2162 "Network adapter has been stopped because it has over heated. "
2163 "Restart the computer. If the problem persists, "
2164 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002165
2166 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002167}
2168
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002169static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2170{
2171 struct ixgbe_hw *hw = &adapter->hw;
2172
2173 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2174 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002175 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002176 /* write to clear the interrupt */
2177 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2178 }
2179}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002180
Jacob Keller4f51bf72011-08-20 04:49:45 +00002181static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2182{
2183 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2184 return;
2185
2186 switch (adapter->hw.mac.type) {
2187 case ixgbe_mac_82599EB:
2188 /*
2189 * Need to check link state so complete overtemp check
2190 * on service task
2191 */
2192 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2193 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2194 adapter->interrupt_event = eicr;
2195 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2196 ixgbe_service_event_schedule(adapter);
2197 return;
2198 }
2199 return;
2200 case ixgbe_mac_X540:
2201 if (!(eicr & IXGBE_EICR_TS))
2202 return;
2203 break;
2204 default:
2205 return;
2206 }
2207
2208 e_crit(drv,
2209 "Network adapter has been stopped because it has over heated. "
2210 "Restart the computer. If the problem persists, "
2211 "power off the system and replace the adapter\n");
2212}
2213
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002214static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2215{
2216 struct ixgbe_hw *hw = &adapter->hw;
2217
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002218 if (eicr & IXGBE_EICR_GPI_SDP2) {
2219 /* Clear the interrupt */
2220 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002221 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2222 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2223 ixgbe_service_event_schedule(adapter);
2224 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002225 }
2226
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002227 if (eicr & IXGBE_EICR_GPI_SDP1) {
2228 /* Clear the interrupt */
2229 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002230 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2231 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2232 ixgbe_service_event_schedule(adapter);
2233 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002234 }
2235}
2236
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002237static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2238{
2239 struct ixgbe_hw *hw = &adapter->hw;
2240
2241 adapter->lsc_int++;
2242 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2243 adapter->link_check_timeout = jiffies;
2244 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2245 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002246 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002247 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002248 }
2249}
2250
Alexander Duyckfe49f042009-06-04 16:00:09 +00002251static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2252 u64 qmask)
2253{
2254 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002255 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002256
Alexander Duyckbd508172010-11-16 19:27:03 -08002257 switch (hw->mac.type) {
2258 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002259 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002260 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2261 break;
2262 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002263 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002264 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002265 if (mask)
2266 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002267 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002268 if (mask)
2269 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2270 break;
2271 default:
2272 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002273 }
2274 /* skip the flush */
2275}
2276
2277static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002278 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002279{
2280 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002281 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002282
Alexander Duyckbd508172010-11-16 19:27:03 -08002283 switch (hw->mac.type) {
2284 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002285 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002286 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2287 break;
2288 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002289 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002290 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002291 if (mask)
2292 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002293 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002294 if (mask)
2295 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2296 break;
2297 default:
2298 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002299 }
2300 /* skip the flush */
2301}
2302
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002303/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002304 * ixgbe_irq_enable - Enable default interrupt generation settings
2305 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002306 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002307static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2308 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002309{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002310 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002311
Alexander Duyck2c4af692011-07-15 07:29:55 +00002312 /* don't reenable LSC while waiting for link */
2313 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2314 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315
Alexander Duyck2c4af692011-07-15 07:29:55 +00002316 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002317 switch (adapter->hw.mac.type) {
2318 case ixgbe_mac_82599EB:
2319 mask |= IXGBE_EIMS_GPI_SDP0;
2320 break;
2321 case ixgbe_mac_X540:
2322 mask |= IXGBE_EIMS_TS;
2323 break;
2324 default:
2325 break;
2326 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002327 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2328 mask |= IXGBE_EIMS_GPI_SDP1;
2329 switch (adapter->hw.mac.type) {
2330 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002331 mask |= IXGBE_EIMS_GPI_SDP1;
2332 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002333 case ixgbe_mac_X540:
2334 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002335 mask |= IXGBE_EIMS_MAILBOX;
2336 break;
2337 default:
2338 break;
2339 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002340
2341#ifdef CONFIG_IXGBE_PTP
2342 if (adapter->hw.mac.type == ixgbe_mac_X540)
2343 mask |= IXGBE_EIMS_TIMESYNC;
2344#endif
2345
Alexander Duyck2c4af692011-07-15 07:29:55 +00002346 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2347 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2348 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002349
Alexander Duyck2c4af692011-07-15 07:29:55 +00002350 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2351 if (queues)
2352 ixgbe_irq_enable_queues(adapter, ~0);
2353 if (flush)
2354 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002355}
2356
Alexander Duyck2c4af692011-07-15 07:29:55 +00002357static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002358{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002359 struct ixgbe_adapter *adapter = data;
2360 struct ixgbe_hw *hw = &adapter->hw;
2361 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002362
Alexander Duyck2c4af692011-07-15 07:29:55 +00002363 /*
2364 * Workaround for Silicon errata. Use clear-by-write instead
2365 * of clear-by-read. Reading with EICS will return the
2366 * interrupt causes without clearing, which later be done
2367 * with the write to EICR.
2368 */
2369 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2370 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002371
Alexander Duyck2c4af692011-07-15 07:29:55 +00002372 if (eicr & IXGBE_EICR_LSC)
2373 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002374
Alexander Duyck2c4af692011-07-15 07:29:55 +00002375 if (eicr & IXGBE_EICR_MAILBOX)
2376 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002377
Alexander Duyck2c4af692011-07-15 07:29:55 +00002378 switch (hw->mac.type) {
2379 case ixgbe_mac_82599EB:
2380 case ixgbe_mac_X540:
2381 if (eicr & IXGBE_EICR_ECC)
2382 e_info(link, "Received unrecoverable ECC Err, please "
2383 "reboot\n");
2384 /* Handle Flow Director Full threshold interrupt */
2385 if (eicr & IXGBE_EICR_FLOW_DIR) {
2386 int reinit_count = 0;
2387 int i;
2388 for (i = 0; i < adapter->num_tx_queues; i++) {
2389 struct ixgbe_ring *ring = adapter->tx_ring[i];
2390 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2391 &ring->state))
2392 reinit_count++;
2393 }
2394 if (reinit_count) {
2395 /* no more flow director interrupts until after init */
2396 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2397 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2398 ixgbe_service_event_schedule(adapter);
2399 }
2400 }
2401 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002402 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002403 break;
2404 default:
2405 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002406 }
2407
Alexander Duyck2c4af692011-07-15 07:29:55 +00002408 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002409
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002410#ifdef CONFIG_IXGBE_PTP
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002411 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2412 ixgbe_ptp_check_pps_event(adapter, eicr);
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002413#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002414
Alexander Duyck2c4af692011-07-15 07:29:55 +00002415 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002416 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002417 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002418
Alexander Duyck2c4af692011-07-15 07:29:55 +00002419 return IRQ_HANDLED;
2420}
2421
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002422static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002423{
2424 struct ixgbe_q_vector *q_vector = data;
2425
Auke Kok9a799d72007-09-15 14:07:45 -07002426 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002427
2428 if (q_vector->rx.ring || q_vector->tx.ring)
2429 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002430
2431 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002432}
2433
Auke Kok9a799d72007-09-15 14:07:45 -07002434/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002435 * ixgbe_poll - NAPI Rx polling callback
2436 * @napi: structure for representing this polling device
2437 * @budget: how many packets driver is allowed to clean
2438 *
2439 * This function is used for legacy and MSI, NAPI mode
2440 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002441int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002442{
2443 struct ixgbe_q_vector *q_vector =
2444 container_of(napi, struct ixgbe_q_vector, napi);
2445 struct ixgbe_adapter *adapter = q_vector->adapter;
2446 struct ixgbe_ring *ring;
2447 int per_ring_budget;
2448 bool clean_complete = true;
2449
2450#ifdef CONFIG_IXGBE_DCA
2451 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2452 ixgbe_update_dca(q_vector);
2453#endif
2454
2455 ixgbe_for_each_ring(ring, q_vector->tx)
2456 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2457
2458 /* attempt to distribute budget to each queue fairly, but don't allow
2459 * the budget to go below 1 because we'll exit polling */
2460 if (q_vector->rx.count > 1)
2461 per_ring_budget = max(budget/q_vector->rx.count, 1);
2462 else
2463 per_ring_budget = budget;
2464
2465 ixgbe_for_each_ring(ring, q_vector->rx)
2466 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2467 per_ring_budget);
2468
2469 /* If all work not completed, return budget and keep polling */
2470 if (!clean_complete)
2471 return budget;
2472
2473 /* all work done, exit the polling mode */
2474 napi_complete(napi);
2475 if (adapter->rx_itr_setting & 1)
2476 ixgbe_set_itr(q_vector);
2477 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2478 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2479
2480 return 0;
2481}
2482
2483/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002484 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2485 * @adapter: board private structure
2486 *
2487 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2488 * interrupts from the kernel.
2489 **/
2490static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2491{
2492 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002493 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002494 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002495
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002496 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002497 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002498 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002499
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002500 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002501 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002502 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002503 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002504 } else if (q_vector->rx.ring) {
2505 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2506 "%s-%s-%d", netdev->name, "rx", ri++);
2507 } else if (q_vector->tx.ring) {
2508 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2509 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002510 } else {
2511 /* skip this unused q_vector */
2512 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002513 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002514 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2515 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002516 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002517 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002518 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002519 goto free_queue_irqs;
2520 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002521 /* If Flow Director is enabled, set interrupt affinity */
2522 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2523 /* assign the mask for this irq */
2524 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002525 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002526 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002527 }
2528
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002530 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002531 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002532 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002533 goto free_queue_irqs;
2534 }
2535
2536 return 0;
2537
2538free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002539 while (vector) {
2540 vector--;
2541 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2542 NULL);
2543 free_irq(adapter->msix_entries[vector].vector,
2544 adapter->q_vector[vector]);
2545 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002546 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2547 pci_disable_msix(adapter->pdev);
2548 kfree(adapter->msix_entries);
2549 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002550 return err;
2551}
2552
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002553/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002554 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002555 * @irq: interrupt number
2556 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002557 **/
2558static irqreturn_t ixgbe_intr(int irq, void *data)
2559{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002560 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002561 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002562 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002563 u32 eicr;
2564
Don Skidmore54037502009-02-21 15:42:56 -08002565 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002566 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002567 * before the read of EICR.
2568 */
2569 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2570
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002571 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002572 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002573 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002574 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002575 /*
2576 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002577 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002578 * have disabled interrupts due to EIAM
2579 * finish the workaround of silicon errata on 82598. Unmask
2580 * the interrupt that we masked before the EICR read.
2581 */
2582 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2583 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002584 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002585 }
Auke Kok9a799d72007-09-15 14:07:45 -07002586
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002587 if (eicr & IXGBE_EICR_LSC)
2588 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002589
Alexander Duyckbd508172010-11-16 19:27:03 -08002590 switch (hw->mac.type) {
2591 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002592 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002593 /* Fall through */
2594 case ixgbe_mac_X540:
2595 if (eicr & IXGBE_EICR_ECC)
2596 e_info(link, "Received unrecoverable ECC err, please "
2597 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002598 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002599 break;
2600 default:
2601 break;
2602 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002603
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002604 ixgbe_check_fan_failure(adapter, eicr);
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002605#ifdef CONFIG_IXGBE_PTP
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002606 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2607 ixgbe_ptp_check_pps_event(adapter, eicr);
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002608#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002609
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002610 /* would disable interrupts here but EIAM disabled it */
2611 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002612
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002613 /*
2614 * re-enable link(maybe) and non-queue interrupts, no flush.
2615 * ixgbe_poll will re-enable the queue interrupts
2616 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002617 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2618 ixgbe_irq_enable(adapter, false, false);
2619
Auke Kok9a799d72007-09-15 14:07:45 -07002620 return IRQ_HANDLED;
2621}
2622
2623/**
2624 * ixgbe_request_irq - initialize interrupts
2625 * @adapter: board private structure
2626 *
2627 * Attempts to configure interrupts using the best available
2628 * capabilities of the hardware and kernel.
2629 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002630static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002631{
2632 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002633 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002634
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002635 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002636 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002637 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002638 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002639 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002640 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002641 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002642 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002643
Alexander Duyckde88eee2012-02-08 07:49:59 +00002644 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002645 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002646
Auke Kok9a799d72007-09-15 14:07:45 -07002647 return err;
2648}
2649
2650static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2651{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002652 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002653
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002654 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002655 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002656 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002657 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002658
2659 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2660 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2661 struct msix_entry *entry = &adapter->msix_entries[vector];
2662
2663 /* free only the irqs that were actually requested */
2664 if (!q_vector->rx.ring && !q_vector->tx.ring)
2665 continue;
2666
2667 /* clear the affinity_mask in the IRQ descriptor */
2668 irq_set_affinity_hint(entry->vector, NULL);
2669
2670 free_irq(entry->vector, q_vector);
2671 }
2672
2673 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002674}
2675
2676/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002677 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2678 * @adapter: board private structure
2679 **/
2680static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2681{
Alexander Duyckbd508172010-11-16 19:27:03 -08002682 switch (adapter->hw.mac.type) {
2683 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002684 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002685 break;
2686 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002687 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002688 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2689 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002690 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002691 break;
2692 default:
2693 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002694 }
2695 IXGBE_WRITE_FLUSH(&adapter->hw);
2696 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002697 int vector;
2698
2699 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2700 synchronize_irq(adapter->msix_entries[vector].vector);
2701
2702 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002703 } else {
2704 synchronize_irq(adapter->pdev->irq);
2705 }
2706}
2707
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002708/**
Auke Kok9a799d72007-09-15 14:07:45 -07002709 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2710 *
2711 **/
2712static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2713{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002714 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002715
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002716 /* rx/tx vector */
2717 if (adapter->rx_itr_setting == 1)
2718 q_vector->itr = IXGBE_20K_ITR;
2719 else
2720 q_vector->itr = adapter->rx_itr_setting;
2721
2722 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002723
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002724 ixgbe_set_ivar(adapter, 0, 0, 0);
2725 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002726
Emil Tantilov396e7992010-07-01 20:05:12 +00002727 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002728}
2729
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002730/**
2731 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2732 * @adapter: board private structure
2733 * @ring: structure containing ring specific data
2734 *
2735 * Configure the Tx descriptor ring after a reset.
2736 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002737void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2738 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002739{
2740 struct ixgbe_hw *hw = &adapter->hw;
2741 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002742 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002743 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002744 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002745
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002746 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002747 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002748 IXGBE_WRITE_FLUSH(hw);
2749
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002750 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002751 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002752 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2753 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2754 ring->count * sizeof(union ixgbe_adv_tx_desc));
2755 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2756 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002757 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002758
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002759 /*
2760 * set WTHRESH to encourage burst writeback, it should not be set
2761 * higher than 1 when ITR is 0 as it could cause false TX hangs
2762 *
2763 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2764 * to or less than the number of on chip descriptors, which is
2765 * currently 40.
2766 */
Alexander Duycke954b372012-02-08 07:49:38 +00002767 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002768 txdctl |= (1 << 16); /* WTHRESH = 1 */
2769 else
2770 txdctl |= (8 << 16); /* WTHRESH = 8 */
2771
Alexander Duycke954b372012-02-08 07:49:38 +00002772 /*
2773 * Setting PTHRESH to 32 both improves performance
2774 * and avoids a TX hang with DFP enabled
2775 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002776 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2777 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002778
2779 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002780 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002781 ring->atr_sample_rate = adapter->atr_sample_rate;
2782 ring->atr_count = 0;
2783 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2784 } else {
2785 ring->atr_sample_rate = 0;
2786 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002787
John Fastabendc84d3242010-11-16 19:27:12 -08002788 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2789
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002790 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002791 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2792
2793 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2794 if (hw->mac.type == ixgbe_mac_82598EB &&
2795 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2796 return;
2797
2798 /* poll to verify queue is enabled */
2799 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002800 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002801 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2802 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2803 if (!wait_loop)
2804 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002805}
2806
Alexander Duyck120ff942010-08-19 13:34:50 +00002807static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2808{
2809 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002810 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002811 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002812
2813 if (hw->mac.type == ixgbe_mac_82598EB)
2814 return;
2815
2816 /* disable the arbiter while setting MTQC */
2817 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2818 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2819 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2820
2821 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002822 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2823 mtqc = IXGBE_MTQC_VT_ENA;
2824 if (tcs > 4)
2825 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2826 else if (tcs > 1)
2827 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2828 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2829 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002830 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002831 mtqc |= IXGBE_MTQC_64VF;
2832 } else {
2833 if (tcs > 4)
2834 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2835 else if (tcs > 1)
2836 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2837 else
2838 mtqc = IXGBE_MTQC_64Q_1PB;
2839 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002840
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002841 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002842
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002843 /* Enable Security TX Buffer IFG for multiple pb */
2844 if (tcs) {
2845 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2846 sectx |= IXGBE_SECTX_DCB;
2847 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002848 }
2849
2850 /* re-enable the arbiter */
2851 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2852 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2853}
2854
Auke Kok9a799d72007-09-15 14:07:45 -07002855/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002856 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002857 * @adapter: board private structure
2858 *
2859 * Configure the Tx unit of the MAC after a reset.
2860 **/
2861static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2862{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002863 struct ixgbe_hw *hw = &adapter->hw;
2864 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002865 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002866
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002867 ixgbe_setup_mtqc(adapter);
2868
2869 if (hw->mac.type != ixgbe_mac_82598EB) {
2870 /* DMATXCTL.EN must be before Tx queues are enabled */
2871 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2872 dmatxctl |= IXGBE_DMATXCTL_TE;
2873 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2874 }
2875
Auke Kok9a799d72007-09-15 14:07:45 -07002876 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002877 for (i = 0; i < adapter->num_tx_queues; i++)
2878 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002879}
2880
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002881static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2882 struct ixgbe_ring *ring)
2883{
2884 struct ixgbe_hw *hw = &adapter->hw;
2885 u8 reg_idx = ring->reg_idx;
2886 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2887
2888 srrctl |= IXGBE_SRRCTL_DROP_EN;
2889
2890 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2891}
2892
2893static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2894 struct ixgbe_ring *ring)
2895{
2896 struct ixgbe_hw *hw = &adapter->hw;
2897 u8 reg_idx = ring->reg_idx;
2898 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2899
2900 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2901
2902 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2903}
2904
2905#ifdef CONFIG_IXGBE_DCB
2906void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2907#else
2908static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2909#endif
2910{
2911 int i;
2912 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2913
2914 if (adapter->ixgbe_ieee_pfc)
2915 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2916
2917 /*
2918 * We should set the drop enable bit if:
2919 * SR-IOV is enabled
2920 * or
2921 * Number of Rx queues > 1 and flow control is disabled
2922 *
2923 * This allows us to avoid head of line blocking for security
2924 * and performance reasons.
2925 */
2926 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2927 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2928 for (i = 0; i < adapter->num_rx_queues; i++)
2929 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2930 } else {
2931 for (i = 0; i < adapter->num_rx_queues; i++)
2932 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2933 }
2934}
2935
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002936#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002937
Yi Zoua6616b42009-08-06 13:05:23 +00002938static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002939 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002940{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002941 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002942 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002943 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002944
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002945 if (hw->mac.type == ixgbe_mac_82598EB) {
2946 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2947
2948 /*
2949 * if VMDq is not active we must program one srrctl register
2950 * per RSS queue since we have enabled RDRXCTL.MVMEN
2951 */
2952 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002953 }
2954
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002955 /* configure header buffer length, needed for RSC */
2956 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002957
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002958 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00002959 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002960
2961 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00002962 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002963
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002964 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002965}
2966
Alexander Duyck05abb122010-08-19 13:35:41 +00002967static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002968{
Alexander Duyck05abb122010-08-19 13:35:41 +00002969 struct ixgbe_hw *hw = &adapter->hw;
2970 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002971 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2972 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002973 u32 mrqc = 0, reta = 0;
2974 u32 rxcsum;
2975 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002976 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00002977
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002978 /*
2979 * Program table for at least 2 queues w/ SR-IOV so that VFs can
2980 * make full use of any rings they may have. We will use the
2981 * PSRTYPE register to control how many rings we use within the PF.
2982 */
2983 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
2984 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002985
Alexander Duyck05abb122010-08-19 13:35:41 +00002986 /* Fill out hash function seeds */
2987 for (i = 0; i < 10; i++)
2988 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002989
Alexander Duyck05abb122010-08-19 13:35:41 +00002990 /* Fill out redirection table */
2991 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002992 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00002993 j = 0;
2994 /* reta = 4-byte sliding window of
2995 * 0x00..(indices-1)(indices-1)00..etc. */
2996 reta = (reta << 8) | (j * 0x11);
2997 if ((i & 3) == 3)
2998 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2999 }
3000
3001 /* Disable indicating checksum in descriptor, enables RSS hash */
3002 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3003 rxcsum |= IXGBE_RXCSUM_PCSD;
3004 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3005
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003006 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003007 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003008 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003009 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003010 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003011
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003012 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3013 if (tcs > 4)
3014 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3015 else if (tcs > 1)
3016 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3017 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3018 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3019 else
3020 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3021 } else {
3022 if (tcs > 4)
3023 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3024 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003025 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3026 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003027 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003028 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003029 }
3030
Alexander Duyck05abb122010-08-19 13:35:41 +00003031 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003032 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3033 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3034 IXGBE_MRQC_RSS_FIELD_IPV6 |
3035 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003036
Alexander Duyckef6afc02012-02-08 07:51:53 +00003037 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3038 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3039 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3040 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3041
Alexander Duyck05abb122010-08-19 13:35:41 +00003042 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003043}
3044
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003045/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003046 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3047 * @adapter: address of board private structure
3048 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003049 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003050static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003051 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003052{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003053 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003054 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003055 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003056
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003057 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003058 return;
3059
Alexander Duyck73670962010-08-19 13:38:34 +00003060 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003061 rscctrl |= IXGBE_RSCCTL_RSCEN;
3062 /*
3063 * we must limit the number of descriptors so that the
3064 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003065 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003066 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003067 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003068 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003069}
3070
Alexander Duyck9e10e042010-08-19 13:40:06 +00003071#define IXGBE_MAX_RX_DESC_POLL 10
3072static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3073 struct ixgbe_ring *ring)
3074{
3075 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003076 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3077 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003078 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003079
3080 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3081 if (hw->mac.type == ixgbe_mac_82598EB &&
3082 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3083 return;
3084
3085 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003086 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003087 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3088 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3089
3090 if (!wait_loop) {
3091 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3092 "the polling period\n", reg_idx);
3093 }
3094}
3095
Yi Zou2d39d572011-01-06 14:29:56 +00003096void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3097 struct ixgbe_ring *ring)
3098{
3099 struct ixgbe_hw *hw = &adapter->hw;
3100 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3101 u32 rxdctl;
3102 u8 reg_idx = ring->reg_idx;
3103
3104 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3105 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3106
3107 /* write value back with RXDCTL.ENABLE bit cleared */
3108 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3109
3110 if (hw->mac.type == ixgbe_mac_82598EB &&
3111 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3112 return;
3113
3114 /* the hardware may take up to 100us to really disable the rx queue */
3115 do {
3116 udelay(10);
3117 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3118 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3119
3120 if (!wait_loop) {
3121 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3122 "the polling period\n", reg_idx);
3123 }
3124}
3125
Alexander Duyck84418e32010-08-19 13:40:54 +00003126void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3127 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003128{
3129 struct ixgbe_hw *hw = &adapter->hw;
3130 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003131 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003132 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003133
Alexander Duyck9e10e042010-08-19 13:40:06 +00003134 /* disable queue to avoid issues while updating state */
3135 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003136 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003137
Alexander Duyckacd37172010-08-19 13:36:05 +00003138 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3139 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3140 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3141 ring->count * sizeof(union ixgbe_adv_rx_desc));
3142 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3143 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003144 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003145
3146 ixgbe_configure_srrctl(adapter, ring);
3147 ixgbe_configure_rscctl(adapter, ring);
3148
Greg Rosee9f98072011-01-26 01:06:07 +00003149 /* If operating in IOV mode set RLPML for X540 */
3150 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3151 hw->mac.type == ixgbe_mac_X540) {
3152 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3153 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3154 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3155 }
3156
Alexander Duyck9e10e042010-08-19 13:40:06 +00003157 if (hw->mac.type == ixgbe_mac_82598EB) {
3158 /*
3159 * enable cache line friendly hardware writes:
3160 * PTHRESH=32 descriptors (half the internal cache),
3161 * this also removes ugly rx_no_buffer_count increment
3162 * HTHRESH=4 descriptors (to minimize latency on fetch)
3163 * WTHRESH=8 burst writeback up to two cache lines
3164 */
3165 rxdctl &= ~0x3FFFFF;
3166 rxdctl |= 0x080420;
3167 }
3168
3169 /* enable receive descriptor ring */
3170 rxdctl |= IXGBE_RXDCTL_ENABLE;
3171 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3172
3173 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003174 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003175}
3176
Alexander Duyck48654522010-08-19 13:36:27 +00003177static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3178{
3179 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003180 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003181 int p;
3182
3183 /* PSRTYPE must be initialized in non 82598 adapters */
3184 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003185 IXGBE_PSRTYPE_UDPHDR |
3186 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003187 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003188 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003189
3190 if (hw->mac.type == ixgbe_mac_82598EB)
3191 return;
3192
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003193 if (rss_i > 3)
3194 psrtype |= 2 << 29;
3195 else if (rss_i > 1)
3196 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003197
3198 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003199 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003200 psrtype);
3201}
3202
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003203static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3204{
3205 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003206 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003207 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003208 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003209
3210 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3211 return;
3212
3213 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003214 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3215 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003216 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003217 vmdctl |= IXGBE_VT_CTL_REPLEN;
3218 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003219
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003220 vf_shift = VMDQ_P(0) % 32;
3221 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003222
3223 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003224 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3225 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3226 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3227 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003228
3229 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003230 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003231
3232 /*
3233 * Set up VF register offsets for selected VT Mode,
3234 * i.e. 32 or 64 VFs for SR-IOV
3235 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003236 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3237 case IXGBE_82599_VMDQ_8Q_MASK:
3238 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3239 break;
3240 case IXGBE_82599_VMDQ_4Q_MASK:
3241 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3242 break;
3243 default:
3244 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3245 break;
3246 }
3247
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003248 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3249
Alexander Duyck435b19f2012-05-18 06:34:08 +00003250
Greg Rosea985b6c32010-11-18 03:02:52 +00003251 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003252 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003253 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003254 /* For VFs that have spoof checking turned off */
3255 for (i = 0; i < adapter->num_vfs; i++) {
3256 if (!adapter->vfinfo[i].spoofchk_enabled)
3257 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3258 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003259}
3260
Alexander Duyck477de6e2010-08-19 13:38:11 +00003261static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003262{
Auke Kok9a799d72007-09-15 14:07:45 -07003263 struct ixgbe_hw *hw = &adapter->hw;
3264 struct net_device *netdev = adapter->netdev;
3265 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003266 struct ixgbe_ring *rx_ring;
3267 int i;
3268 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003269
Alexander Duyck477de6e2010-08-19 13:38:11 +00003270#ifdef IXGBE_FCOE
3271 /* adjust max frame to be able to do baby jumbo for FCoE */
3272 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3273 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3274 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3275
3276#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003277
3278 /* adjust max frame to be at least the size of a standard frame */
3279 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3280 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3281
Alexander Duyck477de6e2010-08-19 13:38:11 +00003282 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3283 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3284 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3285 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3286
3287 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003288 }
3289
Auke Kok9a799d72007-09-15 14:07:45 -07003290 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003291 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3292 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003293 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3294
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003295 /*
3296 * Setup the HW Rx Head and Tail Descriptor Pointers and
3297 * the Base and Length of the Rx Descriptor Ring
3298 */
Auke Kok9a799d72007-09-15 14:07:45 -07003299 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003300 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003301 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3302 set_ring_rsc_enabled(rx_ring);
3303 else
3304 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003305 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003306}
3307
Alexander Duyck73670962010-08-19 13:38:34 +00003308static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3309{
3310 struct ixgbe_hw *hw = &adapter->hw;
3311 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3312
3313 switch (hw->mac.type) {
3314 case ixgbe_mac_82598EB:
3315 /*
3316 * For VMDq support of different descriptor types or
3317 * buffer sizes through the use of multiple SRRCTL
3318 * registers, RDRXCTL.MVMEN must be set to 1
3319 *
3320 * also, the manual doesn't mention it clearly but DCA hints
3321 * will only use queue 0's tags unless this bit is set. Side
3322 * effects of setting this bit are only that SRRCTL must be
3323 * fully programmed [0..15]
3324 */
3325 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3326 break;
3327 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003328 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003329 /* Disable RSC for ACK packets */
3330 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3331 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3332 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3333 /* hardware requires some bits to be set by default */
3334 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3335 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3336 break;
3337 default:
3338 /* We should do nothing since we don't know this hardware */
3339 return;
3340 }
3341
3342 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3343}
3344
Alexander Duyck477de6e2010-08-19 13:38:11 +00003345/**
3346 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3347 * @adapter: board private structure
3348 *
3349 * Configure the Rx unit of the MAC after a reset.
3350 **/
3351static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3352{
3353 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003354 int i;
3355 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003356
3357 /* disable receives while setting up the descriptors */
3358 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3359 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3360
3361 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003362 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003363
Alexander Duyck9e10e042010-08-19 13:40:06 +00003364 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003365 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003366
Alexander Duyck477de6e2010-08-19 13:38:11 +00003367 /* set_rx_buffer_len must be called before ring initialization */
3368 ixgbe_set_rx_buffer_len(adapter);
3369
3370 /*
3371 * Setup the HW Rx Head and Tail Descriptor Pointers and
3372 * the Base and Length of the Rx Descriptor Ring
3373 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003374 for (i = 0; i < adapter->num_rx_queues; i++)
3375 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003376
Alexander Duyck9e10e042010-08-19 13:40:06 +00003377 /* disable drop enable for 82598 parts */
3378 if (hw->mac.type == ixgbe_mac_82598EB)
3379 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3380
3381 /* enable all receives */
3382 rxctrl |= IXGBE_RXCTRL_RXEN;
3383 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003384}
3385
Jiri Pirko8e586132011-12-08 19:52:37 -05003386static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003387{
3388 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003389 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003390
3391 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003392 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003393 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003394
3395 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003396}
3397
Jiri Pirko8e586132011-12-08 19:52:37 -05003398static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003399{
3400 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003401 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003402
Auke Kok9a799d72007-09-15 14:07:45 -07003403 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003404 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003405 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003406
3407 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003408}
3409
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003410/**
3411 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3412 * @adapter: driver data
3413 */
3414static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3415{
3416 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003417 u32 vlnctrl;
3418
3419 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3420 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3421 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3422}
3423
3424/**
3425 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3426 * @adapter: driver data
3427 */
3428static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3429{
3430 struct ixgbe_hw *hw = &adapter->hw;
3431 u32 vlnctrl;
3432
3433 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3434 vlnctrl |= IXGBE_VLNCTRL_VFE;
3435 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3436 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3437}
3438
3439/**
3440 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3441 * @adapter: driver data
3442 */
3443static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3444{
3445 struct ixgbe_hw *hw = &adapter->hw;
3446 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003447 int i, j;
3448
3449 switch (hw->mac.type) {
3450 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003451 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3452 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003453 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3454 break;
3455 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003456 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003457 for (i = 0; i < adapter->num_rx_queues; i++) {
3458 j = adapter->rx_ring[i]->reg_idx;
3459 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3460 vlnctrl &= ~IXGBE_RXDCTL_VME;
3461 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3462 }
3463 break;
3464 default:
3465 break;
3466 }
3467}
3468
3469/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003470 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003471 * @adapter: driver data
3472 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003473static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003474{
3475 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003476 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003477 int i, j;
3478
3479 switch (hw->mac.type) {
3480 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003481 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3482 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003483 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3484 break;
3485 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003486 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003487 for (i = 0; i < adapter->num_rx_queues; i++) {
3488 j = adapter->rx_ring[i]->reg_idx;
3489 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3490 vlnctrl |= IXGBE_RXDCTL_VME;
3491 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3492 }
3493 break;
3494 default:
3495 break;
3496 }
3497}
3498
Auke Kok9a799d72007-09-15 14:07:45 -07003499static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3500{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003501 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003502
Jesse Grossf62bbb52010-10-20 13:56:10 +00003503 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3504
3505 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3506 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003507}
3508
3509/**
Alexander Duyck28500622010-06-15 09:25:48 +00003510 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3511 * @netdev: network interface device structure
3512 *
3513 * Writes unicast address list to the RAR table.
3514 * Returns: -ENOMEM on failure/insufficient address space
3515 * 0 on no addresses written
3516 * X on writing X addresses to the RAR table
3517 **/
3518static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3519{
3520 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3521 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003522 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003523 int count = 0;
3524
John Fastabend95447462012-05-31 12:42:26 +00003525 /* In SR-IOV mode significantly less RAR entries are available */
3526 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3527 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3528
Alexander Duyck28500622010-06-15 09:25:48 +00003529 /* return ENOMEM indicating insufficient memory for addresses */
3530 if (netdev_uc_count(netdev) > rar_entries)
3531 return -ENOMEM;
3532
John Fastabend95447462012-05-31 12:42:26 +00003533 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003534 struct netdev_hw_addr *ha;
3535 /* return error if we do not support writing to RAR table */
3536 if (!hw->mac.ops.set_rar)
3537 return -ENOMEM;
3538
3539 netdev_for_each_uc_addr(ha, netdev) {
3540 if (!rar_entries)
3541 break;
3542 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003543 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003544 count++;
3545 }
3546 }
3547 /* write the addresses in reverse order to avoid write combining */
3548 for (; rar_entries > 0 ; rar_entries--)
3549 hw->mac.ops.clear_rar(hw, rar_entries);
3550
3551 return count;
3552}
3553
3554/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003555 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003556 * @netdev: network interface device structure
3557 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003558 * The set_rx_method entry point is called whenever the unicast/multicast
3559 * address list or the network interface flags are updated. This routine is
3560 * responsible for configuring the hardware for proper unicast, multicast and
3561 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003562 **/
Greg Rose7f870472010-01-09 02:25:29 +00003563void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003564{
3565 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3566 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003567 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3568 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003569
3570 /* Check for Promiscuous and All Multicast modes */
3571
3572 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3573
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003574 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003575 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003576 fctrl |= IXGBE_FCTRL_BAM;
3577 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3578 fctrl |= IXGBE_FCTRL_PMCF;
3579
Alexander Duyck28500622010-06-15 09:25:48 +00003580 /* clear the bits we are changing the status of */
3581 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3582
Auke Kok9a799d72007-09-15 14:07:45 -07003583 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003584 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003585 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003586 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003587 /* don't hardware filter vlans in promisc mode */
3588 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003589 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003590 if (netdev->flags & IFF_ALLMULTI) {
3591 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003592 vmolr |= IXGBE_VMOLR_MPE;
3593 } else {
3594 /*
3595 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003596 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003597 * that we can at least receive multicast traffic
3598 */
3599 hw->mac.ops.update_mc_addr_list(hw, netdev);
3600 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003601 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003602 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003603 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003604 }
3605
3606 /*
3607 * Write addresses to available RAR registers, if there is not
3608 * sufficient space to store all the addresses then enable
3609 * unicast promiscuous mode
3610 */
3611 count = ixgbe_write_uc_addr_list(netdev);
3612 if (count < 0) {
3613 fctrl |= IXGBE_FCTRL_UPE;
3614 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003615 }
3616
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003617 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003618 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003619
3620 if (hw->mac.type != ixgbe_mac_82598EB) {
3621 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003622 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3623 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003624 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003625 }
3626
Ben Greear3f2d1c02012-03-08 08:28:41 +00003627 /* This is useful for sniffing bad packets. */
3628 if (adapter->netdev->features & NETIF_F_RXALL) {
3629 /* UPE and MPE will be handled by normal PROMISC logic
3630 * in e1000e_set_rx_mode */
3631 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3632 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3633 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3634
3635 fctrl &= ~(IXGBE_FCTRL_DPF);
3636 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3637 }
3638
Auke Kok9a799d72007-09-15 14:07:45 -07003639 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003640
3641 if (netdev->features & NETIF_F_HW_VLAN_RX)
3642 ixgbe_vlan_strip_enable(adapter);
3643 else
3644 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003645}
3646
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003647static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3648{
3649 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003650
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003651 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3652 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003653}
3654
3655static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3656{
3657 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003658
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003659 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3660 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003661}
3662
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003663#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003664/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003665 * ixgbe_configure_dcb - Configure DCB hardware
3666 * @adapter: ixgbe adapter struct
3667 *
3668 * This is called by the driver on open to configure the DCB hardware.
3669 * This is also called by the gennetlink interface when reconfiguring
3670 * the DCB state.
3671 */
3672static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3673{
3674 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003675 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003676
Alexander Duyck67ebd792010-08-19 13:34:04 +00003677 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3678 if (hw->mac.type == ixgbe_mac_82598EB)
3679 netif_set_gso_max_size(adapter->netdev, 65536);
3680 return;
3681 }
3682
3683 if (hw->mac.type == ixgbe_mac_82598EB)
3684 netif_set_gso_max_size(adapter->netdev, 32768);
3685
John Fastabendb1208182011-10-15 05:00:10 +00003686#ifdef IXGBE_FCOE
3687 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3688 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3689#endif
3690
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003691 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003692 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003693 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3694 DCB_TX_CONFIG);
3695 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3696 DCB_RX_CONFIG);
3697 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003698 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3699 ixgbe_dcb_hw_ets(&adapter->hw,
3700 adapter->ixgbe_ieee_ets,
3701 max_frame);
3702 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3703 adapter->ixgbe_ieee_pfc->pfc_en,
3704 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003705 }
John Fastabend8187cd42011-02-23 05:58:08 +00003706
3707 /* Enable RSS Hash per TC */
3708 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003709 u32 msb = 0;
3710 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003711
Alexander Duyckd411a932012-06-30 00:14:01 +00003712 while (rss_i) {
3713 msb++;
3714 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003715 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003716
Alexander Duyck4ae63732012-06-22 06:46:33 +00003717 /* write msb to all 8 TCs in one write */
3718 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003719 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003720}
John Fastabend9da712d2011-08-23 03:14:22 +00003721#endif
3722
3723/* Additional bittime to account for IXGBE framing */
3724#define IXGBE_ETH_FRAMING 20
3725
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003726/**
John Fastabend9da712d2011-08-23 03:14:22 +00003727 * ixgbe_hpbthresh - calculate high water mark for flow control
3728 *
3729 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003730 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003731 */
3732static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3733{
3734 struct ixgbe_hw *hw = &adapter->hw;
3735 struct net_device *dev = adapter->netdev;
3736 int link, tc, kb, marker;
3737 u32 dv_id, rx_pba;
3738
3739 /* Calculate max LAN frame size */
3740 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3741
3742#ifdef IXGBE_FCOE
3743 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003744 if ((dev->features & NETIF_F_FCOE_MTU) &&
3745 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3746 (pb == ixgbe_fcoe_get_tc(adapter)))
3747 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003748
3749#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003750 /* Calculate delay value for device */
3751 switch (hw->mac.type) {
3752 case ixgbe_mac_X540:
3753 dv_id = IXGBE_DV_X540(link, tc);
3754 break;
3755 default:
3756 dv_id = IXGBE_DV(link, tc);
3757 break;
3758 }
3759
3760 /* Loopback switch introduces additional latency */
3761 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3762 dv_id += IXGBE_B2BT(tc);
3763
3764 /* Delay value is calculated in bit times convert to KB */
3765 kb = IXGBE_BT2KB(dv_id);
3766 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3767
3768 marker = rx_pba - kb;
3769
3770 /* It is possible that the packet buffer is not large enough
3771 * to provide required headroom. In this case throw an error
3772 * to user and a do the best we can.
3773 */
3774 if (marker < 0) {
3775 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3776 "headroom to support flow control."
3777 "Decrease MTU or number of traffic classes\n", pb);
3778 marker = tc + 1;
3779 }
3780
3781 return marker;
3782}
3783
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003784/**
John Fastabend9da712d2011-08-23 03:14:22 +00003785 * ixgbe_lpbthresh - calculate low water mark for for flow control
3786 *
3787 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003788 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003789 */
3790static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3791{
3792 struct ixgbe_hw *hw = &adapter->hw;
3793 struct net_device *dev = adapter->netdev;
3794 int tc;
3795 u32 dv_id;
3796
3797 /* Calculate max LAN frame size */
3798 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3799
3800 /* Calculate delay value for device */
3801 switch (hw->mac.type) {
3802 case ixgbe_mac_X540:
3803 dv_id = IXGBE_LOW_DV_X540(tc);
3804 break;
3805 default:
3806 dv_id = IXGBE_LOW_DV(tc);
3807 break;
3808 }
3809
3810 /* Delay value is calculated in bit times convert to KB */
3811 return IXGBE_BT2KB(dv_id);
3812}
3813
3814/*
3815 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3816 */
3817static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3818{
3819 struct ixgbe_hw *hw = &adapter->hw;
3820 int num_tc = netdev_get_num_tc(adapter->netdev);
3821 int i;
3822
3823 if (!num_tc)
3824 num_tc = 1;
3825
3826 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3827
3828 for (i = 0; i < num_tc; i++) {
3829 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3830
3831 /* Low water marks must not be larger than high water marks */
3832 if (hw->fc.low_water > hw->fc.high_water[i])
3833 hw->fc.low_water = 0;
3834 }
3835}
John Fastabend80605c652011-05-02 12:34:10 +00003836
3837static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3838{
John Fastabend80605c652011-05-02 12:34:10 +00003839 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003840 int hdrm;
3841 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003842
3843 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3844 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003845 hdrm = 32 << adapter->fdir_pballoc;
3846 else
3847 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003848
Alexander Duyckf7e10272011-07-21 00:40:35 +00003849 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003850 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003851}
3852
Alexander Duycke4911d52011-05-11 07:18:52 +00003853static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3854{
3855 struct ixgbe_hw *hw = &adapter->hw;
3856 struct hlist_node *node, *node2;
3857 struct ixgbe_fdir_filter *filter;
3858
3859 spin_lock(&adapter->fdir_perfect_lock);
3860
3861 if (!hlist_empty(&adapter->fdir_filter_list))
3862 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3863
3864 hlist_for_each_entry_safe(filter, node, node2,
3865 &adapter->fdir_filter_list, fdir_node) {
3866 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003867 &filter->filter,
3868 filter->sw_idx,
3869 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3870 IXGBE_FDIR_DROP_QUEUE :
3871 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003872 }
3873
3874 spin_unlock(&adapter->fdir_perfect_lock);
3875}
3876
Auke Kok9a799d72007-09-15 14:07:45 -07003877static void ixgbe_configure(struct ixgbe_adapter *adapter)
3878{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003879 struct ixgbe_hw *hw = &adapter->hw;
3880
John Fastabend80605c652011-05-02 12:34:10 +00003881 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003882#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003883 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003884#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00003885 /*
3886 * We must restore virtualization before VLANs or else
3887 * the VLVF registers will not be populated
3888 */
3889 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003890
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003891 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003892 ixgbe_restore_vlan(adapter);
3893
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003894 switch (hw->mac.type) {
3895 case ixgbe_mac_82599EB:
3896 case ixgbe_mac_X540:
3897 hw->mac.ops.disable_rx_buff(hw);
3898 break;
3899 default:
3900 break;
3901 }
3902
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003903 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003904 ixgbe_init_fdir_signature_82599(&adapter->hw,
3905 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003906 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3907 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3908 adapter->fdir_pballoc);
3909 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003910 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003911
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003912 switch (hw->mac.type) {
3913 case ixgbe_mac_82599EB:
3914 case ixgbe_mac_X540:
3915 hw->mac.ops.enable_rx_buff(hw);
3916 break;
3917 default:
3918 break;
3919 }
3920
Alexander Duyck7c8ae652012-05-05 05:32:47 +00003921#ifdef IXGBE_FCOE
3922 /* configure FCoE L2 filters, redirection table, and Rx control */
3923 ixgbe_configure_fcoe(adapter);
3924
3925#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07003926 ixgbe_configure_tx(adapter);
3927 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003928}
3929
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003930static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3931{
3932 switch (hw->phy.type) {
3933 case ixgbe_phy_sfp_avago:
3934 case ixgbe_phy_sfp_ftl:
3935 case ixgbe_phy_sfp_intel:
3936 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003937 case ixgbe_phy_sfp_passive_tyco:
3938 case ixgbe_phy_sfp_passive_unknown:
3939 case ixgbe_phy_sfp_active_unknown:
3940 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003941 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003942 case ixgbe_phy_nl:
3943 if (hw->mac.type == ixgbe_mac_82598EB)
3944 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003945 default:
3946 return false;
3947 }
3948}
3949
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003950/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003951 * ixgbe_sfp_link_config - set up SFP+ link
3952 * @adapter: pointer to private adapter struct
3953 **/
3954static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3955{
Alexander Duyck70864002011-04-27 09:13:56 +00003956 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003957 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003958 * is that an SFP was inserted/removed after the reset
3959 * but before SFP detection was enabled. As such the best
3960 * solution is to just start searching as soon as we start
3961 */
3962 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3963 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003964
Alexander Duyck70864002011-04-27 09:13:56 +00003965 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003966}
3967
3968/**
3969 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003970 * @hw: pointer to private hardware struct
3971 *
3972 * Returns 0 on success, negative on failure
3973 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003974static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003975{
3976 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003977 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003978 u32 ret = IXGBE_ERR_LINK_SETUP;
3979
3980 if (hw->mac.ops.check_link)
3981 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3982
3983 if (ret)
3984 goto link_cfg_out;
3985
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003986 autoneg = hw->phy.autoneg_advertised;
3987 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003988 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3989 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003990 if (ret)
3991 goto link_cfg_out;
3992
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003993 if (hw->mac.ops.setup_link)
3994 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003995link_cfg_out:
3996 return ret;
3997}
3998
Alexander Duycka34bcff2010-08-19 13:39:20 +00003999static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004000{
Auke Kok9a799d72007-09-15 14:07:45 -07004001 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004002 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004003
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004004 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004005 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4006 IXGBE_GPIE_OCD;
4007 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004008 /*
4009 * use EIAM to auto-mask when MSI-X interrupt is asserted
4010 * this saves a register write for every interrupt
4011 */
4012 switch (hw->mac.type) {
4013 case ixgbe_mac_82598EB:
4014 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4015 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004016 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004017 case ixgbe_mac_X540:
4018 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004019 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4020 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4021 break;
4022 }
4023 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004024 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4025 * specifically only auto mask tx and rx interrupts */
4026 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004027 }
4028
Alexander Duycka34bcff2010-08-19 13:39:20 +00004029 /* XXX: to interrupt immediately for EICS writes, enable this */
4030 /* gpie |= IXGBE_GPIE_EIMEN; */
4031
4032 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4033 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004034
4035 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4036 case IXGBE_82599_VMDQ_8Q_MASK:
4037 gpie |= IXGBE_GPIE_VTMODE_16;
4038 break;
4039 case IXGBE_82599_VMDQ_4Q_MASK:
4040 gpie |= IXGBE_GPIE_VTMODE_32;
4041 break;
4042 default:
4043 gpie |= IXGBE_GPIE_VTMODE_64;
4044 break;
4045 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004046 }
4047
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004048 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004049 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4050 switch (adapter->hw.mac.type) {
4051 case ixgbe_mac_82599EB:
4052 gpie |= IXGBE_SDP0_GPIEN;
4053 break;
4054 case ixgbe_mac_X540:
4055 gpie |= IXGBE_EIMS_TS;
4056 break;
4057 default:
4058 break;
4059 }
4060 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004061
Alexander Duycka34bcff2010-08-19 13:39:20 +00004062 /* Enable fan failure interrupt */
4063 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004064 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004065
Don Skidmore2698b202011-04-13 07:01:52 +00004066 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004067 gpie |= IXGBE_SDP1_GPIEN;
4068 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004069 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004070
4071 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4072}
4073
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004074static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004075{
4076 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004077 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004078 u32 ctrl_ext;
4079
4080 ixgbe_get_hw_control(adapter);
4081 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004082
Auke Kok9a799d72007-09-15 14:07:45 -07004083 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4084 ixgbe_configure_msix(adapter);
4085 else
4086 ixgbe_configure_msi_and_legacy(adapter);
4087
Don Skidmorec6ecf392010-12-03 03:31:51 +00004088 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
4089 if (hw->mac.ops.enable_tx_laser &&
4090 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004091 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004092 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004093 hw->mac.ops.enable_tx_laser(hw);
4094
Auke Kok9a799d72007-09-15 14:07:45 -07004095 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004096 ixgbe_napi_enable_all(adapter);
4097
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004098 if (ixgbe_is_sfp(hw)) {
4099 ixgbe_sfp_link_config(adapter);
4100 } else {
4101 err = ixgbe_non_sfp_link_config(hw);
4102 if (err)
4103 e_err(probe, "link_config FAILED %d\n", err);
4104 }
4105
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004106 /* clear any pending interrupts, may auto mask */
4107 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004108 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004109
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004110 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004111 * If this adapter has a fan, check to see if we had a failure
4112 * before we enabled the interrupt.
4113 */
4114 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4115 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4116 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004117 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004118 }
4119
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004120 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004121 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004122
Auke Kok9a799d72007-09-15 14:07:45 -07004123 /* bring the link up in the watchdog, this could race with our first
4124 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004125 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4126 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004127 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004128
4129 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4130 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4131 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4132 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004133}
4134
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004135void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4136{
4137 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004138 /* put off any impending NetWatchDogTimeout */
4139 adapter->netdev->trans_start = jiffies;
4140
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004141 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004142 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004143 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004144 /*
4145 * If SR-IOV enabled then wait a bit before bringing the adapter
4146 * back up to give the VFs time to respond to the reset. The
4147 * two second wait is based upon the watchdog timer cycle in
4148 * the VF driver.
4149 */
4150 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4151 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004152 ixgbe_up(adapter);
4153 clear_bit(__IXGBE_RESETTING, &adapter->state);
4154}
4155
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004156void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004157{
4158 /* hardware has been reset, we need to reload some things */
4159 ixgbe_configure(adapter);
4160
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004161 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004162}
4163
4164void ixgbe_reset(struct ixgbe_adapter *adapter)
4165{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004166 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004167 int err;
4168
Alexander Duyck70864002011-04-27 09:13:56 +00004169 /* lock SFP init bit to prevent race conditions with the watchdog */
4170 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4171 usleep_range(1000, 2000);
4172
4173 /* clear all SFP and link config related flags while holding SFP_INIT */
4174 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4175 IXGBE_FLAG2_SFP_NEEDS_RESET);
4176 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4177
Don Skidmore8ca783a2009-05-26 20:40:47 -07004178 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004179 switch (err) {
4180 case 0:
4181 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004182 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004183 break;
4184 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004185 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004186 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004187 case IXGBE_ERR_EEPROM_VERSION:
4188 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004189 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004190 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004191 "your hardware. If you are experiencing problems "
4192 "please contact your Intel or hardware "
4193 "representative who provided you with this "
4194 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004195 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004196 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004197 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004198 }
Auke Kok9a799d72007-09-15 14:07:45 -07004199
Alexander Duyck70864002011-04-27 09:13:56 +00004200 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4201
Auke Kok9a799d72007-09-15 14:07:45 -07004202 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004203 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004204
4205 /* update SAN MAC vmdq pool selection */
4206 if (hw->mac.san_mac_rar_index)
4207 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004208
4209#ifdef CONFIG_IXGBE_PTP
4210 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4211 ixgbe_ptp_reset(adapter);
4212#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004213}
4214
Auke Kok9a799d72007-09-15 14:07:45 -07004215/**
4216 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004217 * @rx_ring: ring to free buffers from
4218 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004219static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004220{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004221 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004222 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004223 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004224
Alexander Duyck84418e32010-08-19 13:40:54 +00004225 /* ring already cleared, nothing to do */
4226 if (!rx_ring->rx_buffer_info)
4227 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004228
Alexander Duyck84418e32010-08-19 13:40:54 +00004229 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004230 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004231 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004232
Alexander Duyckf8003262012-03-03 02:35:52 +00004233 rx_buffer = &rx_ring->rx_buffer_info[i];
4234 if (rx_buffer->skb) {
4235 struct sk_buff *skb = rx_buffer->skb;
4236 if (IXGBE_CB(skb)->page_released) {
4237 dma_unmap_page(dev,
4238 IXGBE_CB(skb)->dma,
4239 ixgbe_rx_bufsz(rx_ring),
4240 DMA_FROM_DEVICE);
4241 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004242 }
4243 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004244 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004245 rx_buffer->skb = NULL;
4246 if (rx_buffer->dma)
4247 dma_unmap_page(dev, rx_buffer->dma,
4248 ixgbe_rx_pg_size(rx_ring),
4249 DMA_FROM_DEVICE);
4250 rx_buffer->dma = 0;
4251 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004252 __free_pages(rx_buffer->page,
4253 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004254 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004255 }
4256
4257 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4258 memset(rx_ring->rx_buffer_info, 0, size);
4259
4260 /* Zero out the descriptor ring */
4261 memset(rx_ring->desc, 0, rx_ring->size);
4262
Alexander Duyckf8003262012-03-03 02:35:52 +00004263 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004264 rx_ring->next_to_clean = 0;
4265 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004266}
4267
4268/**
4269 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004270 * @tx_ring: ring to be cleaned
4271 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004272static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004273{
4274 struct ixgbe_tx_buffer *tx_buffer_info;
4275 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004276 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004277
Alexander Duyck84418e32010-08-19 13:40:54 +00004278 /* ring already cleared, nothing to do */
4279 if (!tx_ring->tx_buffer_info)
4280 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004281
Alexander Duyck84418e32010-08-19 13:40:54 +00004282 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004283 for (i = 0; i < tx_ring->count; i++) {
4284 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004285 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004286 }
4287
John Fastabenddad8a3b2012-04-23 12:22:39 +00004288 netdev_tx_reset_queue(txring_txq(tx_ring));
4289
Auke Kok9a799d72007-09-15 14:07:45 -07004290 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4291 memset(tx_ring->tx_buffer_info, 0, size);
4292
4293 /* Zero out the descriptor ring */
4294 memset(tx_ring->desc, 0, tx_ring->size);
4295
4296 tx_ring->next_to_use = 0;
4297 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004298}
4299
4300/**
Auke Kok9a799d72007-09-15 14:07:45 -07004301 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4302 * @adapter: board private structure
4303 **/
4304static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4305{
4306 int i;
4307
4308 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004309 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004310}
4311
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004312/**
4313 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4314 * @adapter: board private structure
4315 **/
4316static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4317{
4318 int i;
4319
4320 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004321 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004322}
4323
Alexander Duycke4911d52011-05-11 07:18:52 +00004324static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4325{
4326 struct hlist_node *node, *node2;
4327 struct ixgbe_fdir_filter *filter;
4328
4329 spin_lock(&adapter->fdir_perfect_lock);
4330
4331 hlist_for_each_entry_safe(filter, node, node2,
4332 &adapter->fdir_filter_list, fdir_node) {
4333 hlist_del(&filter->fdir_node);
4334 kfree(filter);
4335 }
4336 adapter->fdir_filter_count = 0;
4337
4338 spin_unlock(&adapter->fdir_perfect_lock);
4339}
4340
Auke Kok9a799d72007-09-15 14:07:45 -07004341void ixgbe_down(struct ixgbe_adapter *adapter)
4342{
4343 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004344 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004345 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004346 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004347
4348 /* signal that we are down to the interrupt handler */
4349 set_bit(__IXGBE_DOWN, &adapter->state);
4350
4351 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004352 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4353 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004354
Yi Zou2d39d572011-01-06 14:29:56 +00004355 /* disable all enabled rx queues */
4356 for (i = 0; i < adapter->num_rx_queues; i++)
4357 /* this call also flushes the previous write */
4358 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4359
Don Skidmore032b4322011-03-18 09:32:53 +00004360 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004361
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004362 netif_tx_stop_all_queues(netdev);
4363
Alexander Duyck70864002011-04-27 09:13:56 +00004364 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004365 netif_carrier_off(netdev);
4366 netif_tx_disable(netdev);
4367
4368 ixgbe_irq_disable(adapter);
4369
4370 ixgbe_napi_disable_all(adapter);
4371
Alexander Duyckd034acf2011-04-27 09:25:34 +00004372 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4373 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004374 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4375
4376 del_timer_sync(&adapter->service_timer);
4377
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004378 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004379 /* Clear EITR Select mapping */
4380 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4381
4382 /* Mark all the VFs as inactive */
4383 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004384 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004385
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004386 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004387 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004388
Auke Kok9a799d72007-09-15 14:07:45 -07004389 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004390 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004391 }
4392
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004393 /* disable transmits in the hardware now that interrupts are off */
4394 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004395 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004396 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004397 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004398
4399 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004400 switch (hw->mac.type) {
4401 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004402 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004403 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004404 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4405 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004406 break;
4407 default:
4408 break;
4409 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004410
Paul Larson6f4a0e42008-06-24 17:00:56 -07004411 if (!pci_channel_offline(adapter->pdev))
4412 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004413
4414 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4415 if (hw->mac.ops.disable_tx_laser &&
4416 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004417 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004418 (hw->mac.type == ixgbe_mac_82599EB))))
4419 hw->mac.ops.disable_tx_laser(hw);
4420
Auke Kok9a799d72007-09-15 14:07:45 -07004421 ixgbe_clean_all_tx_rings(adapter);
4422 ixgbe_clean_all_rx_rings(adapter);
4423
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004424#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004425 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004426 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004427#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004428}
4429
Auke Kok9a799d72007-09-15 14:07:45 -07004430/**
Auke Kok9a799d72007-09-15 14:07:45 -07004431 * ixgbe_tx_timeout - Respond to a Tx Hang
4432 * @netdev: network interface device structure
4433 **/
4434static void ixgbe_tx_timeout(struct net_device *netdev)
4435{
4436 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4437
4438 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004439 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004440}
4441
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004442/**
Auke Kok9a799d72007-09-15 14:07:45 -07004443 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4444 * @adapter: board private structure to initialize
4445 *
4446 * ixgbe_sw_init initializes the Adapter private data structure.
4447 * Fields are initialized based on PCI device information and
4448 * OS network device settings (MTU size).
4449 **/
4450static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4451{
4452 struct ixgbe_hw *hw = &adapter->hw;
4453 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004454 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004455#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004456 int j;
4457 struct tc_configuration *tc;
4458#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004459
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004460 /* PCI config space info */
4461
4462 hw->vendor_id = pdev->vendor;
4463 hw->device_id = pdev->device;
4464 hw->revision_id = pdev->revision;
4465 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4466 hw->subsystem_device_id = pdev->subsystem_device;
4467
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004468 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004469 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004470 adapter->ring_feature[RING_F_RSS].limit = rss;
Alexander Duyckbd508172010-11-16 19:27:03 -08004471 switch (hw->mac.type) {
4472 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004473 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4474 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004475 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004476 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004477 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004478 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4479 case ixgbe_mac_82599EB:
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004480 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004481 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4482 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004483 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4484 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004485 /* Flow Director hash filters enabled */
Alexander Duyck45b9f502011-01-06 14:29:59 +00004486 adapter->atr_sample_rate = 20;
Alexander Duyckc0876632012-05-10 00:01:46 +00004487 adapter->ring_feature[RING_F_FDIR].limit =
Joe Perchese8e9f692010-09-07 21:34:53 +00004488 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004489 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004490#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004491 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4492 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
Yi Zou61a0f422009-12-03 11:32:22 +00004493#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004494 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004495 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004496#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004497#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004498 break;
4499 default:
4500 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004501 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004502
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004503#ifdef IXGBE_FCOE
4504 /* FCoE support exists, always init the FCoE lock */
4505 spin_lock_init(&adapter->fcoe.lock);
4506
4507#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004508 /* n-tuple support exists, always init our spinlock */
4509 spin_lock_init(&adapter->fdir_perfect_lock);
4510
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004511#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004512 switch (hw->mac.type) {
4513 case ixgbe_mac_X540:
4514 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4515 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4516 break;
4517 default:
4518 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4519 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4520 break;
4521 }
4522
Alexander Duyck2f90b862008-11-20 20:52:10 -08004523 /* Configure DCB traffic classes */
4524 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4525 tc = &adapter->dcb_cfg.tc_config[j];
4526 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4527 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4528 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4529 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4530 tc->dcb_pfc = pfc_disabled;
4531 }
John Fastabend4de2a022011-09-27 03:52:01 +00004532
4533 /* Initialize default user to priority mapping, UPx->TC0 */
4534 tc = &adapter->dcb_cfg.tc_config[0];
4535 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4536 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4537
Alexander Duyck2f90b862008-11-20 20:52:10 -08004538 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4539 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004540 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004541 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004542 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004543 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4544 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004545
4546#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004547
4548 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004549 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004550 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004551 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004552 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4553 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004554 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004555
Alexander Duyck99d74482012-05-09 08:09:25 +00004556#ifdef CONFIG_PCI_IOV
4557 /* assign number of SR-IOV VFs */
4558 if (hw->mac.type != ixgbe_mac_82598EB)
4559 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4560
4561#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004562 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004563 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004564 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004565
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004566 /* set default ring sizes */
4567 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4568 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4569
Alexander Duyckbd198052011-06-11 01:45:08 +00004570 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004571 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004572
Auke Kok9a799d72007-09-15 14:07:45 -07004573 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004574 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004575 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004576 return -EIO;
4577 }
4578
Auke Kok9a799d72007-09-15 14:07:45 -07004579 set_bit(__IXGBE_DOWN, &adapter->state);
4580
4581 return 0;
4582}
4583
4584/**
4585 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004586 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004587 *
4588 * Return 0 on success, negative on failure
4589 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004590int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004591{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004592 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004593 int orig_node = dev_to_node(dev);
4594 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004595 int size;
4596
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004597 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004598
4599 if (tx_ring->q_vector)
4600 numa_node = tx_ring->q_vector->numa_node;
4601
4602 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004603 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004604 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004605 if (!tx_ring->tx_buffer_info)
4606 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004607
4608 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004609 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004610 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004611
Alexander Duyckde88eee2012-02-08 07:49:59 +00004612 set_dev_node(dev, numa_node);
4613 tx_ring->desc = dma_alloc_coherent(dev,
4614 tx_ring->size,
4615 &tx_ring->dma,
4616 GFP_KERNEL);
4617 set_dev_node(dev, orig_node);
4618 if (!tx_ring->desc)
4619 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4620 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004621 if (!tx_ring->desc)
4622 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004623
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004624 tx_ring->next_to_use = 0;
4625 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004626 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004627
4628err:
4629 vfree(tx_ring->tx_buffer_info);
4630 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004631 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004632 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004633}
4634
4635/**
Alexander Duyck69888672008-09-11 20:05:39 -07004636 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4637 * @adapter: board private structure
4638 *
4639 * If this function returns with an error, then it's possible one or
4640 * more of the rings is populated (while the rest are not). It is the
4641 * callers duty to clean those orphaned rings.
4642 *
4643 * Return 0 on success, negative on failure
4644 **/
4645static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4646{
4647 int i, err = 0;
4648
4649 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004650 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004651 if (!err)
4652 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004653
Emil Tantilov396e7992010-07-01 20:05:12 +00004654 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004655 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004656 }
4657
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004658 return 0;
4659err_setup_tx:
4660 /* rewind the index freeing the rings as we go */
4661 while (i--)
4662 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004663 return err;
4664}
4665
4666/**
Auke Kok9a799d72007-09-15 14:07:45 -07004667 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004668 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004669 *
4670 * Returns 0 on success, negative on failure
4671 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004672int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004673{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004674 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004675 int orig_node = dev_to_node(dev);
4676 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004677 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004678
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004679 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004680
4681 if (rx_ring->q_vector)
4682 numa_node = rx_ring->q_vector->numa_node;
4683
4684 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004685 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004686 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004687 if (!rx_ring->rx_buffer_info)
4688 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004689
Auke Kok9a799d72007-09-15 14:07:45 -07004690 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004691 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4692 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004693
Alexander Duyckde88eee2012-02-08 07:49:59 +00004694 set_dev_node(dev, numa_node);
4695 rx_ring->desc = dma_alloc_coherent(dev,
4696 rx_ring->size,
4697 &rx_ring->dma,
4698 GFP_KERNEL);
4699 set_dev_node(dev, orig_node);
4700 if (!rx_ring->desc)
4701 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4702 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004703 if (!rx_ring->desc)
4704 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004705
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004706 rx_ring->next_to_clean = 0;
4707 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004708
4709 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004710err:
4711 vfree(rx_ring->rx_buffer_info);
4712 rx_ring->rx_buffer_info = NULL;
4713 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004714 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004715}
4716
4717/**
Alexander Duyck69888672008-09-11 20:05:39 -07004718 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4719 * @adapter: board private structure
4720 *
4721 * If this function returns with an error, then it's possible one or
4722 * more of the rings is populated (while the rest are not). It is the
4723 * callers duty to clean those orphaned rings.
4724 *
4725 * Return 0 on success, negative on failure
4726 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004727static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4728{
4729 int i, err = 0;
4730
4731 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004732 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004733 if (!err)
4734 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004735
Emil Tantilov396e7992010-07-01 20:05:12 +00004736 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004737 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004738 }
4739
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004740#ifdef IXGBE_FCOE
4741 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4742 if (!err)
4743#endif
4744 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004745err_setup_rx:
4746 /* rewind the index freeing the rings as we go */
4747 while (i--)
4748 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004749 return err;
4750}
4751
4752/**
Auke Kok9a799d72007-09-15 14:07:45 -07004753 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004754 * @tx_ring: Tx descriptor ring for a specific queue
4755 *
4756 * Free all transmit software resources
4757 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004758void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004759{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004760 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004761
4762 vfree(tx_ring->tx_buffer_info);
4763 tx_ring->tx_buffer_info = NULL;
4764
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004765 /* if not set, then don't free */
4766 if (!tx_ring->desc)
4767 return;
4768
4769 dma_free_coherent(tx_ring->dev, tx_ring->size,
4770 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004771
4772 tx_ring->desc = NULL;
4773}
4774
4775/**
4776 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4777 * @adapter: board private structure
4778 *
4779 * Free all transmit software resources
4780 **/
4781static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4782{
4783 int i;
4784
4785 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004786 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004787 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004788}
4789
4790/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004791 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004792 * @rx_ring: ring to clean the resources from
4793 *
4794 * Free all receive software resources
4795 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004796void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004797{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004798 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004799
4800 vfree(rx_ring->rx_buffer_info);
4801 rx_ring->rx_buffer_info = NULL;
4802
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004803 /* if not set, then don't free */
4804 if (!rx_ring->desc)
4805 return;
4806
4807 dma_free_coherent(rx_ring->dev, rx_ring->size,
4808 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004809
4810 rx_ring->desc = NULL;
4811}
4812
4813/**
4814 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4815 * @adapter: board private structure
4816 *
4817 * Free all receive software resources
4818 **/
4819static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4820{
4821 int i;
4822
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004823#ifdef IXGBE_FCOE
4824 ixgbe_free_fcoe_ddp_resources(adapter);
4825
4826#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004827 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004828 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004829 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004830}
4831
4832/**
Auke Kok9a799d72007-09-15 14:07:45 -07004833 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4834 * @netdev: network interface device structure
4835 * @new_mtu: new value for maximum frame size
4836 *
4837 * Returns 0 on success, negative on failure
4838 **/
4839static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4840{
4841 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4842 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4843
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004844 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004845 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4846 return -EINVAL;
4847
4848 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00004849 * For 82599EB we cannot allow legacy VFs to enable their receive
4850 * paths when MTU greater than 1500 is configured. So display a
4851 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00004852 */
4853 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4854 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4855 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Alexander Duyck872844d2012-08-15 02:10:43 +00004856 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004857
Emil Tantilov396e7992010-07-01 20:05:12 +00004858 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004859
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004860 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004861 netdev->mtu = new_mtu;
4862
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004863 if (netif_running(netdev))
4864 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004865
4866 return 0;
4867}
4868
4869/**
4870 * ixgbe_open - Called when a network interface is made active
4871 * @netdev: network interface device structure
4872 *
4873 * Returns 0 on success, negative value on failure
4874 *
4875 * The open entry point is called when a network interface is made
4876 * active by the system (IFF_UP). At this point all resources needed
4877 * for transmit and receive operations are allocated, the interrupt
4878 * handler is registered with the OS, the watchdog timer is started,
4879 * and the stack is notified that the interface is ready.
4880 **/
4881static int ixgbe_open(struct net_device *netdev)
4882{
4883 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4884 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004885
Auke Kok4bebfaa2008-02-11 09:26:01 -08004886 /* disallow open during test */
4887 if (test_bit(__IXGBE_TESTING, &adapter->state))
4888 return -EBUSY;
4889
Jesse Brandeburg54386462009-04-17 20:44:27 +00004890 netif_carrier_off(netdev);
4891
Auke Kok9a799d72007-09-15 14:07:45 -07004892 /* allocate transmit descriptors */
4893 err = ixgbe_setup_all_tx_resources(adapter);
4894 if (err)
4895 goto err_setup_tx;
4896
Auke Kok9a799d72007-09-15 14:07:45 -07004897 /* allocate receive descriptors */
4898 err = ixgbe_setup_all_rx_resources(adapter);
4899 if (err)
4900 goto err_setup_rx;
4901
4902 ixgbe_configure(adapter);
4903
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004904 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004905 if (err)
4906 goto err_req_irq;
4907
Alexander Duyckac802f52012-07-12 05:52:53 +00004908 /* Notify the stack of the actual queue counts. */
4909 err = netif_set_real_num_tx_queues(netdev,
4910 adapter->num_rx_pools > 1 ? 1 :
4911 adapter->num_tx_queues);
4912 if (err)
4913 goto err_set_queues;
4914
4915
4916 err = netif_set_real_num_rx_queues(netdev,
4917 adapter->num_rx_pools > 1 ? 1 :
4918 adapter->num_rx_queues);
4919 if (err)
4920 goto err_set_queues;
4921
Jacob Keller1a71ab22012-08-25 03:54:19 +00004922#ifdef CONFIG_IXGBE_PTP
4923 ixgbe_ptp_init(adapter);
4924#endif /* CONFIG_IXGBE_PTP*/
4925
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004926 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004927
4928 return 0;
4929
Alexander Duyckac802f52012-07-12 05:52:53 +00004930err_set_queues:
4931 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004932err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004933 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004934err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004935 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004936err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07004937 ixgbe_reset(adapter);
4938
4939 return err;
4940}
4941
4942/**
4943 * ixgbe_close - Disables a network interface
4944 * @netdev: network interface device structure
4945 *
4946 * Returns 0, this is not allowed to fail
4947 *
4948 * The close entry point is called when an interface is de-activated
4949 * by the OS. The hardware is still under the drivers control, but
4950 * needs to be disabled. A global MAC reset is issued to stop the
4951 * hardware, and all transmit and receive resources are freed.
4952 **/
4953static int ixgbe_close(struct net_device *netdev)
4954{
4955 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004956
Jacob Keller1a71ab22012-08-25 03:54:19 +00004957#ifdef CONFIG_IXGBE_PTP
4958 ixgbe_ptp_stop(adapter);
4959#endif
4960
Auke Kok9a799d72007-09-15 14:07:45 -07004961 ixgbe_down(adapter);
4962 ixgbe_free_irq(adapter);
4963
Alexander Duycke4911d52011-05-11 07:18:52 +00004964 ixgbe_fdir_filter_exit(adapter);
4965
Auke Kok9a799d72007-09-15 14:07:45 -07004966 ixgbe_free_all_tx_resources(adapter);
4967 ixgbe_free_all_rx_resources(adapter);
4968
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004969 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004970
4971 return 0;
4972}
4973
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004974#ifdef CONFIG_PM
4975static int ixgbe_resume(struct pci_dev *pdev)
4976{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004977 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4978 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004979 u32 err;
4980
4981 pci_set_power_state(pdev, PCI_D0);
4982 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004983 /*
4984 * pci_restore_state clears dev->state_saved so call
4985 * pci_save_state to restore it.
4986 */
4987 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004988
4989 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004990 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004991 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004992 return err;
4993 }
4994 pci_set_master(pdev);
4995
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004996 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004997
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004998 ixgbe_reset(adapter);
4999
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005000 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5001
Alexander Duyckac802f52012-07-12 05:52:53 +00005002 rtnl_lock();
5003 err = ixgbe_init_interrupt_scheme(adapter);
5004 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005005 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005006
5007 rtnl_unlock();
5008
5009 if (err)
5010 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005011
5012 netif_device_attach(netdev);
5013
5014 return 0;
5015}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005016#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005017
5018static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005019{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005020 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5021 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005022 struct ixgbe_hw *hw = &adapter->hw;
5023 u32 ctrl, fctrl;
5024 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005025#ifdef CONFIG_PM
5026 int retval = 0;
5027#endif
5028
5029 netif_device_detach(netdev);
5030
5031 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00005032 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005033 ixgbe_down(adapter);
5034 ixgbe_free_irq(adapter);
5035 ixgbe_free_all_tx_resources(adapter);
5036 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00005037 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005038 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005039
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005040 ixgbe_clear_interrupt_scheme(adapter);
5041
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005042#ifdef CONFIG_PM
5043 retval = pci_save_state(pdev);
5044 if (retval)
5045 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005046
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005047#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005048 if (wufc) {
5049 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005050
Don Skidmorec509e752012-04-05 08:12:05 +00005051 /*
5052 * enable the optics for both mult-speed fiber and
5053 * 82599 SFP+ fiber as we can WoL.
5054 */
5055 if (hw->mac.ops.enable_tx_laser &&
5056 (hw->phy.multispeed_fiber ||
5057 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
5058 hw->mac.type == ixgbe_mac_82599EB)))
5059 hw->mac.ops.enable_tx_laser(hw);
5060
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005061 /* turn on all-multi mode if wake on multicast is enabled */
5062 if (wufc & IXGBE_WUFC_MC) {
5063 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5064 fctrl |= IXGBE_FCTRL_MPE;
5065 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5066 }
5067
5068 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5069 ctrl |= IXGBE_CTRL_GIO_DIS;
5070 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5071
5072 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5073 } else {
5074 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5075 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5076 }
5077
Alexander Duyckbd508172010-11-16 19:27:03 -08005078 switch (hw->mac.type) {
5079 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005080 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005081 break;
5082 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005083 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005084 pci_wake_from_d3(pdev, !!wufc);
5085 break;
5086 default:
5087 break;
5088 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005089
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005090 *enable_wake = !!wufc;
5091
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005092 ixgbe_release_hw_control(adapter);
5093
5094 pci_disable_device(pdev);
5095
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005096 return 0;
5097}
5098
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005099#ifdef CONFIG_PM
5100static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5101{
5102 int retval;
5103 bool wake;
5104
5105 retval = __ixgbe_shutdown(pdev, &wake);
5106 if (retval)
5107 return retval;
5108
5109 if (wake) {
5110 pci_prepare_to_sleep(pdev);
5111 } else {
5112 pci_wake_from_d3(pdev, false);
5113 pci_set_power_state(pdev, PCI_D3hot);
5114 }
5115
5116 return 0;
5117}
5118#endif /* CONFIG_PM */
5119
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005120static void ixgbe_shutdown(struct pci_dev *pdev)
5121{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005122 bool wake;
5123
5124 __ixgbe_shutdown(pdev, &wake);
5125
5126 if (system_state == SYSTEM_POWER_OFF) {
5127 pci_wake_from_d3(pdev, wake);
5128 pci_set_power_state(pdev, PCI_D3hot);
5129 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005130}
5131
5132/**
Auke Kok9a799d72007-09-15 14:07:45 -07005133 * ixgbe_update_stats - Update the board statistics counters.
5134 * @adapter: board private structure
5135 **/
5136void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5137{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005138 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005139 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005140 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005141 u64 total_mpc = 0;
5142 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005143 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5144 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005145 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005146
Don Skidmored08935c2010-06-11 13:20:29 +00005147 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5148 test_bit(__IXGBE_RESETTING, &adapter->state))
5149 return;
5150
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005151 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005152 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005153 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005154 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005155 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5156 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005157 }
5158 adapter->rsc_total_count = rsc_count;
5159 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005160 }
5161
Alexander Duyck5b7da512010-11-16 19:26:50 -08005162 for (i = 0; i < adapter->num_rx_queues; i++) {
5163 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5164 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5165 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5166 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005167 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005168 bytes += rx_ring->stats.bytes;
5169 packets += rx_ring->stats.packets;
5170 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005171 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005172 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5173 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005174 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005175 netdev->stats.rx_bytes = bytes;
5176 netdev->stats.rx_packets = packets;
5177
5178 bytes = 0;
5179 packets = 0;
5180 /* gather some stats to the adapter struct that are per queue */
5181 for (i = 0; i < adapter->num_tx_queues; i++) {
5182 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5183 restart_queue += tx_ring->tx_stats.restart_queue;
5184 tx_busy += tx_ring->tx_stats.tx_busy;
5185 bytes += tx_ring->stats.bytes;
5186 packets += tx_ring->stats.packets;
5187 }
5188 adapter->restart_queue = restart_queue;
5189 adapter->tx_busy = tx_busy;
5190 netdev->stats.tx_bytes = bytes;
5191 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005192
Joe Perches7ca647b2010-09-07 21:35:40 +00005193 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005194
5195 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005196 for (i = 0; i < 8; i++) {
5197 /* for packet buffers not used, the register should read 0 */
5198 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5199 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005200 hwstats->mpc[i] += mpc;
5201 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005202 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5203 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005204 switch (hw->mac.type) {
5205 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005206 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5207 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5208 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005209 hwstats->pxonrxc[i] +=
5210 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005211 break;
5212 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005213 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005214 hwstats->pxonrxc[i] +=
5215 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005216 break;
5217 default:
5218 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005219 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005220 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005221
5222 /*16 register reads */
5223 for (i = 0; i < 16; i++) {
5224 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5225 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5226 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5227 (hw->mac.type == ixgbe_mac_X540)) {
5228 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5229 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5230 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5231 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5232 }
5233 }
5234
Joe Perches7ca647b2010-09-07 21:35:40 +00005235 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005236 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005237 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005238
John Fastabendc84d3242010-11-16 19:27:12 -08005239 ixgbe_update_xoff_received(adapter);
5240
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005241 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005242 switch (hw->mac.type) {
5243 case ixgbe_mac_82598EB:
5244 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005245 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5246 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5247 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5248 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005249 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005250 /* OS2BMC stats are X540 only*/
5251 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5252 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5253 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5254 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5255 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005256 for (i = 0; i < 16; i++)
5257 adapter->hw_rx_no_dma_resources +=
5258 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005259 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005260 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005261 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005262 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005263 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005264 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005265 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005266 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5267 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005268#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005269 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5270 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5271 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5272 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5273 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5274 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005275 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005276 if (adapter->fcoe.ddp_pool) {
5277 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5278 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5279 unsigned int cpu;
5280 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005281 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005282 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5283 noddp += ddp_pool->noddp;
5284 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005285 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005286 hwstats->fcoe_noddp = noddp;
5287 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005288 }
Yi Zou6d455222009-05-13 13:12:16 +00005289#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005290 break;
5291 default:
5292 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005293 }
Auke Kok9a799d72007-09-15 14:07:45 -07005294 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005295 hwstats->bprc += bprc;
5296 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005297 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005298 hwstats->mprc -= bprc;
5299 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5300 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5301 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5302 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5303 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5304 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5305 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5306 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005307 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005308 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005309 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005310 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005311 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5312 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005313 /*
5314 * 82598 errata - tx of flow control packets is included in tx counters
5315 */
5316 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005317 hwstats->gptc -= xon_off_tot;
5318 hwstats->mptc -= xon_off_tot;
5319 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5320 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5321 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5322 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5323 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5324 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5325 hwstats->ptc64 -= xon_off_tot;
5326 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5327 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5328 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5329 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5330 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5331 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005332
5333 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005334 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005335
5336 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005337 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005338 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005339 netdev->stats.rx_length_errors = hwstats->rlec;
5340 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005341 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005342}
5343
5344/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005345 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005346 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005347 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005348static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005349{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005350 struct ixgbe_hw *hw = &adapter->hw;
5351 int i;
5352
Alexander Duyckd034acf2011-04-27 09:25:34 +00005353 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5354 return;
5355
5356 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5357
5358 /* if interface is down do nothing */
5359 if (test_bit(__IXGBE_DOWN, &adapter->state))
5360 return;
5361
5362 /* do nothing if we are not using signature filters */
5363 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5364 return;
5365
5366 adapter->fdir_overflow++;
5367
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005368 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5369 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005370 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005371 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005372 /* re-enable flow director interrupts */
5373 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005374 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005375 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005376 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005377 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005378}
5379
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005380/**
5381 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005382 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005383 *
5384 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005385 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005386 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005387 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005388 */
5389static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5390{
Auke Kok9a799d72007-09-15 14:07:45 -07005391 struct ixgbe_hw *hw = &adapter->hw;
5392 u64 eics = 0;
5393 int i;
5394
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005395 /* If we're down or resetting, just bail */
5396 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5397 test_bit(__IXGBE_RESETTING, &adapter->state))
5398 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005399
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005400 /* Force detection of hung controller */
5401 if (netif_carrier_ok(adapter->netdev)) {
5402 for (i = 0; i < adapter->num_tx_queues; i++)
5403 set_check_for_tx_hang(adapter->tx_ring[i]);
5404 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005405
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005406 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005407 /*
5408 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005409 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005410 * would set *both* EIMS and EICS for any bit in EIAM
5411 */
5412 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5413 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005414 } else {
5415 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005416 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005417 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005418 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005419 eics |= ((u64)1 << i);
5420 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005421 }
5422
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005423 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005424 ixgbe_irq_rearm_queues(adapter, eics);
5425
Alexander Duyckfe49f042009-06-04 16:00:09 +00005426}
5427
5428/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005429 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005430 * @adapter: pointer to the device adapter structure
5431 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005432 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005433static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005434{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005435 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005436 u32 link_speed = adapter->link_speed;
5437 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005438 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005439
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005440 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5441 return;
5442
5443 if (hw->mac.ops.check_link) {
5444 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005445 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005446 /* always assume link is up, if no check link function */
5447 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5448 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005449 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005450
5451 if (adapter->ixgbe_ieee_pfc)
5452 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5453
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005454 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005455 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005456 ixgbe_set_rx_drop_en(adapter);
5457 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005458
5459 if (link_up ||
5460 time_after(jiffies, (adapter->link_check_timeout +
5461 IXGBE_TRY_LINK_TIMEOUT))) {
5462 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5463 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5464 IXGBE_WRITE_FLUSH(hw);
5465 }
5466
5467 adapter->link_up = link_up;
5468 adapter->link_speed = link_speed;
5469}
5470
Alexander Duyck107d3012012-10-02 00:17:03 +00005471static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5472{
5473#ifdef CONFIG_IXGBE_DCB
5474 struct net_device *netdev = adapter->netdev;
5475 struct dcb_app app = {
5476 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5477 .protocol = 0,
5478 };
5479 u8 up = 0;
5480
5481 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5482 up = dcb_ieee_getapp_mask(netdev, &app);
5483
5484 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5485#endif
5486}
5487
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005488/**
5489 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5490 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005491 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005492 **/
5493static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5494{
5495 struct net_device *netdev = adapter->netdev;
5496 struct ixgbe_hw *hw = &adapter->hw;
5497 u32 link_speed = adapter->link_speed;
5498 bool flow_rx, flow_tx;
5499
5500 /* only continue if link was previously down */
5501 if (netif_carrier_ok(netdev))
5502 return;
5503
5504 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5505
5506 switch (hw->mac.type) {
5507 case ixgbe_mac_82598EB: {
5508 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5509 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5510 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5511 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5512 }
5513 break;
5514 case ixgbe_mac_X540:
5515 case ixgbe_mac_82599EB: {
5516 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5517 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5518 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5519 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5520 }
5521 break;
5522 default:
5523 flow_tx = false;
5524 flow_rx = false;
5525 break;
5526 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005527
5528#ifdef CONFIG_IXGBE_PTP
Jacob Keller1a71ab22012-08-25 03:54:19 +00005529 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5530 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005531#endif
5532
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005533 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5534 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5535 "10 Gbps" :
5536 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5537 "1 Gbps" :
5538 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5539 "100 Mbps" :
5540 "unknown speed"))),
5541 ((flow_rx && flow_tx) ? "RX/TX" :
5542 (flow_rx ? "RX" :
5543 (flow_tx ? "TX" : "None"))));
5544
5545 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005546 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005547
Alexander Duyck107d3012012-10-02 00:17:03 +00005548 /* update the default user priority for VFs */
5549 ixgbe_update_default_up(adapter);
5550
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005551 /* ping all the active vfs to let them know link has changed */
5552 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005553}
5554
5555/**
5556 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5557 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005558 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005559 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005560static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005561{
5562 struct net_device *netdev = adapter->netdev;
5563 struct ixgbe_hw *hw = &adapter->hw;
5564
5565 adapter->link_up = false;
5566 adapter->link_speed = 0;
5567
5568 /* only continue if link was up previously */
5569 if (!netif_carrier_ok(netdev))
5570 return;
5571
5572 /* poll for SFP+ cable when link is down */
5573 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5574 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5575
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005576#ifdef CONFIG_IXGBE_PTP
Jacob Keller1a71ab22012-08-25 03:54:19 +00005577 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5578 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005579#endif
5580
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005581 e_info(drv, "NIC Link is Down\n");
5582 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005583
5584 /* ping all the active vfs to let them know link has changed */
5585 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005586}
5587
5588/**
5589 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005590 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005591 **/
5592static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5593{
5594 int i;
5595 int some_tx_pending = 0;
5596
5597 if (!netif_carrier_ok(adapter->netdev)) {
5598 for (i = 0; i < adapter->num_tx_queues; i++) {
5599 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5600 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5601 some_tx_pending = 1;
5602 break;
5603 }
5604 }
5605
5606 if (some_tx_pending) {
5607 /* We've lost link, so the controller stops DMA,
5608 * but we've got queued Tx work that's never going
5609 * to get done, so reset controller to flush Tx.
5610 * (Do the reset outside of interrupt context).
5611 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005612 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005613 }
5614 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005615}
5616
Greg Rosea985b6c32010-11-18 03:02:52 +00005617static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5618{
5619 u32 ssvpc;
5620
Greg Rose0584d992012-08-08 00:00:58 +00005621 /* Do not perform spoof check for 82598 or if not in IOV mode */
5622 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5623 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005624 return;
5625
5626 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5627
5628 /*
5629 * ssvpc register is cleared on read, if zero then no
5630 * spoofed packets in the last interval.
5631 */
5632 if (!ssvpc)
5633 return;
5634
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005635 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005636}
5637
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005638/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005639 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005640 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005641 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005642static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005643{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005644 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005645 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5646 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005647 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005648
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005649 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005650
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005651 if (adapter->link_up)
5652 ixgbe_watchdog_link_is_up(adapter);
5653 else
5654 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005655
Greg Rosea985b6c32010-11-18 03:02:52 +00005656 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005657 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005658
5659 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005660}
5661
Alexander Duyck70864002011-04-27 09:13:56 +00005662/**
5663 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005664 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005665 **/
5666static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5667{
5668 struct ixgbe_hw *hw = &adapter->hw;
5669 s32 err;
5670
5671 /* not searching for SFP so there is nothing to do here */
5672 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5673 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5674 return;
5675
5676 /* someone else is in init, wait until next service event */
5677 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5678 return;
5679
5680 err = hw->phy.ops.identify_sfp(hw);
5681 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5682 goto sfp_out;
5683
5684 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5685 /* If no cable is present, then we need to reset
5686 * the next time we find a good cable. */
5687 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5688 }
5689
5690 /* exit on error */
5691 if (err)
5692 goto sfp_out;
5693
5694 /* exit if reset not needed */
5695 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5696 goto sfp_out;
5697
5698 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5699
5700 /*
5701 * A module may be identified correctly, but the EEPROM may not have
5702 * support for that module. setup_sfp() will fail in that case, so
5703 * we should not allow that module to load.
5704 */
5705 if (hw->mac.type == ixgbe_mac_82598EB)
5706 err = hw->phy.ops.reset(hw);
5707 else
5708 err = hw->mac.ops.setup_sfp(hw);
5709
5710 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5711 goto sfp_out;
5712
5713 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5714 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5715
5716sfp_out:
5717 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5718
5719 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5720 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5721 e_dev_err("failed to initialize because an unsupported "
5722 "SFP+ module type was detected.\n");
5723 e_dev_err("Reload the driver after installing a "
5724 "supported module.\n");
5725 unregister_netdev(adapter->netdev);
5726 }
5727}
5728
5729/**
5730 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005731 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005732 **/
5733static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5734{
5735 struct ixgbe_hw *hw = &adapter->hw;
5736 u32 autoneg;
5737 bool negotiation;
5738
5739 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5740 return;
5741
5742 /* someone else is in init, wait until next service event */
5743 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5744 return;
5745
5746 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5747
5748 autoneg = hw->phy.autoneg_advertised;
5749 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5750 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005751 if (hw->mac.ops.setup_link)
5752 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5753
5754 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5755 adapter->link_check_timeout = jiffies;
5756 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5757}
5758
Greg Rose83c61fa2011-09-07 05:59:35 +00005759#ifdef CONFIG_PCI_IOV
5760static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5761{
5762 int vf;
5763 struct ixgbe_hw *hw = &adapter->hw;
5764 struct net_device *netdev = adapter->netdev;
5765 u32 gpc;
5766 u32 ciaa, ciad;
5767
5768 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5769 if (gpc) /* If incrementing then no need for the check below */
5770 return;
5771 /*
5772 * Check to see if a bad DMA write target from an errant or
5773 * malicious VF has caused a PCIe error. If so then we can
5774 * issue a VFLR to the offending VF(s) and then resume without
5775 * requesting a full slot reset.
5776 */
5777
5778 for (vf = 0; vf < adapter->num_vfs; vf++) {
5779 ciaa = (vf << 16) | 0x80000000;
5780 /* 32 bit read so align, we really want status at offset 6 */
5781 ciaa |= PCI_COMMAND;
5782 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5783 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5784 ciaa &= 0x7FFFFFFF;
5785 /* disable debug mode asap after reading data */
5786 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5787 /* Get the upper 16 bits which will be the PCI status reg */
5788 ciad >>= 16;
5789 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5790 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5791 /* Issue VFLR */
5792 ciaa = (vf << 16) | 0x80000000;
5793 ciaa |= 0xA8;
5794 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5795 ciad = 0x00008000; /* VFLR */
5796 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5797 ciaa &= 0x7FFFFFFF;
5798 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5799 }
5800 }
5801}
5802
5803#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005804/**
5805 * ixgbe_service_timer - Timer Call-back
5806 * @data: pointer to adapter cast into an unsigned long
5807 **/
5808static void ixgbe_service_timer(unsigned long data)
5809{
5810 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5811 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005812 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005813
5814 /* poll faster when waiting for link */
5815 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5816 next_event_offset = HZ / 10;
5817 else
5818 next_event_offset = HZ * 2;
5819
Greg Rose83c61fa2011-09-07 05:59:35 +00005820#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005821 /*
5822 * don't bother with SR-IOV VF DMA hang check if there are
5823 * no VFs or the link is down
5824 */
5825 if (!adapter->num_vfs ||
5826 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5827 goto normal_timer_service;
5828
5829 /* If we have VFs allocated then we must check for DMA hangs */
5830 ixgbe_check_for_bad_vf(adapter);
5831 next_event_offset = HZ / 50;
5832 adapter->timer_event_accumulator++;
5833
5834 if (adapter->timer_event_accumulator >= 100)
5835 adapter->timer_event_accumulator = 0;
5836 else
5837 ready = false;
5838
5839normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005840#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005841 /* Reset the timer */
5842 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5843
Greg Rose83c61fa2011-09-07 05:59:35 +00005844 if (ready)
5845 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005846}
5847
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005848static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5849{
5850 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5851 return;
5852
5853 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5854
5855 /* If we're already down or resetting, just bail */
5856 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5857 test_bit(__IXGBE_RESETTING, &adapter->state))
5858 return;
5859
5860 ixgbe_dump(adapter);
5861 netdev_err(adapter->netdev, "Reset adapter\n");
5862 adapter->tx_timeout_count++;
5863
5864 ixgbe_reinit_locked(adapter);
5865}
5866
Alexander Duyck70864002011-04-27 09:13:56 +00005867/**
5868 * ixgbe_service_task - manages and runs subtasks
5869 * @work: pointer to work_struct containing our data
5870 **/
5871static void ixgbe_service_task(struct work_struct *work)
5872{
5873 struct ixgbe_adapter *adapter = container_of(work,
5874 struct ixgbe_adapter,
5875 service_task);
5876
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005877 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005878 ixgbe_sfp_detection_subtask(adapter);
5879 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005880 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005881 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005882 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005883 ixgbe_check_hang_subtask(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005884#ifdef CONFIG_IXGBE_PTP
5885 ixgbe_ptp_overflow_check(adapter);
5886#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005887
5888 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005889}
5890
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005891static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5892 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005893 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005894{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005895 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005896 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005897 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005898
Alexander Duyck897ab152011-05-27 05:31:47 +00005899 if (!skb_is_gso(skb))
5900 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005901
Alexander Duyck897ab152011-05-27 05:31:47 +00005902 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005903 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005904 if (err)
5905 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005906 }
5907
Alexander Duyck897ab152011-05-27 05:31:47 +00005908 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5909 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5910
Alexander Duyck244e27a2012-02-08 07:51:11 +00005911 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005912 struct iphdr *iph = ip_hdr(skb);
5913 iph->tot_len = 0;
5914 iph->check = 0;
5915 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5916 iph->daddr, 0,
5917 IPPROTO_TCP,
5918 0);
5919 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005920 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5921 IXGBE_TX_FLAGS_CSUM |
5922 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005923 } else if (skb_is_gso_v6(skb)) {
5924 ipv6_hdr(skb)->payload_len = 0;
5925 tcp_hdr(skb)->check =
5926 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5927 &ipv6_hdr(skb)->daddr,
5928 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005929 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5930 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005931 }
5932
Alexander Duyck091a6242012-02-08 07:51:01 +00005933 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005934 l4len = tcp_hdrlen(skb);
5935 *hdr_len = skb_transport_offset(skb) + l4len;
5936
Alexander Duyck091a6242012-02-08 07:51:01 +00005937 /* update gso size and bytecount with header size */
5938 first->gso_segs = skb_shinfo(skb)->gso_segs;
5939 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5940
Alexander Duyck897ab152011-05-27 05:31:47 +00005941 /* mss_l4len_id: use 1 as index for TSO */
5942 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5943 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5944 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5945
5946 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5947 vlan_macip_lens = skb_network_header_len(skb);
5948 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005949 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005950
5951 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005952 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005953
5954 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005955}
5956
Alexander Duyck244e27a2012-02-08 07:51:11 +00005957static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5958 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005959{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005960 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005961 u32 vlan_macip_lens = 0;
5962 u32 mss_l4len_idx = 0;
5963 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005964
Alexander Duyck897ab152011-05-27 05:31:47 +00005965 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck62748b72012-07-20 08:09:01 +00005966 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) {
5967 if (unlikely(skb->no_fcs))
5968 first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS;
5969 if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5970 return;
5971 }
Alexander Duyck897ab152011-05-27 05:31:47 +00005972 } else {
5973 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005974 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005975 case __constant_htons(ETH_P_IP):
5976 vlan_macip_lens |= skb_network_header_len(skb);
5977 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5978 l4_hdr = ip_hdr(skb)->protocol;
5979 break;
5980 case __constant_htons(ETH_P_IPV6):
5981 vlan_macip_lens |= skb_network_header_len(skb);
5982 l4_hdr = ipv6_hdr(skb)->nexthdr;
5983 break;
5984 default:
5985 if (unlikely(net_ratelimit())) {
5986 dev_warn(tx_ring->dev,
5987 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005988 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005989 }
5990 break;
5991 }
Auke Kok9a799d72007-09-15 14:07:45 -07005992
Alexander Duyck897ab152011-05-27 05:31:47 +00005993 switch (l4_hdr) {
5994 case IPPROTO_TCP:
5995 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5996 mss_l4len_idx = tcp_hdrlen(skb) <<
5997 IXGBE_ADVTXD_L4LEN_SHIFT;
5998 break;
5999 case IPPROTO_SCTP:
6000 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6001 mss_l4len_idx = sizeof(struct sctphdr) <<
6002 IXGBE_ADVTXD_L4LEN_SHIFT;
6003 break;
6004 case IPPROTO_UDP:
6005 mss_l4len_idx = sizeof(struct udphdr) <<
6006 IXGBE_ADVTXD_L4LEN_SHIFT;
6007 break;
6008 default:
6009 if (unlikely(net_ratelimit())) {
6010 dev_warn(tx_ring->dev,
6011 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006012 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006013 }
6014 break;
6015 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006016
6017 /* update TX checksum flag */
6018 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006019 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006020
Alexander Duyck244e27a2012-02-08 07:51:11 +00006021 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006022 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006023 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006024
6025 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6026 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006027}
6028
Alexander Duyckd3d00232011-07-15 02:31:25 +00006029static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6030{
6031 /* set type for advanced descriptor with frame checksum insertion */
6032 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
Alexander Duyckd3d00232011-07-15 02:31:25 +00006033 IXGBE_ADVTXD_DCMD_DEXT);
6034
6035 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006036 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006037 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6038
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006039#ifdef CONFIG_IXGBE_PTP
6040 if (tx_flags & IXGBE_TX_FLAGS_TSTAMP)
6041 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP);
6042#endif
6043
Alexander Duyckd3d00232011-07-15 02:31:25 +00006044 /* set segmentation enable bits for TSO/FSO */
6045#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006046 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006047#else
6048 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6049#endif
6050 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6051
Alexander Duyck62748b72012-07-20 08:09:01 +00006052 /* insert frame checksum */
6053 if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS))
6054 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS);
6055
Alexander Duyckd3d00232011-07-15 02:31:25 +00006056 return cmd_type;
6057}
6058
Alexander Duyck729739b2012-02-08 07:51:06 +00006059static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6060 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006061{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006062 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006063
6064 /* enable L4 checksum for TSO and TX checksum offload */
6065 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6066 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6067
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006068 /* enble IPv4 checksum for TSO */
6069 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6070 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006071
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006072 /* use index 1 context for TSO/FSO/FCOE */
6073#ifdef IXGBE_FCOE
6074 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6075#else
6076 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006077#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006078 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6079
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006080 /*
6081 * Check Context must be set if Tx switch is enabled, which it
6082 * always is for case where virtual functions are running
6083 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006084#ifdef IXGBE_FCOE
6085 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6086#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006087 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006088#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006089 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6090
Alexander Duyck729739b2012-02-08 07:51:06 +00006091 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006092}
6093
6094#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6095 IXGBE_TXD_CMD_RS)
6096
6097static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006098 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006099 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006100{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006101 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00006102 struct sk_buff *skb = first->skb;
6103 struct ixgbe_tx_buffer *tx_buffer;
6104 union ixgbe_adv_tx_desc *tx_desc;
6105 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006106 unsigned int data_len = skb->data_len;
6107 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00006108 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006109 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00006110 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006111 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006112
Alexander Duyck729739b2012-02-08 07:51:06 +00006113 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6114
6115 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6116 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6117
Alexander Duyckd3d00232011-07-15 02:31:25 +00006118#ifdef IXGBE_FCOE
6119 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006120 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006121 size -= sizeof(struct fcoe_crc_eof) - data_len;
6122 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006123 } else {
6124 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006125 }
Auke Kok9a799d72007-09-15 14:07:45 -07006126 }
6127
Alexander Duyckd3d00232011-07-15 02:31:25 +00006128#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006129 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6130 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006131 goto dma_error;
6132
Alexander Duyck729739b2012-02-08 07:51:06 +00006133 /* record length, and DMA address */
6134 dma_unmap_len_set(first, len, size);
6135 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006136
Alexander Duyck729739b2012-02-08 07:51:06 +00006137 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006138
6139 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006140 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006141 tx_desc->read.cmd_type_len =
6142 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006143
Alexander Duyckd3d00232011-07-15 02:31:25 +00006144 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006145 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006146 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006147 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006148 i = 0;
6149 }
Alexander Duyck729739b2012-02-08 07:51:06 +00006150
6151 dma += IXGBE_MAX_DATA_PER_TXD;
6152 size -= IXGBE_MAX_DATA_PER_TXD;
6153
6154 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6155 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006156 }
6157
Alexander Duyck729739b2012-02-08 07:51:06 +00006158 if (likely(!data_len))
6159 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006160
Alexander Duyckd3d00232011-07-15 02:31:25 +00006161 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006162
Alexander Duyck729739b2012-02-08 07:51:06 +00006163 i++;
6164 tx_desc++;
6165 if (i == tx_ring->count) {
6166 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6167 i = 0;
6168 }
Auke Kok9a799d72007-09-15 14:07:45 -07006169
Alexander Duyckd3d00232011-07-15 02:31:25 +00006170#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006171 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006172#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006173 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006174#endif
6175 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006176
Alexander Duyck729739b2012-02-08 07:51:06 +00006177 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6178 DMA_TO_DEVICE);
6179 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006180 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006181
Alexander Duyck729739b2012-02-08 07:51:06 +00006182 tx_buffer = &tx_ring->tx_buffer_info[i];
6183 dma_unmap_len_set(tx_buffer, len, size);
6184 dma_unmap_addr_set(tx_buffer, dma, dma);
6185
6186 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6187 tx_desc->read.olinfo_status = 0;
6188
6189 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07006190 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006191
Alexander Duyck729739b2012-02-08 07:51:06 +00006192 /* write last descriptor with RS and EOP bits */
6193 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6194 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006195
Alexander Duyck091a6242012-02-08 07:51:01 +00006196 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006197
Alexander Duyckd3d00232011-07-15 02:31:25 +00006198 /* set the timestamp */
6199 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006200
6201 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006202 * Force memory writes to complete before letting h/w know there
6203 * are new descriptors to fetch. (Only applicable for weak-ordered
6204 * memory model archs, such as IA-64).
6205 *
6206 * We also need this memory barrier to make certain all of the
6207 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006208 */
6209 wmb();
6210
Alexander Duyckd3d00232011-07-15 02:31:25 +00006211 /* set next_to_watch value indicating a packet is present */
6212 first->next_to_watch = tx_desc;
6213
Alexander Duyck729739b2012-02-08 07:51:06 +00006214 i++;
6215 if (i == tx_ring->count)
6216 i = 0;
6217
6218 tx_ring->next_to_use = i;
6219
Alexander Duyckd3d00232011-07-15 02:31:25 +00006220 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006221 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006222
6223 return;
6224dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006225 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006226
6227 /* clear dma mappings for failed tx_buffer_info map */
6228 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006229 tx_buffer = &tx_ring->tx_buffer_info[i];
6230 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6231 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006232 break;
6233 if (i == 0)
6234 i = tx_ring->count;
6235 i--;
6236 }
6237
Alexander Duyckd3d00232011-07-15 02:31:25 +00006238 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006239}
6240
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006241static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006242 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006243{
Alexander Duyck69830522011-01-06 14:29:58 +00006244 struct ixgbe_q_vector *q_vector = ring->q_vector;
6245 union ixgbe_atr_hash_dword input = { .dword = 0 };
6246 union ixgbe_atr_hash_dword common = { .dword = 0 };
6247 union {
6248 unsigned char *network;
6249 struct iphdr *ipv4;
6250 struct ipv6hdr *ipv6;
6251 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006252 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006253 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006254
Alexander Duyck69830522011-01-06 14:29:58 +00006255 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6256 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006257 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006258
Alexander Duyck69830522011-01-06 14:29:58 +00006259 /* do nothing if sampling is disabled */
6260 if (!ring->atr_sample_rate)
6261 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006262
Alexander Duyck69830522011-01-06 14:29:58 +00006263 ring->atr_count++;
6264
6265 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006266 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006267
6268 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006269 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006270 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006271 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006272 hdr.ipv4->protocol != IPPROTO_TCP))
6273 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006274
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006275 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006276
Alexander Duyck66f32a82011-06-29 05:43:22 +00006277 /* skip this packet since it is invalid or the socket is closing */
6278 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006279 return;
6280
6281 /* sample on all syn packets or once every atr sample count */
6282 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6283 return;
6284
6285 /* reset sample count */
6286 ring->atr_count = 0;
6287
Alexander Duyck244e27a2012-02-08 07:51:11 +00006288 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006289
6290 /*
6291 * src and dst are inverted, think how the receiver sees them
6292 *
6293 * The input is broken into two sections, a non-compressed section
6294 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6295 * is XORed together and stored in the compressed dword.
6296 */
6297 input.formatted.vlan_id = vlan_id;
6298
6299 /*
6300 * since src port and flex bytes occupy the same word XOR them together
6301 * and write the value to source port portion of compressed dword
6302 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006303 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006304 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6305 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006306 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006307 common.port.dst ^= th->source;
6308
Alexander Duyck244e27a2012-02-08 07:51:11 +00006309 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006310 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6311 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6312 } else {
6313 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6314 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6315 hdr.ipv6->saddr.s6_addr32[1] ^
6316 hdr.ipv6->saddr.s6_addr32[2] ^
6317 hdr.ipv6->saddr.s6_addr32[3] ^
6318 hdr.ipv6->daddr.s6_addr32[0] ^
6319 hdr.ipv6->daddr.s6_addr32[1] ^
6320 hdr.ipv6->daddr.s6_addr32[2] ^
6321 hdr.ipv6->daddr.s6_addr32[3];
6322 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006323
6324 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006325 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6326 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006327}
6328
Alexander Duyck63544e92011-05-27 05:31:42 +00006329static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006330{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006331 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006332 /* Herbert's original patch had:
6333 * smp_mb__after_netif_stop_queue();
6334 * but since that doesn't exist yet, just open code it. */
6335 smp_mb();
6336
6337 /* We need to check again in a case another CPU has just
6338 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006339 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006340 return -EBUSY;
6341
6342 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006343 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006344 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006345 return 0;
6346}
6347
Alexander Duyck82d4e462011-06-11 01:44:58 +00006348static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006349{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006350 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006351 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006352 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006353}
6354
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006355static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6356{
6357 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006358 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6359 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006360#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006361 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006362
John Fastabende5b64632011-03-08 03:44:52 +00006363 if (((protocol == htons(ETH_P_FCOE)) ||
6364 (protocol == htons(ETH_P_FIP))) &&
6365 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckc0876632012-05-10 00:01:46 +00006366 struct ixgbe_ring_feature *f;
6367
6368 f = &adapter->ring_feature[RING_F_FCOE];
6369
6370 while (txq >= f->indices)
6371 txq -= f->indices;
Alexander Duycke4b317e2012-05-05 05:30:53 +00006372 txq += adapter->ring_feature[RING_F_FCOE].offset;
Alexander Duyckc0876632012-05-10 00:01:46 +00006373
John Fastabende5b64632011-03-08 03:44:52 +00006374 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006375 }
6376#endif
6377
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006378 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6379 while (unlikely(txq >= dev->real_num_tx_queues))
6380 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006381 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006382 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006383
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006384 return skb_tx_hash(dev, skb);
6385}
6386
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006387netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006388 struct ixgbe_adapter *adapter,
6389 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006390{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006391 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006392 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006393 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006394#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6395 unsigned short f;
6396#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006397 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006398 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006399 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006400
Alexander Duycka535c302011-05-27 05:31:52 +00006401 /*
6402 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006403 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006404 * + 2 desc gap to keep tail from touching head,
6405 * + 1 desc for context descriptor,
6406 * otherwise try next time
6407 */
6408#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6409 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6410 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6411#else
6412 count += skb_shinfo(skb)->nr_frags;
6413#endif
6414 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6415 tx_ring->tx_stats.tx_busy++;
6416 return NETDEV_TX_BUSY;
6417 }
6418
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006419 /* record the location of the first descriptor for this packet */
6420 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6421 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006422 first->bytecount = skb->len;
6423 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006424
Alexander Duyck66f32a82011-06-29 05:43:22 +00006425 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006426 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006427 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6428 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6429 /* else if it is a SW VLAN check the next protocol and store the tag */
6430 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6431 struct vlan_hdr *vhdr, _vhdr;
6432 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6433 if (!vhdr)
6434 goto out_drop;
6435
6436 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006437 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6438 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006439 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006440 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006441
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006442 skb_tx_timestamp(skb);
6443
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006444#ifdef CONFIG_IXGBE_PTP
6445 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6446 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6447 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
6448 }
6449#endif
6450
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006451#ifdef CONFIG_PCI_IOV
6452 /*
6453 * Use the l2switch_enable flag - would be false if the DMA
6454 * Tx switch had been disabled.
6455 */
6456 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6457 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6458
6459#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006460 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006461 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006462 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6463 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006464 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006465 tx_flags |= (skb->priority & 0x7) <<
6466 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006467 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6468 struct vlan_ethhdr *vhdr;
6469 if (skb_header_cloned(skb) &&
6470 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6471 goto out_drop;
6472 vhdr = (struct vlan_ethhdr *)skb->data;
6473 vhdr->h_vlan_TCI = htons(tx_flags >>
6474 IXGBE_TX_FLAGS_VLAN_SHIFT);
6475 } else {
6476 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6477 }
6478 }
Alexander Duycka535c302011-05-27 05:31:52 +00006479
Alexander Duyck244e27a2012-02-08 07:51:11 +00006480 /* record initial flags and protocol */
6481 first->tx_flags = tx_flags;
6482 first->protocol = protocol;
6483
Yi Zoueacd73f2009-05-13 13:11:06 +00006484#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006485 /* setup tx offload for FCoE */
6486 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006487 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006488 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006489 if (tso < 0)
6490 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006491
Alexander Duyck66f32a82011-06-29 05:43:22 +00006492 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006493 }
Auke Kok9a799d72007-09-15 14:07:45 -07006494
Auke Kok9a799d72007-09-15 14:07:45 -07006495#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006496 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006497 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006498 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006499 else if (!tso)
6500 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006501
6502 /* add the ATR filter if ATR is on */
6503 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006504 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006505
6506#ifdef IXGBE_FCOE
6507xmit_fcoe:
6508#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006509 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006510
6511 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006512
6513 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006514
6515out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006516 dev_kfree_skb_any(first->skb);
6517 first->skb = NULL;
6518
Alexander Duyck897ab152011-05-27 05:31:47 +00006519 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006520}
6521
Alexander Duycka50c29d2012-02-08 07:50:40 +00006522static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6523 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006524{
6525 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006526 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006527
Alexander Duycka50c29d2012-02-08 07:50:40 +00006528 /*
6529 * The minimum packet size for olinfo paylen is 17 so pad the skb
6530 * in order to meet this minimum size requirement.
6531 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006532 if (unlikely(skb->len < 17)) {
6533 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006534 return NETDEV_TX_OK;
6535 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006536 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006537 }
6538
Auke Kok9a799d72007-09-15 14:07:45 -07006539 tx_ring = adapter->tx_ring[skb->queue_mapping];
6540 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6541}
6542
6543/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006544 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006545 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006546 * @p: pointer to an address structure
6547 *
Auke Kok9a799d72007-09-15 14:07:45 -07006548 * Returns 0 on success, negative on failure
6549 **/
6550static int ixgbe_set_mac(struct net_device *netdev, void *p)
6551{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006552 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6553 struct ixgbe_hw *hw = &adapter->hw;
6554 struct sockaddr *addr = p;
6555
6556 if (!is_valid_ether_addr(addr->sa_data))
6557 return -EADDRNOTAVAIL;
6558
6559 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6560 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6561
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006562 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006563
6564 return 0;
6565}
6566
Ben Hutchings6b73e102009-04-29 08:08:58 +00006567static int
6568ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6569{
6570 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6571 struct ixgbe_hw *hw = &adapter->hw;
6572 u16 value;
6573 int rc;
6574
6575 if (prtad != hw->phy.mdio.prtad)
6576 return -EINVAL;
6577 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6578 if (!rc)
6579 rc = value;
6580 return rc;
6581}
6582
6583static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6584 u16 addr, u16 value)
6585{
6586 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6587 struct ixgbe_hw *hw = &adapter->hw;
6588
6589 if (prtad != hw->phy.mdio.prtad)
6590 return -EINVAL;
6591 return hw->phy.ops.write_reg(hw, addr, devad, value);
6592}
6593
6594static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6595{
6596 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6597
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006598 switch (cmd) {
6599#ifdef CONFIG_IXGBE_PTP
6600 case SIOCSHWTSTAMP:
6601 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
6602#endif
6603 default:
6604 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6605 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006606}
6607
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006608/**
6609 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006610 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006611 * @netdev: network interface device structure
6612 *
6613 * Returns non-zero on failure
6614 **/
6615static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6616{
6617 int err = 0;
6618 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006619 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006620
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006621 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006622 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006623 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006624 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006625
6626 /* update SAN MAC vmdq pool selection */
6627 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006628 }
6629 return err;
6630}
6631
6632/**
6633 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006634 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006635 * @netdev: network interface device structure
6636 *
6637 * Returns non-zero on failure
6638 **/
6639static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6640{
6641 int err = 0;
6642 struct ixgbe_adapter *adapter = netdev_priv(dev);
6643 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6644
6645 if (is_valid_ether_addr(mac->san_addr)) {
6646 rtnl_lock();
6647 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6648 rtnl_unlock();
6649 }
6650 return err;
6651}
6652
Auke Kok9a799d72007-09-15 14:07:45 -07006653#ifdef CONFIG_NET_POLL_CONTROLLER
6654/*
6655 * Polling 'interrupt' - used by things like netconsole to send skbs
6656 * without having to re-enable interrupts. It's not called while
6657 * the interrupt routine is executing.
6658 */
6659static void ixgbe_netpoll(struct net_device *netdev)
6660{
6661 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006662 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006663
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006664 /* if interface is down do nothing */
6665 if (test_bit(__IXGBE_DOWN, &adapter->state))
6666 return;
6667
Auke Kok9a799d72007-09-15 14:07:45 -07006668 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006669 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006670 for (i = 0; i < adapter->num_q_vectors; i++)
6671 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006672 } else {
6673 ixgbe_intr(adapter->pdev->irq, netdev);
6674 }
Auke Kok9a799d72007-09-15 14:07:45 -07006675 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006676}
Auke Kok9a799d72007-09-15 14:07:45 -07006677
Alexander Duyck581330b2012-02-08 07:51:47 +00006678#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006679static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6680 struct rtnl_link_stats64 *stats)
6681{
6682 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6683 int i;
6684
Eric Dumazet1a515022010-11-16 19:26:42 -08006685 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006686 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006687 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006688 u64 bytes, packets;
6689 unsigned int start;
6690
Eric Dumazet1a515022010-11-16 19:26:42 -08006691 if (ring) {
6692 do {
6693 start = u64_stats_fetch_begin_bh(&ring->syncp);
6694 packets = ring->stats.packets;
6695 bytes = ring->stats.bytes;
6696 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6697 stats->rx_packets += packets;
6698 stats->rx_bytes += bytes;
6699 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006700 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006701
6702 for (i = 0; i < adapter->num_tx_queues; i++) {
6703 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6704 u64 bytes, packets;
6705 unsigned int start;
6706
6707 if (ring) {
6708 do {
6709 start = u64_stats_fetch_begin_bh(&ring->syncp);
6710 packets = ring->stats.packets;
6711 bytes = ring->stats.bytes;
6712 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6713 stats->tx_packets += packets;
6714 stats->tx_bytes += bytes;
6715 }
6716 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006717 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006718 /* following stats updated by ixgbe_watchdog_task() */
6719 stats->multicast = netdev->stats.multicast;
6720 stats->rx_errors = netdev->stats.rx_errors;
6721 stats->rx_length_errors = netdev->stats.rx_length_errors;
6722 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6723 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6724 return stats;
6725}
6726
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006727#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006728/**
6729 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6730 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006731 * @tc: number of traffic classes currently enabled
6732 *
6733 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6734 * 802.1Q priority maps to a packet buffer that exists.
6735 */
6736static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6737{
6738 struct ixgbe_hw *hw = &adapter->hw;
6739 u32 reg, rsave;
6740 int i;
6741
6742 /* 82598 have a static priority to TC mapping that can not
6743 * be changed so no validation is needed.
6744 */
6745 if (hw->mac.type == ixgbe_mac_82598EB)
6746 return;
6747
6748 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6749 rsave = reg;
6750
6751 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6752 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6753
6754 /* If up2tc is out of bounds default to zero */
6755 if (up2tc > tc)
6756 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6757 }
6758
6759 if (reg != rsave)
6760 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6761
6762 return;
6763}
6764
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006765/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006766 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6767 * @adapter: Pointer to adapter struct
6768 *
6769 * Populate the netdev user priority to tc map
6770 */
6771static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6772{
6773 struct net_device *dev = adapter->netdev;
6774 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6775 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6776 u8 prio;
6777
6778 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6779 u8 tc = 0;
6780
6781 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6782 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6783 else if (ets)
6784 tc = ets->prio_tc[prio];
6785
6786 netdev_set_prio_tc_map(dev, prio, tc);
6787 }
6788}
6789
6790/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006791 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006792 *
6793 * @netdev: net device to configure
6794 * @tc: number of traffic classes to enable
6795 */
6796int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6797{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006798 struct ixgbe_adapter *adapter = netdev_priv(dev);
6799 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006800
John Fastabend8b1c0b22011-05-03 02:26:48 +00006801 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006802 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006803 (hw->mac.type == ixgbe_mac_82598EB &&
6804 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006805 return -EINVAL;
6806
6807 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006808 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006809 * hardware is not flexible enough to do this dynamically.
6810 */
6811 if (netif_running(dev))
6812 ixgbe_close(dev);
6813 ixgbe_clear_interrupt_scheme(adapter);
6814
John Fastabende7589ea2011-07-18 22:38:36 +00006815 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006816 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006817 ixgbe_set_prio_tc_map(adapter);
6818
John Fastabende7589ea2011-07-18 22:38:36 +00006819 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006820
Alexander Duyck943561d2012-05-09 22:14:44 -07006821 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6822 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006823 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006824 }
John Fastabende7589ea2011-07-18 22:38:36 +00006825 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006826 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006827
Alexander Duyck943561d2012-05-09 22:14:44 -07006828 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6829 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006830
6831 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006832
6833 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6834 adapter->dcb_cfg.pfc_mode_enable = false;
6835 }
6836
John Fastabend8b1c0b22011-05-03 02:26:48 +00006837 ixgbe_init_interrupt_scheme(adapter);
6838 ixgbe_validate_rtr(adapter, tc);
6839 if (netif_running(dev))
6840 ixgbe_open(dev);
6841
6842 return 0;
6843}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006844
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006845#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006846void ixgbe_do_reset(struct net_device *netdev)
6847{
6848 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6849
6850 if (netif_running(netdev))
6851 ixgbe_reinit_locked(adapter);
6852 else
6853 ixgbe_reset(adapter);
6854}
6855
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006856static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006857 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006858{
6859 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6860
Don Skidmore082757a2011-07-21 05:55:00 +00006861 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006862 if (!(features & NETIF_F_RXCSUM))
6863 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006864
Alexander Duyck567d2de2012-02-11 07:18:57 +00006865 /* Turn off LRO if not RSC capable */
6866 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6867 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006868
Alexander Duyck567d2de2012-02-11 07:18:57 +00006869 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006870}
6871
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006872static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006873 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006874{
6875 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006876 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006877 bool need_reset = false;
6878
Don Skidmore082757a2011-07-21 05:55:00 +00006879 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006880 if (!(features & NETIF_F_LRO)) {
6881 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006882 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006883 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6884 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6885 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6886 if (adapter->rx_itr_setting == 1 ||
6887 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6888 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6889 need_reset = true;
6890 } else if ((changed ^ features) & NETIF_F_LRO) {
6891 e_info(probe, "rx-usecs set too low, "
6892 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006893 }
6894 }
6895
6896 /*
6897 * Check if Flow Director n-tuple support was enabled or disabled. If
6898 * the state changed, we need to reset.
6899 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006900 switch (features & NETIF_F_NTUPLE) {
6901 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00006902 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006903 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6904 need_reset = true;
6905
Alexander Duyck567d2de2012-02-11 07:18:57 +00006906 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6907 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00006908 break;
6909 default:
6910 /* turn off perfect filters, enable ATR and reset */
6911 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6912 need_reset = true;
6913
6914 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6915
6916 /* We cannot enable ATR if SR-IOV is enabled */
6917 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6918 break;
6919
6920 /* We cannot enable ATR if we have 2 or more traffic classes */
6921 if (netdev_get_num_tc(netdev) > 1)
6922 break;
6923
6924 /* We cannot enable ATR if RSS is disabled */
6925 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6926 break;
6927
6928 /* A sample rate of 0 indicates ATR disabled */
6929 if (!adapter->atr_sample_rate)
6930 break;
6931
6932 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6933 break;
Don Skidmore082757a2011-07-21 05:55:00 +00006934 }
6935
John Fastabend146d4cc2012-05-15 05:59:26 +00006936 if (features & NETIF_F_HW_VLAN_RX)
6937 ixgbe_vlan_strip_enable(adapter);
6938 else
6939 ixgbe_vlan_strip_disable(adapter);
6940
Ben Greear3f2d1c02012-03-08 08:28:41 +00006941 if (changed & NETIF_F_RXALL)
6942 need_reset = true;
6943
Alexander Duyck567d2de2012-02-11 07:18:57 +00006944 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006945 if (need_reset)
6946 ixgbe_do_reset(netdev);
6947
6948 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006949}
6950
stephen hemmingeredc7d572012-10-01 12:32:33 +00006951static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006952 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006953 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006954 u16 flags)
6955{
6956 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00006957 int err;
6958
6959 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6960 return -EOPNOTSUPP;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006961
6962 if (ndm->ndm_state & NUD_PERMANENT) {
6963 pr_info("%s: FDB only supports static addresses\n",
6964 ixgbe_driver_name);
6965 return -EINVAL;
6966 }
6967
John Fastabend95447462012-05-31 12:42:26 +00006968 if (is_unicast_ether_addr(addr)) {
6969 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6970
6971 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006972 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006973 else
John Fastabend95447462012-05-31 12:42:26 +00006974 err = -ENOMEM;
6975 } else if (is_multicast_ether_addr(addr)) {
6976 err = dev_mc_add_excl(dev, addr);
6977 } else {
6978 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006979 }
6980
6981 /* Only return duplicate errors if NLM_F_EXCL is set */
6982 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6983 err = 0;
6984
6985 return err;
6986}
6987
6988static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6989 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006990 const unsigned char *addr)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006991{
6992 struct ixgbe_adapter *adapter = netdev_priv(dev);
6993 int err = -EOPNOTSUPP;
6994
6995 if (ndm->ndm_state & NUD_PERMANENT) {
6996 pr_info("%s: FDB only supports static addresses\n",
6997 ixgbe_driver_name);
6998 return -EINVAL;
6999 }
7000
7001 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7002 if (is_unicast_ether_addr(addr))
7003 err = dev_uc_del(dev, addr);
7004 else if (is_multicast_ether_addr(addr))
7005 err = dev_mc_del(dev, addr);
7006 else
7007 err = -EINVAL;
7008 }
7009
7010 return err;
7011}
7012
7013static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7014 struct netlink_callback *cb,
7015 struct net_device *dev,
7016 int idx)
7017{
7018 struct ixgbe_adapter *adapter = netdev_priv(dev);
7019
7020 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7021 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7022
7023 return idx;
7024}
7025
John Fastabend815cccb2012-10-24 08:13:09 +00007026static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7027 struct nlmsghdr *nlh)
7028{
7029 struct ixgbe_adapter *adapter = netdev_priv(dev);
7030 struct nlattr *attr, *br_spec;
7031 int rem;
7032
7033 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7034 return -EOPNOTSUPP;
7035
7036 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7037
7038 nla_for_each_nested(attr, br_spec, rem) {
7039 __u16 mode;
7040 u32 reg = 0;
7041
7042 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7043 continue;
7044
7045 mode = nla_get_u16(attr);
7046 if (mode == BRIDGE_MODE_VEPA)
7047 reg = 0;
7048 else if (mode == BRIDGE_MODE_VEB)
7049 reg = IXGBE_PFDTXGSWC_VT_LBEN;
7050 else
7051 return -EINVAL;
7052
7053 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7054
7055 e_info(drv, "enabling bridge mode: %s\n",
7056 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7057 }
7058
7059 return 0;
7060}
7061
7062static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7063 struct net_device *dev)
7064{
7065 struct ixgbe_adapter *adapter = netdev_priv(dev);
7066 u16 mode;
7067
7068 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7069 return 0;
7070
7071 if (IXGBE_READ_REG(&adapter->hw, IXGBE_PFDTXGSWC) & 1)
7072 mode = BRIDGE_MODE_VEB;
7073 else
7074 mode = BRIDGE_MODE_VEPA;
7075
7076 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7077}
7078
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007079static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007080 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007081 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007082 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007083 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007084 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007085 .ndo_validate_addr = eth_validate_addr,
7086 .ndo_set_mac_address = ixgbe_set_mac,
7087 .ndo_change_mtu = ixgbe_change_mtu,
7088 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007089 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7090 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007091 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007092 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7093 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7094 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007095 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007096 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007097 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007098#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007099 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007100#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007101#ifdef CONFIG_NET_POLL_CONTROLLER
7102 .ndo_poll_controller = ixgbe_netpoll,
7103#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007104#ifdef IXGBE_FCOE
7105 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007106 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007107 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007108 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7109 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007110 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007111 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007112#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007113 .ndo_set_features = ixgbe_set_features,
7114 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007115 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7116 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7117 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
John Fastabend815cccb2012-10-24 08:13:09 +00007118 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7119 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007120};
7121
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007122/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007123 * ixgbe_wol_supported - Check whether device supports WoL
7124 * @hw: hw specific details
7125 * @device_id: the device ID
7126 * @subdev_id: the subsystem device ID
7127 *
7128 * This function is used by probe and ethtool to determine
7129 * which devices have WoL support
7130 *
7131 **/
7132int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7133 u16 subdevice_id)
7134{
7135 struct ixgbe_hw *hw = &adapter->hw;
7136 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7137 int is_wol_supported = 0;
7138
7139 switch (device_id) {
7140 case IXGBE_DEV_ID_82599_SFP:
7141 /* Only these subdevices could supports WOL */
7142 switch (subdevice_id) {
7143 case IXGBE_SUBDEV_ID_82599_560FLR:
7144 /* only support first port */
7145 if (hw->bus.func != 0)
7146 break;
7147 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007148 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007149 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007150 is_wol_supported = 1;
7151 break;
7152 }
7153 break;
7154 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7155 /* All except this subdevice support WOL */
7156 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7157 is_wol_supported = 1;
7158 break;
7159 case IXGBE_DEV_ID_82599_KX4:
7160 is_wol_supported = 1;
7161 break;
7162 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007163 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007164 /* check eeprom to see if enabled wol */
7165 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7166 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7167 (hw->bus.func == 0))) {
7168 is_wol_supported = 1;
7169 }
7170 break;
7171 }
7172
7173 return is_wol_supported;
7174}
7175
7176/**
Auke Kok9a799d72007-09-15 14:07:45 -07007177 * ixgbe_probe - Device Initialization Routine
7178 * @pdev: PCI device information struct
7179 * @ent: entry in ixgbe_pci_tbl
7180 *
7181 * Returns 0 on success, negative on failure
7182 *
7183 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7184 * The OS initialization, configuring of the adapter private structure,
7185 * and a hardware reset occur.
7186 **/
7187static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007188 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007189{
7190 struct net_device *netdev;
7191 struct ixgbe_adapter *adapter = NULL;
7192 struct ixgbe_hw *hw;
7193 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007194 static int cards_found;
7195 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007196 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007197 unsigned int indices = num_possible_cpus();
John Fastabend3f4a6f02012-06-05 05:58:52 +00007198 unsigned int dcb_max = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00007199#ifdef IXGBE_FCOE
7200 u16 device_caps;
7201#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007202 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007203
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007204 /* Catch broken hardware that put the wrong VF device ID in
7205 * the PCIe SR-IOV capability.
7206 */
7207 if (pdev->is_virtfn) {
7208 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7209 pci_name(pdev), pdev->vendor, pdev->device);
7210 return -EINVAL;
7211 }
7212
gouji-new9ce77662009-05-06 10:44:45 +00007213 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007214 if (err)
7215 return err;
7216
Nick Nunley1b507732010-04-27 13:10:27 +00007217 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7218 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007219 pci_using_dac = 1;
7220 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007221 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007222 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007223 err = dma_set_coherent_mask(&pdev->dev,
7224 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007225 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007226 dev_err(&pdev->dev,
7227 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007228 goto err_dma;
7229 }
7230 }
7231 pci_using_dac = 0;
7232 }
7233
gouji-new9ce77662009-05-06 10:44:45 +00007234 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007235 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007236 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007237 dev_err(&pdev->dev,
7238 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007239 goto err_pci_reg;
7240 }
7241
Frans Pop19d5afd2009-10-02 10:04:12 -07007242 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007243
Auke Kok9a799d72007-09-15 14:07:45 -07007244 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007245 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007246
John Fastabende901acd2011-04-26 07:26:08 +00007247#ifdef CONFIG_IXGBE_DCB
John Fastabend3f4a6f02012-06-05 05:58:52 +00007248 if (ii->mac == ixgbe_mac_82598EB)
7249 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7250 IXGBE_MAX_RSS_INDICES);
7251 else
7252 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7253 IXGBE_MAX_FDIR_INDICES);
John Fastabende901acd2011-04-26 07:26:08 +00007254#endif
7255
John Fastabendc85a2612010-02-25 23:15:21 +00007256 if (ii->mac == ixgbe_mac_82598EB)
7257 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7258 else
7259 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7260
John Fastabende901acd2011-04-26 07:26:08 +00007261#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007262 indices += min_t(unsigned int, num_possible_cpus(),
7263 IXGBE_MAX_FCOE_INDICES);
7264#endif
John Fastabend3f4a6f02012-06-05 05:58:52 +00007265 indices = max_t(unsigned int, dcb_max, indices);
John Fastabendc85a2612010-02-25 23:15:21 +00007266 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007267 if (!netdev) {
7268 err = -ENOMEM;
7269 goto err_alloc_etherdev;
7270 }
7271
Auke Kok9a799d72007-09-15 14:07:45 -07007272 SET_NETDEV_DEV(netdev, &pdev->dev);
7273
Auke Kok9a799d72007-09-15 14:07:45 -07007274 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007275 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007276
7277 adapter->netdev = netdev;
7278 adapter->pdev = pdev;
7279 hw = &adapter->hw;
7280 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007281 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007282
Jeff Kirsher05857982008-09-11 19:57:00 -07007283 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007284 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007285 if (!hw->hw_addr) {
7286 err = -EIO;
7287 goto err_ioremap;
7288 }
7289
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007290 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007291 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007292 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007293 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007294
Auke Kok9a799d72007-09-15 14:07:45 -07007295 adapter->bd_number = cards_found;
7296
Auke Kok9a799d72007-09-15 14:07:45 -07007297 /* Setup hw api */
7298 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007299 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007300
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007301 /* EEPROM */
7302 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7303 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7304 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7305 if (!(eec & (1 << 8)))
7306 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7307
7308 /* PHY */
7309 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007310 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007311 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7312 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7313 hw->phy.mdio.mmds = 0;
7314 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7315 hw->phy.mdio.dev = netdev;
7316 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7317 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007318
Don Skidmore8ca783a2009-05-26 20:40:47 -07007319 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007320
7321 /* setup the private structure */
7322 err = ixgbe_sw_init(adapter);
7323 if (err)
7324 goto err_sw_init;
7325
Don Skidmoree86bff02010-02-11 04:14:08 +00007326 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007327 switch (adapter->hw.mac.type) {
7328 case ixgbe_mac_82599EB:
7329 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007330 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007331 break;
7332 default:
7333 break;
7334 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007335
Don Skidmorebf069c92009-05-07 10:39:54 +00007336 /*
7337 * If there is a fan on this device and it has failed log the
7338 * failure.
7339 */
7340 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7341 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7342 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007343 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007344 }
7345
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007346 if (allow_unsupported_sfp)
7347 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7348
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007349 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007350 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007351 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007352 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007353 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7354 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007355 err = 0;
7356 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007357 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007358 "module type was detected.\n");
7359 e_dev_err("Reload the driver after installing a supported "
7360 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007361 goto err_sw_init;
7362 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007363 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007364 goto err_sw_init;
7365 }
7366
Alexander Duyck99d74482012-05-09 08:09:25 +00007367#ifdef CONFIG_PCI_IOV
7368 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007369
Alexander Duyck99d74482012-05-09 08:09:25 +00007370#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007371 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007372 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007373 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007374 NETIF_F_HW_VLAN_TX |
7375 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007376 NETIF_F_HW_VLAN_FILTER |
7377 NETIF_F_TSO |
7378 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007379 NETIF_F_RXHASH |
7380 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007381
Don Skidmore082757a2011-07-21 05:55:00 +00007382 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007383
Don Skidmore58be7662011-04-12 09:42:11 +00007384 switch (adapter->hw.mac.type) {
7385 case ixgbe_mac_82599EB:
7386 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007387 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007388 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7389 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007390 break;
7391 default:
7392 break;
7393 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007394
Ben Greear3f2d1c02012-03-08 08:28:41 +00007395 netdev->hw_features |= NETIF_F_RXALL;
7396
Jeff Kirsherad31c402008-06-05 04:05:30 -07007397 netdev->vlan_features |= NETIF_F_TSO;
7398 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007399 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007400 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007401 netdev->vlan_features |= NETIF_F_SG;
7402
Jiri Pirko01789342011-08-16 06:29:00 +00007403 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007404 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007405
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007406#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007407 netdev->dcbnl_ops = &dcbnl_ops;
7408#endif
7409
Yi Zoueacd73f2009-05-13 13:11:06 +00007410#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007411 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007412 if (hw->mac.ops.get_device_caps) {
7413 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007414 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7415 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007416 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007417
7418 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7419
Alexander Duycka58915c2012-05-25 06:38:18 +00007420 netdev->features |= NETIF_F_FSO |
7421 NETIF_F_FCOE_CRC;
7422
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007423 netdev->vlan_features |= NETIF_F_FSO |
7424 NETIF_F_FCOE_CRC |
7425 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007426 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007427#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007428 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007429 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007430 netdev->vlan_features |= NETIF_F_HIGHDMA;
7431 }
Auke Kok9a799d72007-09-15 14:07:45 -07007432
Don Skidmore082757a2011-07-21 05:55:00 +00007433 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7434 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007435 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007436 netdev->features |= NETIF_F_LRO;
7437
Auke Kok9a799d72007-09-15 14:07:45 -07007438 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007439 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007440 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007441 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007442 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007443 }
7444
7445 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7446 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7447
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007448 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007449 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007450 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007451 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007452 }
7453
Alexander Duyck70864002011-04-27 09:13:56 +00007454 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007455 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007456
Alexander Duyck70864002011-04-27 09:13:56 +00007457 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7458 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007459
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007460 err = ixgbe_init_interrupt_scheme(adapter);
7461 if (err)
7462 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007463
Jacob Keller8e2813f2012-04-21 06:05:40 +00007464 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007465 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007466 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7467 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007468 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007469
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007470 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7471
Emil Tantilov15e52092011-09-29 05:01:29 +00007472 /* save off EEPROM version number */
7473 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7474 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7475
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007476 /* pick up the PCI bus settings for reporting later */
7477 hw->mac.ops.get_bus_info(hw);
7478
Auke Kok9a799d72007-09-15 14:07:45 -07007479 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007480 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007481 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7482 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007483 "Unknown"),
7484 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7485 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7486 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7487 "Unknown"),
7488 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007489
7490 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7491 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007492 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007493 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007494 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007495 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007496 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007497 else
Don Skidmore289700db2010-12-03 03:32:58 +00007498 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7499 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007500
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007501 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007502 e_dev_warn("PCI-Express bandwidth available for this card is "
7503 "not sufficient for optimal performance.\n");
7504 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7505 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007506 }
7507
Auke Kok9a799d72007-09-15 14:07:45 -07007508 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007509 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007510 if (err == IXGBE_ERR_EEPROM_VERSION) {
7511 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007512 e_dev_warn("This device is a pre-production adapter/LOM. "
7513 "Please be aware there may be issues associated "
7514 "with your hardware. If you are experiencing "
7515 "problems please contact your Intel or hardware "
7516 "representative who provided you with this "
7517 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007518 }
Auke Kok9a799d72007-09-15 14:07:45 -07007519 strcpy(netdev->name, "eth%d");
7520 err = register_netdev(netdev);
7521 if (err)
7522 goto err_register;
7523
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007524 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7525 if (hw->mac.ops.disable_tx_laser &&
7526 ((hw->phy.multispeed_fiber) ||
7527 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7528 (hw->mac.type == ixgbe_mac_82599EB))))
7529 hw->mac.ops.disable_tx_laser(hw);
7530
Jesse Brandeburg54386462009-04-17 20:44:27 +00007531 /* carrier off reporting is important to ethtool even BEFORE open */
7532 netif_carrier_off(netdev);
7533
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007534#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007535 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007536 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007537 ixgbe_setup_dca(adapter);
7538 }
7539#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007540 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007541 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007542 for (i = 0; i < adapter->num_vfs; i++)
7543 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7544 }
7545
Jacob Keller2466dd92011-09-08 03:50:54 +00007546 /* firmware requires driver version to be 0xFFFFFFFF
7547 * since os does not support feature
7548 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007549 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007550 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7551 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007552
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007553 /* add san mac addr to netdev */
7554 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007555
Neerav Parikhea818752012-01-04 20:23:40 +00007556 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007557 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007558
Don Skidmore12109822012-05-04 06:07:08 +00007559#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007560 if (ixgbe_sysfs_init(adapter))
7561 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007562#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007563
Catherine Sullivan00949162012-08-10 01:59:10 +00007564#ifdef CONFIG_DEBUG_FS
7565 ixgbe_dbg_adapter_init(adapter);
7566#endif /* CONFIG_DEBUG_FS */
7567
Auke Kok9a799d72007-09-15 14:07:45 -07007568 return 0;
7569
7570err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007571 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007572 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007573err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007574 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007575 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007576 iounmap(hw->hw_addr);
7577err_ioremap:
7578 free_netdev(netdev);
7579err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007580 pci_release_selected_regions(pdev,
7581 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007582err_pci_reg:
7583err_dma:
7584 pci_disable_device(pdev);
7585 return err;
7586}
7587
7588/**
7589 * ixgbe_remove - Device Removal Routine
7590 * @pdev: PCI device information struct
7591 *
7592 * ixgbe_remove is called by the PCI subsystem to alert the driver
7593 * that it should release a PCI device. The could be caused by a
7594 * Hot-Plug event, or because the driver is going to be removed from
7595 * memory.
7596 **/
7597static void __devexit ixgbe_remove(struct pci_dev *pdev)
7598{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007599 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7600 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007601
Catherine Sullivan00949162012-08-10 01:59:10 +00007602#ifdef CONFIG_DEBUG_FS
7603 ixgbe_dbg_adapter_exit(adapter);
7604#endif /*CONFIG_DEBUG_FS */
7605
Auke Kok9a799d72007-09-15 14:07:45 -07007606 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007607 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007608
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007609
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007610#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007611 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7612 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7613 dca_remove_requester(&pdev->dev);
7614 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7615 }
7616
7617#endif
Don Skidmore12109822012-05-04 06:07:08 +00007618#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007619 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007620#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007621
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007622 /* remove the added san mac */
7623 ixgbe_del_sanmac_netdev(netdev);
7624
Donald Skidmorec4900be2008-11-20 21:11:42 -08007625 if (netdev->reg_state == NETREG_REGISTERED)
7626 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007627
Alexander Duyck92971272012-05-23 02:58:40 +00007628 ixgbe_disable_sriov(adapter);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007629
Alexander Duyck7a921c92009-05-06 10:43:28 +00007630 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007631
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007632 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007633
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007634#ifdef CONFIG_DCB
7635 kfree(adapter->ixgbe_ieee_pfc);
7636 kfree(adapter->ixgbe_ieee_ets);
7637
7638#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007639 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007640 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007641 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007642
Emil Tantilov849c4542010-06-03 16:53:41 +00007643 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007644
Auke Kok9a799d72007-09-15 14:07:45 -07007645 free_netdev(netdev);
7646
Frans Pop19d5afd2009-10-02 10:04:12 -07007647 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007648
Auke Kok9a799d72007-09-15 14:07:45 -07007649 pci_disable_device(pdev);
7650}
7651
7652/**
7653 * ixgbe_io_error_detected - called when PCI error is detected
7654 * @pdev: Pointer to PCI device
7655 * @state: The current pci connection state
7656 *
7657 * This function is called after a PCI bus error affecting
7658 * this device has been detected.
7659 */
7660static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007661 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007662{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007663 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7664 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007665
Greg Rose83c61fa2011-09-07 05:59:35 +00007666#ifdef CONFIG_PCI_IOV
7667 struct pci_dev *bdev, *vfdev;
7668 u32 dw0, dw1, dw2, dw3;
7669 int vf, pos;
7670 u16 req_id, pf_func;
7671
7672 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7673 adapter->num_vfs == 0)
7674 goto skip_bad_vf_detection;
7675
7676 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007677 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007678 bdev = bdev->bus->self;
7679
7680 if (!bdev)
7681 goto skip_bad_vf_detection;
7682
7683 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7684 if (!pos)
7685 goto skip_bad_vf_detection;
7686
7687 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7688 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7689 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7690 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7691
7692 req_id = dw1 >> 16;
7693 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7694 if (!(req_id & 0x0080))
7695 goto skip_bad_vf_detection;
7696
7697 pf_func = req_id & 0x01;
7698 if ((pf_func & 1) == (pdev->devfn & 1)) {
7699 unsigned int device_id;
7700
7701 vf = (req_id & 0x7F) >> 1;
7702 e_dev_err("VF %d has caused a PCIe error\n", vf);
7703 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7704 "%8.8x\tdw3: %8.8x\n",
7705 dw0, dw1, dw2, dw3);
7706 switch (adapter->hw.mac.type) {
7707 case ixgbe_mac_82599EB:
7708 device_id = IXGBE_82599_VF_DEVICE_ID;
7709 break;
7710 case ixgbe_mac_X540:
7711 device_id = IXGBE_X540_VF_DEVICE_ID;
7712 break;
7713 default:
7714 device_id = 0;
7715 break;
7716 }
7717
7718 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007719 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007720 while (vfdev) {
7721 if (vfdev->devfn == (req_id & 0xFF))
7722 break;
Jon Mason36e90312012-07-19 21:02:09 +00007723 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007724 device_id, vfdev);
7725 }
7726 /*
7727 * There's a slim chance the VF could have been hot plugged,
7728 * so if it is no longer present we don't need to issue the
7729 * VFLR. Just clean up the AER in that case.
7730 */
7731 if (vfdev) {
7732 e_dev_err("Issuing VFLR to VF %d\n", vf);
7733 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7734 }
7735
7736 pci_cleanup_aer_uncorrect_error_status(pdev);
7737 }
7738
7739 /*
7740 * Even though the error may have occurred on the other port
7741 * we still need to increment the vf error reference count for
7742 * both ports because the I/O resume function will be called
7743 * for both of them.
7744 */
7745 adapter->vferr_refcount++;
7746
7747 return PCI_ERS_RESULT_RECOVERED;
7748
7749skip_bad_vf_detection:
7750#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007751 netif_device_detach(netdev);
7752
Breno Leitao3044b8d2009-05-06 10:44:26 +00007753 if (state == pci_channel_io_perm_failure)
7754 return PCI_ERS_RESULT_DISCONNECT;
7755
Auke Kok9a799d72007-09-15 14:07:45 -07007756 if (netif_running(netdev))
7757 ixgbe_down(adapter);
7758 pci_disable_device(pdev);
7759
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007760 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007761 return PCI_ERS_RESULT_NEED_RESET;
7762}
7763
7764/**
7765 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7766 * @pdev: Pointer to PCI device
7767 *
7768 * Restart the card from scratch, as if from a cold-boot.
7769 */
7770static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7771{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007772 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007773 pci_ers_result_t result;
7774 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007775
gouji-new9ce77662009-05-06 10:44:45 +00007776 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007777 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007778 result = PCI_ERS_RESULT_DISCONNECT;
7779 } else {
7780 pci_set_master(pdev);
7781 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007782 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007783
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007784 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007785
7786 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007787 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007788 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007789 }
Auke Kok9a799d72007-09-15 14:07:45 -07007790
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007791 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7792 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007793 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7794 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007795 /* non-fatal, continue */
7796 }
Auke Kok9a799d72007-09-15 14:07:45 -07007797
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007798 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007799}
7800
7801/**
7802 * ixgbe_io_resume - called when traffic can start flowing again.
7803 * @pdev: Pointer to PCI device
7804 *
7805 * This callback is called when the error recovery driver tells us that
7806 * its OK to resume normal operation.
7807 */
7808static void ixgbe_io_resume(struct pci_dev *pdev)
7809{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007810 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7811 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007812
Greg Rose83c61fa2011-09-07 05:59:35 +00007813#ifdef CONFIG_PCI_IOV
7814 if (adapter->vferr_refcount) {
7815 e_info(drv, "Resuming after VF err\n");
7816 adapter->vferr_refcount--;
7817 return;
7818 }
7819
7820#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007821 if (netif_running(netdev))
7822 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007823
7824 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007825}
7826
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007827static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007828 .error_detected = ixgbe_io_error_detected,
7829 .slot_reset = ixgbe_io_slot_reset,
7830 .resume = ixgbe_io_resume,
7831};
7832
7833static struct pci_driver ixgbe_driver = {
7834 .name = ixgbe_driver_name,
7835 .id_table = ixgbe_pci_tbl,
7836 .probe = ixgbe_probe,
7837 .remove = __devexit_p(ixgbe_remove),
7838#ifdef CONFIG_PM
7839 .suspend = ixgbe_suspend,
7840 .resume = ixgbe_resume,
7841#endif
7842 .shutdown = ixgbe_shutdown,
7843 .err_handler = &ixgbe_err_handler
7844};
7845
7846/**
7847 * ixgbe_init_module - Driver Registration Routine
7848 *
7849 * ixgbe_init_module is the first routine called when the driver is
7850 * loaded. All it does is register with the PCI subsystem.
7851 **/
7852static int __init ixgbe_init_module(void)
7853{
7854 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007855 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007856 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007857
Catherine Sullivan00949162012-08-10 01:59:10 +00007858#ifdef CONFIG_DEBUG_FS
7859 ixgbe_dbg_init();
7860#endif /* CONFIG_DEBUG_FS */
7861
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007862#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007863 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007864#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007865
Auke Kok9a799d72007-09-15 14:07:45 -07007866 ret = pci_register_driver(&ixgbe_driver);
7867 return ret;
7868}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007869
Auke Kok9a799d72007-09-15 14:07:45 -07007870module_init(ixgbe_init_module);
7871
7872/**
7873 * ixgbe_exit_module - Driver Exit Cleanup Routine
7874 *
7875 * ixgbe_exit_module is called just before the driver is removed
7876 * from memory.
7877 **/
7878static void __exit ixgbe_exit_module(void)
7879{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007880#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007881 dca_unregister_notify(&dca_notifier);
7882#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007883 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00007884
7885#ifdef CONFIG_DEBUG_FS
7886 ixgbe_dbg_exit();
7887#endif /* CONFIG_DEBUG_FS */
7888
Eric Dumazet1a515022010-11-16 19:26:42 -08007889 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007890}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007891
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007892#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007893static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007894 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007895{
7896 int ret_val;
7897
7898 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007899 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007900
7901 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7902}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007903
Alexander Duyckb4533682009-03-31 21:32:42 +00007904#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007905
Auke Kok9a799d72007-09-15 14:07:45 -07007906module_exit(ixgbe_exit_module);
7907
7908/* ixgbe_main.c */