blob: 88f6b2e9b72db2ddb22b917fcb4e4ae4c9b99514 [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>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000058#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000059char ixgbe_default_device_descr[] =
60 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000061#else
62static char ixgbe_default_device_descr[] =
63 "Intel(R) 10 Gigabit Network Connection";
64#endif
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000065#define MAJ 3
Don Skidmore8e4f3252012-03-16 05:41:48 +000066#define MIN 8
67#define BUILD 21
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000068#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000069 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070070const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000071static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000072 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070073
74static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070075 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000076 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e2010-11-16 19:27:16 -080077 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070078};
79
80/* ixgbe_pci_tbl - PCI Device ID Table
81 *
82 * Wildcard entries (PCI_ANY_ID) should come last
83 * Last entry must be all 0s
84 *
85 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
86 * Class, Class Mask, private data (not used) }
87 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000088static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700117 /* required last entry */
118 {0, }
119};
120MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
121
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400122#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800123static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000124 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800125static struct notifier_block dca_notifier = {
126 .notifier_call = ixgbe_notify_dca,
127 .next = NULL,
128 .priority = 0
129};
130#endif
131
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#ifdef CONFIG_PCI_IOV
133static unsigned int max_vfs;
134module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000135MODULE_PARM_DESC(max_vfs,
136 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000137#endif /* CONFIG_PCI_IOV */
138
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000139static unsigned int allow_unsupported_sfp;
140module_param(allow_unsupported_sfp, uint, 0);
141MODULE_PARM_DESC(allow_unsupported_sfp,
142 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
143
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000144#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
145static int debug = -1;
146module_param(debug, int, 0);
147MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
148
Auke Kok9a799d72007-09-15 14:07:45 -0700149MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
150MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
151MODULE_LICENSE("GPL");
152MODULE_VERSION(DRV_VERSION);
153
Alexander Duyck70864002011-04-27 09:13:56 +0000154static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
155{
156 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
157 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
158 schedule_work(&adapter->service_task);
159}
160
161static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
162{
163 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
164
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000165 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000166 smp_mb__before_clear_bit();
167 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
168}
169
Taku Izumidcd79ae2010-04-27 14:39:53 +0000170struct ixgbe_reg_info {
171 u32 ofs;
172 char *name;
173};
174
175static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
176
177 /* General Registers */
178 {IXGBE_CTRL, "CTRL"},
179 {IXGBE_STATUS, "STATUS"},
180 {IXGBE_CTRL_EXT, "CTRL_EXT"},
181
182 /* Interrupt Registers */
183 {IXGBE_EICR, "EICR"},
184
185 /* RX Registers */
186 {IXGBE_SRRCTL(0), "SRRCTL"},
187 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
188 {IXGBE_RDLEN(0), "RDLEN"},
189 {IXGBE_RDH(0), "RDH"},
190 {IXGBE_RDT(0), "RDT"},
191 {IXGBE_RXDCTL(0), "RXDCTL"},
192 {IXGBE_RDBAL(0), "RDBAL"},
193 {IXGBE_RDBAH(0), "RDBAH"},
194
195 /* TX Registers */
196 {IXGBE_TDBAL(0), "TDBAL"},
197 {IXGBE_TDBAH(0), "TDBAH"},
198 {IXGBE_TDLEN(0), "TDLEN"},
199 {IXGBE_TDH(0), "TDH"},
200 {IXGBE_TDT(0), "TDT"},
201 {IXGBE_TXDCTL(0), "TXDCTL"},
202
203 /* List Terminator */
204 {}
205};
206
207
208/*
209 * ixgbe_regdump - register printout routine
210 */
211static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
212{
213 int i = 0, j = 0;
214 char rname[16];
215 u32 regs[64];
216
217 switch (reginfo->ofs) {
218 case IXGBE_SRRCTL(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
221 break;
222 case IXGBE_DCA_RXCTRL(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
225 break;
226 case IXGBE_RDLEN(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
229 break;
230 case IXGBE_RDH(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
233 break;
234 case IXGBE_RDT(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
237 break;
238 case IXGBE_RXDCTL(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
241 break;
242 case IXGBE_RDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
245 break;
246 case IXGBE_RDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
249 break;
250 case IXGBE_TDBAL(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
253 break;
254 case IXGBE_TDBAH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
257 break;
258 case IXGBE_TDLEN(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
261 break;
262 case IXGBE_TDH(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
265 break;
266 case IXGBE_TDT(0):
267 for (i = 0; i < 64; i++)
268 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
269 break;
270 case IXGBE_TXDCTL(0):
271 for (i = 0; i < 64; i++)
272 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
273 break;
274 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000275 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000276 IXGBE_READ_REG(hw, reginfo->ofs));
277 return;
278 }
279
280 for (i = 0; i < 8; i++) {
281 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000282 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000283 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000284 pr_cont(" %08x", regs[i*8+j]);
285 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000286 }
287
288}
289
290/*
291 * ixgbe_dump - Print registers, tx-rings and rx-rings
292 */
293static void ixgbe_dump(struct ixgbe_adapter *adapter)
294{
295 struct net_device *netdev = adapter->netdev;
296 struct ixgbe_hw *hw = &adapter->hw;
297 struct ixgbe_reg_info *reginfo;
298 int n = 0;
299 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000300 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000301 union ixgbe_adv_tx_desc *tx_desc;
302 struct my_u0 { u64 a; u64 b; } *u0;
303 struct ixgbe_ring *rx_ring;
304 union ixgbe_adv_rx_desc *rx_desc;
305 struct ixgbe_rx_buffer *rx_buffer_info;
306 u32 staterr;
307 int i = 0;
308
309 if (!netif_msg_hw(adapter))
310 return;
311
312 /* Print netdevice Info */
313 if (netdev) {
314 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000315 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000316 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000317 pr_info("%-15s %016lX %016lX %016lX\n",
318 netdev->name,
319 netdev->state,
320 netdev->trans_start,
321 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000322 }
323
324 /* Print Registers */
325 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000326 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000327 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
328 reginfo->name; reginfo++) {
329 ixgbe_regdump(hw, reginfo);
330 }
331
332 /* Print TX Ring Summary */
333 if (!netdev || !netif_running(netdev))
334 goto exit;
335
336 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000337 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000338 for (n = 0; n < adapter->num_tx_queues; n++) {
339 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000340 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000341 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000342 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000343 (u64)dma_unmap_addr(tx_buffer, dma),
344 dma_unmap_len(tx_buffer, len),
345 tx_buffer->next_to_watch,
346 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000347 }
348
349 /* Print TX Rings */
350 if (!netif_msg_tx_done(adapter))
351 goto rx_ring_summary;
352
353 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
354
355 /* Transmit Descriptor Formats
356 *
357 * Advanced Transmit Descriptor
358 * +--------------------------------------------------------------+
359 * 0 | Buffer Address [63:0] |
360 * +--------------------------------------------------------------+
361 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
362 * +--------------------------------------------------------------+
363 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
364 */
365
366 for (n = 0; n < adapter->num_tx_queues; n++) {
367 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000368 pr_info("------------------------------------\n");
369 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
370 pr_info("------------------------------------\n");
371 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000372 "[PlPOIdStDDt Ln] [bi->dma ] "
373 "leng ntw timestamp bi->skb\n");
374
375 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000376 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000377 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000378 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000379 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000380 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000381 le64_to_cpu(u0->a),
382 le64_to_cpu(u0->b),
Alexander Duyck729739b2012-02-08 07:51:06 +0000383 (u64)dma_unmap_addr(tx_buffer, dma),
384 dma_unmap_len(tx_buffer, len),
385 tx_buffer->next_to_watch,
386 (u64)tx_buffer->time_stamp,
387 tx_buffer->skb);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 if (i == tx_ring->next_to_use &&
389 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000390 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000391 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000392 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000393 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000394 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000395 else
Joe Perchesc7689572010-09-07 21:35:17 +0000396 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000397
398 if (netif_msg_pktdata(adapter) &&
Alexander Duyck729739b2012-02-08 07:51:06 +0000399 dma_unmap_len(tx_buffer, len) != 0)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000400 print_hex_dump(KERN_INFO, "",
401 DUMP_PREFIX_ADDRESS, 16, 1,
Alexander Duyck729739b2012-02-08 07:51:06 +0000402 phys_to_virt(dma_unmap_addr(tx_buffer,
403 dma)),
404 dma_unmap_len(tx_buffer, len),
405 true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000406 }
407 }
408
409 /* Print RX Rings Summary */
410rx_ring_summary:
411 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000412 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000413 for (n = 0; n < adapter->num_rx_queues; n++) {
414 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000415 pr_info("%5d %5X %5X\n",
416 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000417 }
418
419 /* Print RX Rings */
420 if (!netif_msg_rx_status(adapter))
421 goto exit;
422
423 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
424
425 /* Advanced Receive Descriptor (Read) Format
426 * 63 1 0
427 * +-----------------------------------------------------+
428 * 0 | Packet Buffer Address [63:1] |A0/NSE|
429 * +----------------------------------------------+------+
430 * 8 | Header Buffer Address [63:1] | DD |
431 * +-----------------------------------------------------+
432 *
433 *
434 * Advanced Receive Descriptor (Write-Back) Format
435 *
436 * 63 48 47 32 31 30 21 20 16 15 4 3 0
437 * +------------------------------------------------------+
438 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
439 * | Checksum Ident | | | | Type | Type |
440 * +------------------------------------------------------+
441 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
442 * +------------------------------------------------------+
443 * 63 48 47 32 31 20 19 0
444 */
445 for (n = 0; n < adapter->num_rx_queues; n++) {
446 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000447 pr_info("------------------------------------\n");
448 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
449 pr_info("------------------------------------\n");
450 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000451 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
452 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000453 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000454 "[vl er S cks ln] ---------------- [bi->skb] "
455 "<-- Adv Rx Write-Back format\n");
456
457 for (i = 0; i < rx_ring->count; i++) {
458 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000459 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000460 u0 = (struct my_u0 *)rx_desc;
461 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
462 if (staterr & IXGBE_RXD_STAT_DD) {
463 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000464 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000465 "%016llX ---------------- %p", i,
466 le64_to_cpu(u0->a),
467 le64_to_cpu(u0->b),
468 rx_buffer_info->skb);
469 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000470 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000471 "%016llX %016llX %p", i,
472 le64_to_cpu(u0->a),
473 le64_to_cpu(u0->b),
474 (u64)rx_buffer_info->dma,
475 rx_buffer_info->skb);
476
477 if (netif_msg_pktdata(adapter)) {
478 print_hex_dump(KERN_INFO, "",
479 DUMP_PREFIX_ADDRESS, 16, 1,
480 phys_to_virt(rx_buffer_info->dma),
Alexander Duyckf8003262012-03-03 02:35:52 +0000481 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000482 }
483 }
484
485 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000486 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000487 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000488 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000489 else
Joe Perchesc7689572010-09-07 21:35:17 +0000490 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000491
492 }
493 }
494
495exit:
496 return;
497}
498
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800499static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
500{
501 u32 ctrl_ext;
502
503 /* Let firmware take over control of h/w */
504 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
505 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000506 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800507}
508
509static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
510{
511 u32 ctrl_ext;
512
513 /* Let firmware know the driver has taken over */
514 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
515 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000516 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800517}
Auke Kok9a799d72007-09-15 14:07:45 -0700518
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000519/*
520 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
521 * @adapter: pointer to adapter struct
522 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
523 * @queue: queue to map the corresponding interrupt to
524 * @msix_vector: the vector to map to the corresponding queue
525 *
526 */
527static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000528 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700529{
530 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000531 struct ixgbe_hw *hw = &adapter->hw;
532 switch (hw->mac.type) {
533 case ixgbe_mac_82598EB:
534 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
535 if (direction == -1)
536 direction = 0;
537 index = (((direction * 64) + queue) >> 2) & 0x1F;
538 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
539 ivar &= ~(0xFF << (8 * (queue & 0x3)));
540 ivar |= (msix_vector << (8 * (queue & 0x3)));
541 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
542 break;
543 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800544 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000545 if (direction == -1) {
546 /* other causes */
547 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
548 index = ((queue & 1) * 8);
549 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
550 ivar &= ~(0xFF << index);
551 ivar |= (msix_vector << index);
552 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
553 break;
554 } else {
555 /* tx or rx causes */
556 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
557 index = ((16 * (queue & 1)) + (8 * direction));
558 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
559 ivar &= ~(0xFF << index);
560 ivar |= (msix_vector << index);
561 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
562 break;
563 }
564 default:
565 break;
566 }
Auke Kok9a799d72007-09-15 14:07:45 -0700567}
568
Alexander Duyckfe49f042009-06-04 16:00:09 +0000569static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000570 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000571{
572 u32 mask;
573
Alexander Duyckbd508172010-11-16 19:27:03 -0800574 switch (adapter->hw.mac.type) {
575 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000576 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
577 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800578 break;
579 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800580 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000581 mask = (qmask & 0xFFFFFFFF);
582 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
583 mask = (qmask >> 32);
584 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800585 break;
586 default:
587 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000588 }
589}
590
Alexander Duyck729739b2012-02-08 07:51:06 +0000591void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
592 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000593{
Alexander Duyck729739b2012-02-08 07:51:06 +0000594 if (tx_buffer->skb) {
595 dev_kfree_skb_any(tx_buffer->skb);
596 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000597 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000598 dma_unmap_addr(tx_buffer, dma),
599 dma_unmap_len(tx_buffer, len),
600 DMA_TO_DEVICE);
601 } else if (dma_unmap_len(tx_buffer, len)) {
602 dma_unmap_page(ring->dev,
603 dma_unmap_addr(tx_buffer, dma),
604 dma_unmap_len(tx_buffer, len),
605 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000606 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000607 tx_buffer->next_to_watch = NULL;
608 tx_buffer->skb = NULL;
609 dma_unmap_len_set(tx_buffer, len, 0);
610 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700611}
612
John Fastabendc84d3242010-11-16 19:27:12 -0800613static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700614{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700615 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800616 struct ixgbe_hw_stats *hwstats = &adapter->stats;
617 u32 data = 0;
618 u32 xoff[8] = {0};
619 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700620
John Fastabendc84d3242010-11-16 19:27:12 -0800621 if ((hw->fc.current_mode == ixgbe_fc_full) ||
622 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
623 switch (hw->mac.type) {
624 case ixgbe_mac_82598EB:
625 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
626 break;
627 default:
628 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
629 }
630 hwstats->lxoffrxc += data;
631
632 /* refill credits (no tx hang) if we received xoff */
633 if (!data)
634 return;
635
636 for (i = 0; i < adapter->num_tx_queues; i++)
637 clear_bit(__IXGBE_HANG_CHECK_ARMED,
638 &adapter->tx_ring[i]->state);
639 return;
640 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
641 return;
642
643 /* update stats for each tc, only valid with PFC enabled */
644 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
645 switch (hw->mac.type) {
646 case ixgbe_mac_82598EB:
647 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
648 break;
649 default:
650 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
651 }
652 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700653 }
654
John Fastabendc84d3242010-11-16 19:27:12 -0800655 /* disarm tx queues that have received xoff frames */
656 for (i = 0; i < adapter->num_tx_queues; i++) {
657 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000658 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800659
660 if (xoff[tc])
661 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
662 }
663}
664
665static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
666{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000667 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800668}
669
670static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
671{
672 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
673 struct ixgbe_hw *hw = &adapter->hw;
674
675 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
676 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
677
678 if (head != tail)
679 return (head < tail) ?
680 tail - head : (tail + ring->count - head);
681
682 return 0;
683}
684
685static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
686{
687 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
688 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
689 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
690 bool ret = false;
691
692 clear_check_for_tx_hang(tx_ring);
693
694 /*
695 * Check for a hung queue, but be thorough. This verifies
696 * that a transmit has been completed since the previous
697 * check AND there is at least one packet pending. The
698 * ARMED bit is set to indicate a potential hang. The
699 * bit is cleared if a pause frame is received to remove
700 * false hang detection due to PFC or 802.3x frames. By
701 * requiring this to fail twice we avoid races with
702 * pfc clearing the ARMED bit and conditions where we
703 * run the check_tx_hang logic with a transmit completion
704 * pending but without time to complete it yet.
705 */
706 if ((tx_done_old == tx_done) && tx_pending) {
707 /* make sure it is true for two checks in a row */
708 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
709 &tx_ring->state);
710 } else {
711 /* update completed stats and continue */
712 tx_ring->tx_stats.tx_done_old = tx_done;
713 /* reset the countdown */
714 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
715 }
716
717 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700718}
719
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000720/**
721 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
722 * @adapter: driver private struct
723 **/
724static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
725{
726
727 /* Do the reset outside of interrupt context */
728 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
729 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
730 ixgbe_service_event_schedule(adapter);
731 }
732}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700733
Auke Kok9a799d72007-09-15 14:07:45 -0700734/**
735 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000736 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700737 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700738 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000739static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000740 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700741{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000742 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000743 struct ixgbe_tx_buffer *tx_buffer;
744 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700745 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000746 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000747 unsigned int i = tx_ring->next_to_clean;
748
749 if (test_bit(__IXGBE_DOWN, &adapter->state))
750 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700751
Alexander Duyckd3d00232011-07-15 02:31:25 +0000752 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000753 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000754 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800755
Alexander Duyck729739b2012-02-08 07:51:06 +0000756 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000757 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700758
Alexander Duyckd3d00232011-07-15 02:31:25 +0000759 /* if next_to_watch is not set then there is no work pending */
760 if (!eop_desc)
761 break;
762
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000763 /* prevent any other reads prior to eop_desc */
764 rmb();
765
Alexander Duyckd3d00232011-07-15 02:31:25 +0000766 /* if DD is not set pending work has not been completed */
767 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
768 break;
769
Alexander Duyckd3d00232011-07-15 02:31:25 +0000770 /* clear next_to_watch to prevent false hangs */
771 tx_buffer->next_to_watch = NULL;
772
Alexander Duyck091a6242012-02-08 07:51:01 +0000773 /* update the statistics for this packet */
774 total_bytes += tx_buffer->bytecount;
775 total_packets += tx_buffer->gso_segs;
776
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000777 /* free the skb */
778 dev_kfree_skb_any(tx_buffer->skb);
779
Alexander Duyck729739b2012-02-08 07:51:06 +0000780 /* unmap skb header data */
781 dma_unmap_single(tx_ring->dev,
782 dma_unmap_addr(tx_buffer, dma),
783 dma_unmap_len(tx_buffer, len),
784 DMA_TO_DEVICE);
785
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000786 /* clear tx_buffer data */
787 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000788 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000789
Alexander Duyck729739b2012-02-08 07:51:06 +0000790 /* unmap remaining buffers */
791 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000792 tx_buffer++;
793 tx_desc++;
794 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000795 if (unlikely(!i)) {
796 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000797 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000798 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000799 }
800
Alexander Duyck729739b2012-02-08 07:51:06 +0000801 /* unmap any remaining paged data */
802 if (dma_unmap_len(tx_buffer, len)) {
803 dma_unmap_page(tx_ring->dev,
804 dma_unmap_addr(tx_buffer, dma),
805 dma_unmap_len(tx_buffer, len),
806 DMA_TO_DEVICE);
807 dma_unmap_len_set(tx_buffer, len, 0);
808 }
809 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800810
Alexander Duyck729739b2012-02-08 07:51:06 +0000811 /* move us one more past the eop_desc for start of next pkt */
812 tx_buffer++;
813 tx_desc++;
814 i++;
815 if (unlikely(!i)) {
816 i -= tx_ring->count;
817 tx_buffer = tx_ring->tx_buffer_info;
818 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
819 }
820
821 /* issue prefetch for next Tx descriptor */
822 prefetch(tx_desc);
823
824 /* update budget accounting */
825 budget--;
826 } while (likely(budget));
827
828 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700829 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000830 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800831 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000832 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000833 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000834 q_vector->tx.total_bytes += total_bytes;
835 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800836
John Fastabendc84d3242010-11-16 19:27:12 -0800837 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800838 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800839 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800840 e_err(drv, "Detected Tx Unit Hang\n"
841 " Tx Queue <%d>\n"
842 " TDH, TDT <%x>, <%x>\n"
843 " next_to_use <%x>\n"
844 " next_to_clean <%x>\n"
845 "tx_buffer_info[next_to_clean]\n"
846 " time_stamp <%lx>\n"
847 " jiffies <%lx>\n",
848 tx_ring->queue_index,
849 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
850 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000851 tx_ring->next_to_use, i,
852 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800853
854 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
855
856 e_info(probe,
857 "tx hang %d detected on queue %d, resetting adapter\n",
858 adapter->tx_timeout_count + 1, tx_ring->queue_index);
859
860 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000861 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800862
863 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000864 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800865 }
Auke Kok9a799d72007-09-15 14:07:45 -0700866
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000867 netdev_tx_completed_queue(txring_txq(tx_ring),
868 total_packets, total_bytes);
869
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800870#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000871 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000872 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800873 /* Make sure that anybody stopping the queue after this
874 * sees the new next_to_clean.
875 */
876 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000877 if (__netif_subqueue_stopped(tx_ring->netdev,
878 tx_ring->queue_index)
879 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
880 netif_wake_subqueue(tx_ring->netdev,
881 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800882 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800883 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800884 }
Auke Kok9a799d72007-09-15 14:07:45 -0700885
Alexander Duyck59224552011-08-31 00:01:06 +0000886 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700887}
888
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400889#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800890static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800891 struct ixgbe_ring *tx_ring,
892 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800893{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000894 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000895 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
896 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800897
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800898 switch (hw->mac.type) {
899 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000900 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800901 break;
902 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800903 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000904 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
905 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
906 break;
907 default:
908 /* for unknown hardware do not write register */
909 return;
910 }
911
912 /*
913 * We can enable relaxed ordering for reads, but not writes when
914 * DCA is enabled. This is due to a known issue in some chipsets
915 * which will cause the DCA tag to be cleared.
916 */
917 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
918 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
919 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
920
921 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
922}
923
924static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
925 struct ixgbe_ring *rx_ring,
926 int cpu)
927{
928 struct ixgbe_hw *hw = &adapter->hw;
929 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
930 u8 reg_idx = rx_ring->reg_idx;
931
932
933 switch (hw->mac.type) {
934 case ixgbe_mac_82599EB:
935 case ixgbe_mac_X540:
936 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800937 break;
938 default:
939 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800940 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000941
942 /*
943 * We can enable relaxed ordering for reads, but not writes when
944 * DCA is enabled. This is due to a known issue in some chipsets
945 * which will cause the DCA tag to be cleared.
946 */
947 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
948 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
949 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
950
951 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800952}
953
954static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
955{
956 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000957 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800959
960 if (q_vector->cpu == cpu)
961 goto out_no_update;
962
Alexander Duycka5579282012-02-08 07:50:04 +0000963 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000964 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800965
Alexander Duycka5579282012-02-08 07:50:04 +0000966 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000967 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968
969 q_vector->cpu = cpu;
970out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800971 put_cpu();
972}
973
974static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
975{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800976 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800977 int i;
978
979 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
980 return;
981
Alexander Duycke35ec122009-05-21 13:07:12 +0000982 /* always use CB2 mode, difference is masked in the CB driver */
983 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
984
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800985 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
986 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
987 else
988 num_q_vectors = 1;
989
990 for (i = 0; i < num_q_vectors; i++) {
991 adapter->q_vector[i]->cpu = -1;
992 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800993 }
994}
995
996static int __ixgbe_notify_dca(struct device *dev, void *data)
997{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800998 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800999 unsigned long event = *(unsigned long *)data;
1000
Don Skidmore2a72c312011-07-20 02:27:05 +00001001 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001002 return 0;
1003
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001004 switch (event) {
1005 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001006 /* if we're already enabled, don't do it again */
1007 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1008 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001009 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001010 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001011 ixgbe_setup_dca(adapter);
1012 break;
1013 }
1014 /* Fall Through since DCA is disabled. */
1015 case DCA_PROVIDER_REMOVE:
1016 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1017 dca_remove_requester(dev);
1018 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1019 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1020 }
1021 break;
1022 }
1023
Denis V. Lunev652f0932008-03-27 14:39:17 +03001024 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001025}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001026
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001027#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001028static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1029 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001030 struct sk_buff *skb)
1031{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001032 if (ring->netdev->features & NETIF_F_RXHASH)
1033 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001034}
1035
Alexander Duyckf8003262012-03-03 02:35:52 +00001036#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001037/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001038 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1039 * @adapter: address of board private structure
1040 * @rx_desc: advanced rx descriptor
1041 *
1042 * Returns : true if it is FCoE pkt
1043 */
1044static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1045 union ixgbe_adv_rx_desc *rx_desc)
1046{
1047 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1048
1049 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1050 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1051 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1052 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1053}
1054
Alexander Duyckf8003262012-03-03 02:35:52 +00001055#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001056/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001057 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001058 * @ring: structure containing ring specific data
1059 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001060 * @skb: skb currently being received and modified
1061 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001062static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001063 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001064 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001065{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001066 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001067
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001068 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001069 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001070 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001071
1072 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001073 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1074 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001075 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001076 return;
1077 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001078
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001079 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001080 return;
1081
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001082 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001083 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001084
1085 /*
1086 * 82599 errata, UDP frames with a 0 checksum can be marked as
1087 * checksum errors.
1088 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001089 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1090 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001091 return;
1092
Alexander Duyck8a0da212012-01-31 02:59:49 +00001093 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001094 return;
1095 }
1096
Auke Kok9a799d72007-09-15 14:07:45 -07001097 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001098 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001099}
1100
Alexander Duyck84ea2592010-11-16 19:26:49 -08001101static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001102{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001103 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001104
1105 /* update next to alloc since we have filled the ring */
1106 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001107 /*
1108 * Force memory writes to complete before letting h/w
1109 * know there are new descriptors to fetch. (Only
1110 * applicable for weak-ordered memory model archs,
1111 * such as IA-64).
1112 */
1113 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001114 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001115}
1116
Alexander Duyckf990b792012-01-31 02:59:34 +00001117static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1118 struct ixgbe_rx_buffer *bi)
1119{
1120 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001121 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001122
Alexander Duyckf8003262012-03-03 02:35:52 +00001123 /* since we are recycling buffers we should seldom need to alloc */
1124 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001125 return true;
1126
Alexander Duyckf8003262012-03-03 02:35:52 +00001127 /* alloc new page for storage */
1128 if (likely(!page)) {
1129 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1130 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001131 if (unlikely(!page)) {
1132 rx_ring->rx_stats.alloc_rx_page_failed++;
1133 return false;
1134 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001135 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001136 }
1137
Alexander Duyckf8003262012-03-03 02:35:52 +00001138 /* map page for use */
1139 dma = dma_map_page(rx_ring->dev, page, 0,
1140 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001141
Alexander Duyckf8003262012-03-03 02:35:52 +00001142 /*
1143 * if mapping failed free memory back to system since
1144 * there isn't much point in holding memory we can't use
1145 */
1146 if (dma_mapping_error(rx_ring->dev, dma)) {
1147 put_page(page);
1148 bi->page = NULL;
1149
Alexander Duyckf990b792012-01-31 02:59:34 +00001150 rx_ring->rx_stats.alloc_rx_page_failed++;
1151 return false;
1152 }
1153
Alexander Duyckf8003262012-03-03 02:35:52 +00001154 bi->dma = dma;
1155 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1156
Alexander Duyckf990b792012-01-31 02:59:34 +00001157 return true;
1158}
1159
Auke Kok9a799d72007-09-15 14:07:45 -07001160/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001161 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001162 * @rx_ring: ring to place buffers on
1163 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001164 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001165void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001166{
Auke Kok9a799d72007-09-15 14:07:45 -07001167 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001168 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001169 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001170
Alexander Duyckf8003262012-03-03 02:35:52 +00001171 /* nothing to do */
1172 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001173 return;
1174
Alexander Duycke4f74022012-01-31 02:59:44 +00001175 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001176 bi = &rx_ring->rx_buffer_info[i];
1177 i -= rx_ring->count;
1178
Alexander Duyckf8003262012-03-03 02:35:52 +00001179 do {
1180 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001181 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001182
Alexander Duyckf8003262012-03-03 02:35:52 +00001183 /*
1184 * Refresh the desc even if buffer_addrs didn't change
1185 * because each write-back erases this info.
1186 */
1187 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001188
Alexander Duyckf990b792012-01-31 02:59:34 +00001189 rx_desc++;
1190 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001191 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001192 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001193 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001194 bi = rx_ring->rx_buffer_info;
1195 i -= rx_ring->count;
1196 }
1197
1198 /* clear the hdr_addr for the next_to_use descriptor */
1199 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001200
1201 cleaned_count--;
1202 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001203
Alexander Duyckf990b792012-01-31 02:59:34 +00001204 i += rx_ring->count;
1205
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001206 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001207 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001208}
1209
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001210/**
1211 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1212 * @data: pointer to the start of the headers
1213 * @max_len: total length of section to find headers in
1214 *
1215 * This function is meant to determine the length of headers that will
1216 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1217 * motivation of doing this is to only perform one pull for IPv4 TCP
1218 * packets so that we can do basic things like calculating the gso_size
1219 * based on the average data per packet.
1220 **/
1221static unsigned int ixgbe_get_headlen(unsigned char *data,
1222 unsigned int max_len)
1223{
1224 union {
1225 unsigned char *network;
1226 /* l2 headers */
1227 struct ethhdr *eth;
1228 struct vlan_hdr *vlan;
1229 /* l3 headers */
1230 struct iphdr *ipv4;
1231 } hdr;
1232 __be16 protocol;
1233 u8 nexthdr = 0; /* default to not TCP */
1234 u8 hlen;
1235
1236 /* this should never happen, but better safe than sorry */
1237 if (max_len < ETH_HLEN)
1238 return max_len;
1239
1240 /* initialize network frame pointer */
1241 hdr.network = data;
1242
1243 /* set first protocol and move network header forward */
1244 protocol = hdr.eth->h_proto;
1245 hdr.network += ETH_HLEN;
1246
1247 /* handle any vlan tag if present */
1248 if (protocol == __constant_htons(ETH_P_8021Q)) {
1249 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1250 return max_len;
1251
1252 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1253 hdr.network += VLAN_HLEN;
1254 }
1255
1256 /* handle L3 protocols */
1257 if (protocol == __constant_htons(ETH_P_IP)) {
1258 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1259 return max_len;
1260
1261 /* access ihl as a u8 to avoid unaligned access on ia64 */
1262 hlen = (hdr.network[0] & 0x0F) << 2;
1263
1264 /* verify hlen meets minimum size requirements */
1265 if (hlen < sizeof(struct iphdr))
1266 return hdr.network - data;
1267
1268 /* record next protocol */
1269 nexthdr = hdr.ipv4->protocol;
1270 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001271#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001272 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1273 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1274 return max_len;
1275 hdr.network += FCOE_HEADER_LEN;
1276#endif
1277 } else {
1278 return hdr.network - data;
1279 }
1280
1281 /* finally sort out TCP */
1282 if (nexthdr == IPPROTO_TCP) {
1283 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1284 return max_len;
1285
1286 /* access doff as a u8 to avoid unaligned access on ia64 */
1287 hlen = (hdr.network[12] & 0xF0) >> 2;
1288
1289 /* verify hlen meets minimum size requirements */
1290 if (hlen < sizeof(struct tcphdr))
1291 return hdr.network - data;
1292
1293 hdr.network += hlen;
1294 }
1295
1296 /*
1297 * If everything has gone correctly hdr.network should be the
1298 * data section of the packet and will be the end of the header.
1299 * If not then it probably represents the end of the last recognized
1300 * header.
1301 */
1302 if ((hdr.network - data) < max_len)
1303 return hdr.network - data;
1304 else
1305 return max_len;
1306}
1307
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001308static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1309 union ixgbe_adv_rx_desc *rx_desc,
1310 struct sk_buff *skb)
1311{
1312 __le32 rsc_enabled;
1313 u32 rsc_cnt;
1314
1315 if (!ring_is_rsc_enabled(rx_ring))
1316 return;
1317
1318 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1319 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1320
1321 /* If this is an RSC frame rsc_cnt should be non-zero */
1322 if (!rsc_enabled)
1323 return;
1324
1325 rsc_cnt = le32_to_cpu(rsc_enabled);
1326 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1327
1328 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001329}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001330
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001331static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1332 struct sk_buff *skb)
1333{
Alexander Duyckf8003262012-03-03 02:35:52 +00001334 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001335
1336 /* set gso_size to avoid messing up TCP MSS */
1337 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1338 IXGBE_CB(skb)->append_cnt);
1339}
1340
1341static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1342 struct sk_buff *skb)
1343{
1344 /* if append_cnt is 0 then frame is not RSC */
1345 if (!IXGBE_CB(skb)->append_cnt)
1346 return;
1347
1348 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1349 rx_ring->rx_stats.rsc_flush++;
1350
1351 ixgbe_set_rsc_gso_size(rx_ring, skb);
1352
1353 /* gso_size is computed using append_cnt so always clear it last */
1354 IXGBE_CB(skb)->append_cnt = 0;
1355}
1356
Alexander Duyck8a0da212012-01-31 02:59:49 +00001357/**
1358 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1359 * @rx_ring: rx descriptor ring packet is being transacted on
1360 * @rx_desc: pointer to the EOP Rx descriptor
1361 * @skb: pointer to current skb being populated
1362 *
1363 * This function checks the ring, descriptor, and packet information in
1364 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1365 * other fields within the skb.
1366 **/
1367static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1368 union ixgbe_adv_rx_desc *rx_desc,
1369 struct sk_buff *skb)
1370{
1371 ixgbe_update_rsc_stats(rx_ring, skb);
1372
1373 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1374
1375 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1376
1377 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1378 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1379 __vlan_hwaccel_put_tag(skb, vid);
1380 }
1381
1382 skb_record_rx_queue(skb, rx_ring->queue_index);
1383
1384 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1385}
1386
1387static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1388 struct sk_buff *skb)
1389{
1390 struct ixgbe_adapter *adapter = q_vector->adapter;
1391
1392 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1393 napi_gro_receive(&q_vector->napi, skb);
1394 else
1395 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001396}
1397
Alexander Duyckf8003262012-03-03 02:35:52 +00001398/**
1399 * ixgbe_is_non_eop - process handling of non-EOP buffers
1400 * @rx_ring: Rx ring being processed
1401 * @rx_desc: Rx descriptor for current buffer
1402 * @skb: Current socket buffer containing buffer in progress
1403 *
1404 * This function updates next to clean. If the buffer is an EOP buffer
1405 * this function exits returning false, otherwise it will place the
1406 * sk_buff in the next buffer to be chained and return true indicating
1407 * that this is in fact a non-EOP buffer.
1408 **/
1409static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1410 union ixgbe_adv_rx_desc *rx_desc,
1411 struct sk_buff *skb)
1412{
1413 u32 ntc = rx_ring->next_to_clean + 1;
1414
1415 /* fetch, update, and store next to clean */
1416 ntc = (ntc < rx_ring->count) ? ntc : 0;
1417 rx_ring->next_to_clean = ntc;
1418
1419 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1420
1421 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1422 return false;
1423
1424 /* append_cnt indicates packet is RSC, if so fetch nextp */
1425 if (IXGBE_CB(skb)->append_cnt) {
1426 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1427 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1428 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1429 }
1430
1431 /* place skb in next buffer to be received */
1432 rx_ring->rx_buffer_info[ntc].skb = skb;
1433 rx_ring->rx_stats.non_eop_descs++;
1434
1435 return true;
1436}
1437
1438/**
1439 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1440 * @rx_ring: rx descriptor ring packet is being transacted on
1441 * @rx_desc: pointer to the EOP Rx descriptor
1442 * @skb: pointer to current skb being fixed
1443 *
1444 * Check for corrupted packet headers caused by senders on the local L2
1445 * embedded NIC switch not setting up their Tx Descriptors right. These
1446 * should be very rare.
1447 *
1448 * Also address the case where we are pulling data in on pages only
1449 * and as such no data is present in the skb header.
1450 *
1451 * In addition if skb is not at least 60 bytes we need to pad it so that
1452 * it is large enough to qualify as a valid Ethernet frame.
1453 *
1454 * Returns true if an error was encountered and skb was freed.
1455 **/
1456static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1457 union ixgbe_adv_rx_desc *rx_desc,
1458 struct sk_buff *skb)
1459{
1460 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1461 struct net_device *netdev = rx_ring->netdev;
1462 unsigned char *va;
1463 unsigned int pull_len;
1464
1465 /* if the page was released unmap it, else just sync our portion */
1466 if (unlikely(IXGBE_CB(skb)->page_released)) {
1467 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1468 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1469 IXGBE_CB(skb)->page_released = false;
1470 } else {
1471 dma_sync_single_range_for_cpu(rx_ring->dev,
1472 IXGBE_CB(skb)->dma,
1473 frag->page_offset,
1474 ixgbe_rx_bufsz(rx_ring),
1475 DMA_FROM_DEVICE);
1476 }
1477 IXGBE_CB(skb)->dma = 0;
1478
1479 /* verify that the packet does not have any known errors */
1480 if (unlikely(ixgbe_test_staterr(rx_desc,
1481 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1482 !(netdev->features & NETIF_F_RXALL))) {
1483 dev_kfree_skb_any(skb);
1484 return true;
1485 }
1486
1487 /*
1488 * it is valid to use page_address instead of kmap since we are
1489 * working with pages allocated out of the lomem pool per
1490 * alloc_page(GFP_ATOMIC)
1491 */
1492 va = skb_frag_address(frag);
1493
1494 /*
1495 * we need the header to contain the greater of either ETH_HLEN or
1496 * 60 bytes if the skb->len is less than 60 for skb_pad.
1497 */
1498 pull_len = skb_frag_size(frag);
1499 if (pull_len > 256)
1500 pull_len = ixgbe_get_headlen(va, pull_len);
1501
1502 /* align pull length to size of long to optimize memcpy performance */
1503 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1504
1505 /* update all of the pointers */
1506 skb_frag_size_sub(frag, pull_len);
1507 frag->page_offset += pull_len;
1508 skb->data_len -= pull_len;
1509 skb->tail += pull_len;
1510
1511 /*
1512 * if we sucked the frag empty then we should free it,
1513 * if there are other frags here something is screwed up in hardware
1514 */
1515 if (skb_frag_size(frag) == 0) {
1516 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1517 skb_shinfo(skb)->nr_frags = 0;
1518 __skb_frag_unref(frag);
1519 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1520 }
1521
1522 /* if skb_pad returns an error the skb was freed */
1523 if (unlikely(skb->len < 60)) {
1524 int pad_len = 60 - skb->len;
1525
1526 if (skb_pad(skb, pad_len))
1527 return true;
1528 __skb_put(skb, pad_len);
1529 }
1530
1531 return false;
1532}
1533
1534/**
1535 * ixgbe_can_reuse_page - determine if we can reuse a page
1536 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1537 *
1538 * Returns true if page can be reused in another Rx buffer
1539 **/
1540static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1541{
1542 struct page *page = rx_buffer->page;
1543
1544 /* if we are only owner of page and it is local we can reuse it */
1545 return likely(page_count(page) == 1) &&
1546 likely(page_to_nid(page) == numa_node_id());
1547}
1548
1549/**
1550 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1551 * @rx_ring: rx descriptor ring to store buffers on
1552 * @old_buff: donor buffer to have page reused
1553 *
1554 * Syncronizes page for reuse by the adapter
1555 **/
1556static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1557 struct ixgbe_rx_buffer *old_buff)
1558{
1559 struct ixgbe_rx_buffer *new_buff;
1560 u16 nta = rx_ring->next_to_alloc;
1561 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1562
1563 new_buff = &rx_ring->rx_buffer_info[nta];
1564
1565 /* update, and store next to alloc */
1566 nta++;
1567 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1568
1569 /* transfer page from old buffer to new buffer */
1570 new_buff->page = old_buff->page;
1571 new_buff->dma = old_buff->dma;
1572
1573 /* flip page offset to other buffer and store to new_buff */
1574 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1575
1576 /* sync the buffer for use by the device */
1577 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1578 new_buff->page_offset, bufsz,
1579 DMA_FROM_DEVICE);
1580
1581 /* bump ref count on page before it is given to the stack */
1582 get_page(new_buff->page);
1583}
1584
1585/**
1586 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1587 * @rx_ring: rx descriptor ring to transact packets on
1588 * @rx_buffer: buffer containing page to add
1589 * @rx_desc: descriptor containing length of buffer written by hardware
1590 * @skb: sk_buff to place the data into
1591 *
1592 * This function is based on skb_add_rx_frag. I would have used that
1593 * function however it doesn't handle the truesize case correctly since we
1594 * are allocating more memory than might be used for a single receive.
1595 **/
1596static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1597 struct ixgbe_rx_buffer *rx_buffer,
1598 struct sk_buff *skb, int size)
1599{
1600 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1601 rx_buffer->page, rx_buffer->page_offset,
1602 size);
1603 skb->len += size;
1604 skb->data_len += size;
1605 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1606}
1607
1608/**
1609 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1610 * @q_vector: structure containing interrupt and ring information
1611 * @rx_ring: rx descriptor ring to transact packets on
1612 * @budget: Total limit on number of packets to process
1613 *
1614 * This function provides a "bounce buffer" approach to Rx interrupt
1615 * processing. The advantage to this is that on systems that have
1616 * expensive overhead for IOMMU access this provides a means of avoiding
1617 * it by maintaining the mapping of the page to the syste.
1618 *
1619 * Returns true if all work is completed without reaching budget
1620 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001621static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001622 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001623 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001624{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001625 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001626#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001627 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001628 int ddp_bytes = 0;
1629#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001630 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001631
Alexander Duyckf8003262012-03-03 02:35:52 +00001632 do {
1633 struct ixgbe_rx_buffer *rx_buffer;
1634 union ixgbe_adv_rx_desc *rx_desc;
1635 struct sk_buff *skb;
1636 struct page *page;
1637 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001638
Alexander Duyckf8003262012-03-03 02:35:52 +00001639 /* return some buffers to hardware, one at a time is too slow */
1640 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1641 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1642 cleaned_count = 0;
1643 }
Auke Kok9a799d72007-09-15 14:07:45 -07001644
Alexander Duyckf8003262012-03-03 02:35:52 +00001645 ntc = rx_ring->next_to_clean;
1646 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1647 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001648
Alexander Duyckf8003262012-03-03 02:35:52 +00001649 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1650 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001651
Alexander Duyckf8003262012-03-03 02:35:52 +00001652 /*
1653 * This memory barrier is needed to keep us from reading
1654 * any other fields out of the rx_desc until we know the
1655 * RXD_STAT_DD bit is set
1656 */
1657 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001658
Alexander Duyckf8003262012-03-03 02:35:52 +00001659 page = rx_buffer->page;
1660 prefetchw(page);
1661
1662 skb = rx_buffer->skb;
1663
1664 if (likely(!skb)) {
1665 void *page_addr = page_address(page) +
1666 rx_buffer->page_offset;
1667
1668 /* prefetch first cache line of first page */
1669 prefetch(page_addr);
1670#if L1_CACHE_BYTES < 128
1671 prefetch(page_addr + L1_CACHE_BYTES);
1672#endif
1673
1674 /* allocate a skb to store the frags */
1675 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1676 IXGBE_RX_HDR_SIZE);
1677 if (unlikely(!skb)) {
1678 rx_ring->rx_stats.alloc_rx_buff_failed++;
1679 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001680 }
1681
Alexander Duyckf8003262012-03-03 02:35:52 +00001682 /*
1683 * we will be copying header into skb->data in
1684 * pskb_may_pull so it is in our interest to prefetch
1685 * it now to avoid a possible cache miss
1686 */
1687 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001688
1689 /*
1690 * Delay unmapping of the first packet. It carries the
1691 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001692 * after the writeback. Only unmap it when EOP is
1693 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001694 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001695 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001696 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001697 /* we are reusing so sync this buffer for CPU use */
1698 dma_sync_single_range_for_cpu(rx_ring->dev,
1699 rx_buffer->dma,
1700 rx_buffer->page_offset,
1701 ixgbe_rx_bufsz(rx_ring),
1702 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001703 }
1704
Alexander Duyckf8003262012-03-03 02:35:52 +00001705 /* pull page into skb */
1706 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1707 le16_to_cpu(rx_desc->wb.upper.length));
1708
1709 if (ixgbe_can_reuse_page(rx_buffer)) {
1710 /* hand second half of page back to the ring */
1711 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1712 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1713 /* the page has been released from the ring */
1714 IXGBE_CB(skb)->page_released = true;
1715 } else {
1716 /* we are not reusing the buffer so unmap it */
1717 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1718 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001719 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001720 }
1721
Alexander Duyckf8003262012-03-03 02:35:52 +00001722 /* clear contents of buffer_info */
1723 rx_buffer->skb = NULL;
1724 rx_buffer->dma = 0;
1725 rx_buffer->page = NULL;
1726
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001727 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1728
Auke Kok9a799d72007-09-15 14:07:45 -07001729 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001730
Alexander Duyckf8003262012-03-03 02:35:52 +00001731 /* place incomplete frames back on ring for completion */
1732 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1733 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001734
Alexander Duyckf8003262012-03-03 02:35:52 +00001735 /* verify the packet layout is correct */
1736 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1737 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001738
1739 /* probably a little skewed due to removing CRC */
1740 total_rx_bytes += skb->len;
1741 total_rx_packets++;
1742
Alexander Duyck8a0da212012-01-31 02:59:49 +00001743 /* populate checksum, timestamp, VLAN, and protocol */
1744 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1745
Yi Zou332d4a72009-05-13 13:11:53 +00001746#ifdef IXGBE_FCOE
1747 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001748 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001749 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001750 if (!ddp_bytes) {
1751 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001752 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001753 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001754 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001755
Yi Zou332d4a72009-05-13 13:11:53 +00001756#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001757 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001758
Alexander Duyckf8003262012-03-03 02:35:52 +00001759 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001760 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001761 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001762
Yi Zou3d8fd382009-06-08 14:38:44 +00001763#ifdef IXGBE_FCOE
1764 /* include DDPed FCoE data */
1765 if (ddp_bytes > 0) {
1766 unsigned int mss;
1767
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001768 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001769 sizeof(struct fc_frame_header) -
1770 sizeof(struct fcoe_crc_eof);
1771 if (mss > 512)
1772 mss &= ~511;
1773 total_rx_bytes += ddp_bytes;
1774 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1775 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001776
Alexander Duyckf8003262012-03-03 02:35:52 +00001777#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001778 u64_stats_update_begin(&rx_ring->syncp);
1779 rx_ring->stats.packets += total_rx_packets;
1780 rx_ring->stats.bytes += total_rx_bytes;
1781 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001782 q_vector->rx.total_packets += total_rx_packets;
1783 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001784
Alexander Duyckf8003262012-03-03 02:35:52 +00001785 if (cleaned_count)
1786 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1787
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001788 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001789}
1790
Auke Kok9a799d72007-09-15 14:07:45 -07001791/**
1792 * ixgbe_configure_msix - Configure MSI-X hardware
1793 * @adapter: board private structure
1794 *
1795 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1796 * interrupts.
1797 **/
1798static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1799{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001800 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001801 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001802 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001803
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001804 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1805
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001806 /* Populate MSIX to EITR Select */
1807 if (adapter->num_vfs > 32) {
1808 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1809 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1810 }
1811
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001812 /*
1813 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001814 * corresponding register.
1815 */
1816 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001817 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001818 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001819
Alexander Duycka5579282012-02-08 07:50:04 +00001820 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001821 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001822
Alexander Duycka5579282012-02-08 07:50:04 +00001823 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001824 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001825
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001826 if (q_vector->tx.ring && !q_vector->rx.ring) {
1827 /* tx only vector */
1828 if (adapter->tx_itr_setting == 1)
1829 q_vector->itr = IXGBE_10K_ITR;
1830 else
1831 q_vector->itr = adapter->tx_itr_setting;
1832 } else {
1833 /* rx or rx/tx vector */
1834 if (adapter->rx_itr_setting == 1)
1835 q_vector->itr = IXGBE_20K_ITR;
1836 else
1837 q_vector->itr = adapter->rx_itr_setting;
1838 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001839
Alexander Duyckfe49f042009-06-04 16:00:09 +00001840 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001841 }
1842
Alexander Duyckbd508172010-11-16 19:27:03 -08001843 switch (adapter->hw.mac.type) {
1844 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001845 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001846 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001847 break;
1848 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001849 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001850 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001851 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001852 default:
1853 break;
1854 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001855 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001856
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001857 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001858 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001859 mask &= ~(IXGBE_EIMS_OTHER |
1860 IXGBE_EIMS_MAILBOX |
1861 IXGBE_EIMS_LSC);
1862
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001864}
1865
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001866enum latency_range {
1867 lowest_latency = 0,
1868 low_latency = 1,
1869 bulk_latency = 2,
1870 latency_invalid = 255
1871};
1872
1873/**
1874 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001875 * @q_vector: structure containing interrupt and ring information
1876 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001877 *
1878 * Stores a new ITR value based on packets and byte
1879 * counts during the last interrupt. The advantage of per interrupt
1880 * computation is faster updates and more accurate ITR for the current
1881 * traffic pattern. Constants in this function were computed
1882 * based on theoretical maximum wire speed and thresholds were set based
1883 * on testing data as well as attempting to minimize response time
1884 * while increasing bulk throughput.
1885 * this functionality is controlled by the InterruptThrottleRate module
1886 * parameter (see ixgbe_param.c)
1887 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001888static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1889 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001890{
Alexander Duyckbd198052011-06-11 01:45:08 +00001891 int bytes = ring_container->total_bytes;
1892 int packets = ring_container->total_packets;
1893 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001894 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001895 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001896
1897 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001898 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001899
1900 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001901 * 0-10MB/s lowest (100000 ints/s)
1902 * 10-20MB/s low (20000 ints/s)
1903 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001904 */
1905 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001906 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001907 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1908
1909 switch (itr_setting) {
1910 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001911 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001912 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001913 break;
1914 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001915 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001916 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001917 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001918 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001919 break;
1920 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001921 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001922 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001923 break;
1924 }
1925
Alexander Duyckbd198052011-06-11 01:45:08 +00001926 /* clear work counters since we have the values we need */
1927 ring_container->total_bytes = 0;
1928 ring_container->total_packets = 0;
1929
1930 /* write updated itr to ring container */
1931 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001932}
1933
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001934/**
1935 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001936 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001937 *
1938 * This function is made to be called by ethtool and by the driver
1939 * when it needs to update EITR registers at runtime. Hardware
1940 * specific quirks/differences are taken care of here.
1941 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001942void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001943{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001944 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001945 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001946 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001947 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001948
Alexander Duyckbd508172010-11-16 19:27:03 -08001949 switch (adapter->hw.mac.type) {
1950 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001951 /* must write high and low 16 bits to reset counter */
1952 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001953 break;
1954 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001955 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001956 /*
1957 * set the WDIS bit to not clear the timer bits and cause an
1958 * immediate assertion of the interrupt
1959 */
1960 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001961 break;
1962 default:
1963 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001964 }
1965 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1966}
1967
Alexander Duyckbd198052011-06-11 01:45:08 +00001968static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001969{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001970 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001971 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001972
Alexander Duyckbd198052011-06-11 01:45:08 +00001973 ixgbe_update_itr(q_vector, &q_vector->tx);
1974 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001975
Alexander Duyck08c88332011-06-11 01:45:03 +00001976 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001977
1978 switch (current_itr) {
1979 /* counts and packets in update_itr are dependent on these numbers */
1980 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001981 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001982 break;
1983 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001984 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001985 break;
1986 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001987 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001988 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001989 default:
1990 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001991 }
1992
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001993 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001994 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001995 new_itr = (10 * new_itr * q_vector->itr) /
1996 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001997
Alexander Duyckbd198052011-06-11 01:45:08 +00001998 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001999 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002000
2001 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002002 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002003}
2004
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002005/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002006 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002007 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002008 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002009static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002010{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002011 struct ixgbe_hw *hw = &adapter->hw;
2012 u32 eicr = adapter->interrupt_event;
2013
Alexander Duyckf0f97782011-04-22 04:08:09 +00002014 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002015 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002016
Alexander Duyckf0f97782011-04-22 04:08:09 +00002017 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2018 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2019 return;
2020
2021 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2022
Joe Perches7ca647b2010-09-07 21:35:40 +00002023 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002024 case IXGBE_DEV_ID_82599_T3_LOM:
2025 /*
2026 * Since the warning interrupt is for both ports
2027 * we don't have to check if:
2028 * - This interrupt wasn't for our port.
2029 * - We may have missed the interrupt so always have to
2030 * check if we got a LSC
2031 */
2032 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2033 !(eicr & IXGBE_EICR_LSC))
2034 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002035
Alexander Duyckf0f97782011-04-22 04:08:09 +00002036 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2037 u32 autoneg;
2038 bool link_up = false;
2039
Joe Perches7ca647b2010-09-07 21:35:40 +00002040 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2041
Alexander Duyckf0f97782011-04-22 04:08:09 +00002042 if (link_up)
2043 return;
2044 }
2045
2046 /* Check if this is not due to overtemp */
2047 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2048 return;
2049
2050 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002051 default:
2052 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2053 return;
2054 break;
2055 }
2056 e_crit(drv,
2057 "Network adapter has been stopped because it has over heated. "
2058 "Restart the computer. If the problem persists, "
2059 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002060
2061 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002062}
2063
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002064static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2065{
2066 struct ixgbe_hw *hw = &adapter->hw;
2067
2068 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2069 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002070 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002071 /* write to clear the interrupt */
2072 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2073 }
2074}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002075
Jacob Keller4f51bf72011-08-20 04:49:45 +00002076static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2077{
2078 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2079 return;
2080
2081 switch (adapter->hw.mac.type) {
2082 case ixgbe_mac_82599EB:
2083 /*
2084 * Need to check link state so complete overtemp check
2085 * on service task
2086 */
2087 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2088 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2089 adapter->interrupt_event = eicr;
2090 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2091 ixgbe_service_event_schedule(adapter);
2092 return;
2093 }
2094 return;
2095 case ixgbe_mac_X540:
2096 if (!(eicr & IXGBE_EICR_TS))
2097 return;
2098 break;
2099 default:
2100 return;
2101 }
2102
2103 e_crit(drv,
2104 "Network adapter has been stopped because it has over heated. "
2105 "Restart the computer. If the problem persists, "
2106 "power off the system and replace the adapter\n");
2107}
2108
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002109static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2110{
2111 struct ixgbe_hw *hw = &adapter->hw;
2112
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002113 if (eicr & IXGBE_EICR_GPI_SDP2) {
2114 /* Clear the interrupt */
2115 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002116 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2117 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2118 ixgbe_service_event_schedule(adapter);
2119 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002120 }
2121
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002122 if (eicr & IXGBE_EICR_GPI_SDP1) {
2123 /* Clear the interrupt */
2124 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002125 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2126 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2127 ixgbe_service_event_schedule(adapter);
2128 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002129 }
2130}
2131
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002132static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2133{
2134 struct ixgbe_hw *hw = &adapter->hw;
2135
2136 adapter->lsc_int++;
2137 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2138 adapter->link_check_timeout = jiffies;
2139 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2140 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002141 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002142 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002143 }
2144}
2145
Alexander Duyckfe49f042009-06-04 16:00:09 +00002146static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2147 u64 qmask)
2148{
2149 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002150 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002151
Alexander Duyckbd508172010-11-16 19:27:03 -08002152 switch (hw->mac.type) {
2153 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002154 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002155 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2156 break;
2157 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002158 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002159 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002160 if (mask)
2161 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002162 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002163 if (mask)
2164 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2165 break;
2166 default:
2167 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002168 }
2169 /* skip the flush */
2170}
2171
2172static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002173 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002174{
2175 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002176 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002177
Alexander Duyckbd508172010-11-16 19:27:03 -08002178 switch (hw->mac.type) {
2179 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002180 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002181 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2182 break;
2183 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002184 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002185 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002186 if (mask)
2187 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002188 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002189 if (mask)
2190 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2191 break;
2192 default:
2193 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002194 }
2195 /* skip the flush */
2196}
2197
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002198/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002199 * ixgbe_irq_enable - Enable default interrupt generation settings
2200 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002201 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002202static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2203 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002204{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002205 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002206
Alexander Duyck2c4af692011-07-15 07:29:55 +00002207 /* don't reenable LSC while waiting for link */
2208 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2209 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002210
Alexander Duyck2c4af692011-07-15 07:29:55 +00002211 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002212 switch (adapter->hw.mac.type) {
2213 case ixgbe_mac_82599EB:
2214 mask |= IXGBE_EIMS_GPI_SDP0;
2215 break;
2216 case ixgbe_mac_X540:
2217 mask |= IXGBE_EIMS_TS;
2218 break;
2219 default:
2220 break;
2221 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002222 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2223 mask |= IXGBE_EIMS_GPI_SDP1;
2224 switch (adapter->hw.mac.type) {
2225 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002226 mask |= IXGBE_EIMS_GPI_SDP1;
2227 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002228 case ixgbe_mac_X540:
2229 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002230 mask |= IXGBE_EIMS_MAILBOX;
2231 break;
2232 default:
2233 break;
2234 }
2235 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2236 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2237 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002238
Alexander Duyck2c4af692011-07-15 07:29:55 +00002239 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2240 if (queues)
2241 ixgbe_irq_enable_queues(adapter, ~0);
2242 if (flush)
2243 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002244}
2245
Alexander Duyck2c4af692011-07-15 07:29:55 +00002246static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002248 struct ixgbe_adapter *adapter = data;
2249 struct ixgbe_hw *hw = &adapter->hw;
2250 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002251
Alexander Duyck2c4af692011-07-15 07:29:55 +00002252 /*
2253 * Workaround for Silicon errata. Use clear-by-write instead
2254 * of clear-by-read. Reading with EICS will return the
2255 * interrupt causes without clearing, which later be done
2256 * with the write to EICR.
2257 */
2258 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2259 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002260
Alexander Duyck2c4af692011-07-15 07:29:55 +00002261 if (eicr & IXGBE_EICR_LSC)
2262 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263
Alexander Duyck2c4af692011-07-15 07:29:55 +00002264 if (eicr & IXGBE_EICR_MAILBOX)
2265 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002266
Alexander Duyck2c4af692011-07-15 07:29:55 +00002267 switch (hw->mac.type) {
2268 case ixgbe_mac_82599EB:
2269 case ixgbe_mac_X540:
2270 if (eicr & IXGBE_EICR_ECC)
2271 e_info(link, "Received unrecoverable ECC Err, please "
2272 "reboot\n");
2273 /* Handle Flow Director Full threshold interrupt */
2274 if (eicr & IXGBE_EICR_FLOW_DIR) {
2275 int reinit_count = 0;
2276 int i;
2277 for (i = 0; i < adapter->num_tx_queues; i++) {
2278 struct ixgbe_ring *ring = adapter->tx_ring[i];
2279 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2280 &ring->state))
2281 reinit_count++;
2282 }
2283 if (reinit_count) {
2284 /* no more flow director interrupts until after init */
2285 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2286 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2287 ixgbe_service_event_schedule(adapter);
2288 }
2289 }
2290 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002291 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002292 break;
2293 default:
2294 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002295 }
2296
Alexander Duyck2c4af692011-07-15 07:29:55 +00002297 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002298
Alexander Duyck2c4af692011-07-15 07:29:55 +00002299 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002300 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002301 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002302
Alexander Duyck2c4af692011-07-15 07:29:55 +00002303 return IRQ_HANDLED;
2304}
2305
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002306static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002307{
2308 struct ixgbe_q_vector *q_vector = data;
2309
Auke Kok9a799d72007-09-15 14:07:45 -07002310 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002311
2312 if (q_vector->rx.ring || q_vector->tx.ring)
2313 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002314
2315 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002316}
2317
Auke Kok9a799d72007-09-15 14:07:45 -07002318/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002319 * ixgbe_poll - NAPI Rx polling callback
2320 * @napi: structure for representing this polling device
2321 * @budget: how many packets driver is allowed to clean
2322 *
2323 * This function is used for legacy and MSI, NAPI mode
2324 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002325int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002326{
2327 struct ixgbe_q_vector *q_vector =
2328 container_of(napi, struct ixgbe_q_vector, napi);
2329 struct ixgbe_adapter *adapter = q_vector->adapter;
2330 struct ixgbe_ring *ring;
2331 int per_ring_budget;
2332 bool clean_complete = true;
2333
2334#ifdef CONFIG_IXGBE_DCA
2335 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2336 ixgbe_update_dca(q_vector);
2337#endif
2338
2339 ixgbe_for_each_ring(ring, q_vector->tx)
2340 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2341
2342 /* attempt to distribute budget to each queue fairly, but don't allow
2343 * the budget to go below 1 because we'll exit polling */
2344 if (q_vector->rx.count > 1)
2345 per_ring_budget = max(budget/q_vector->rx.count, 1);
2346 else
2347 per_ring_budget = budget;
2348
2349 ixgbe_for_each_ring(ring, q_vector->rx)
2350 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2351 per_ring_budget);
2352
2353 /* If all work not completed, return budget and keep polling */
2354 if (!clean_complete)
2355 return budget;
2356
2357 /* all work done, exit the polling mode */
2358 napi_complete(napi);
2359 if (adapter->rx_itr_setting & 1)
2360 ixgbe_set_itr(q_vector);
2361 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2362 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2363
2364 return 0;
2365}
2366
2367/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002368 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2369 * @adapter: board private structure
2370 *
2371 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2372 * interrupts from the kernel.
2373 **/
2374static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2375{
2376 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002377 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2378 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002379 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002380
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002381 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002382 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002383 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002384
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002385 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002386 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002387 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002388 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002389 } else if (q_vector->rx.ring) {
2390 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2391 "%s-%s-%d", netdev->name, "rx", ri++);
2392 } else if (q_vector->tx.ring) {
2393 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2394 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002395 } else {
2396 /* skip this unused q_vector */
2397 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002398 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002399 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2400 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002401 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002402 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002403 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002404 goto free_queue_irqs;
2405 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002406 /* If Flow Director is enabled, set interrupt affinity */
2407 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2408 /* assign the mask for this irq */
2409 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002410 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002411 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002412 }
2413
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002414 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002415 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002416 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002417 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002418 goto free_queue_irqs;
2419 }
2420
2421 return 0;
2422
2423free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002424 while (vector) {
2425 vector--;
2426 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2427 NULL);
2428 free_irq(adapter->msix_entries[vector].vector,
2429 adapter->q_vector[vector]);
2430 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002431 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2432 pci_disable_msix(adapter->pdev);
2433 kfree(adapter->msix_entries);
2434 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435 return err;
2436}
2437
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002438/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002439 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002440 * @irq: interrupt number
2441 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002442 **/
2443static irqreturn_t ixgbe_intr(int irq, void *data)
2444{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002445 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002446 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002447 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002448 u32 eicr;
2449
Don Skidmore54037502009-02-21 15:42:56 -08002450 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002451 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002452 * before the read of EICR.
2453 */
2454 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002456 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002457 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002458 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002459 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002460 /*
2461 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002462 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002463 * have disabled interrupts due to EIAM
2464 * finish the workaround of silicon errata on 82598. Unmask
2465 * the interrupt that we masked before the EICR read.
2466 */
2467 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2468 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002469 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002470 }
Auke Kok9a799d72007-09-15 14:07:45 -07002471
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002472 if (eicr & IXGBE_EICR_LSC)
2473 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002474
Alexander Duyckbd508172010-11-16 19:27:03 -08002475 switch (hw->mac.type) {
2476 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002477 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002478 /* Fall through */
2479 case ixgbe_mac_X540:
2480 if (eicr & IXGBE_EICR_ECC)
2481 e_info(link, "Received unrecoverable ECC err, please "
2482 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002483 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002484 break;
2485 default:
2486 break;
2487 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002488
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002489 ixgbe_check_fan_failure(adapter, eicr);
2490
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002491 /* would disable interrupts here but EIAM disabled it */
2492 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002493
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002494 /*
2495 * re-enable link(maybe) and non-queue interrupts, no flush.
2496 * ixgbe_poll will re-enable the queue interrupts
2497 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002498 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2499 ixgbe_irq_enable(adapter, false, false);
2500
Auke Kok9a799d72007-09-15 14:07:45 -07002501 return IRQ_HANDLED;
2502}
2503
2504/**
2505 * ixgbe_request_irq - initialize interrupts
2506 * @adapter: board private structure
2507 *
2508 * Attempts to configure interrupts using the best available
2509 * capabilities of the hardware and kernel.
2510 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002511static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002512{
2513 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002514 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002515
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002516 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002518 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002519 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002520 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002521 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002522 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002523 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002524
Alexander Duyckde88eee2012-02-08 07:49:59 +00002525 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002526 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002527
Auke Kok9a799d72007-09-15 14:07:45 -07002528 return err;
2529}
2530
2531static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2532{
Auke Kok9a799d72007-09-15 14:07:45 -07002533 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002534 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002535
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002536 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002537 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002538 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002539 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002540
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002541 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002542 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002543 if (!adapter->q_vector[i]->rx.ring &&
2544 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002545 continue;
2546
Alexander Duyck207867f2011-07-15 03:05:37 +00002547 /* clear the affinity_mask in the IRQ descriptor */
2548 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2549 NULL);
2550
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002551 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002552 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002554 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002555 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002556 }
2557}
2558
2559/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002560 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2561 * @adapter: board private structure
2562 **/
2563static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2564{
Alexander Duyckbd508172010-11-16 19:27:03 -08002565 switch (adapter->hw.mac.type) {
2566 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002568 break;
2569 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002570 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002571 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2572 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002573 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002574 break;
2575 default:
2576 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002577 }
2578 IXGBE_WRITE_FLUSH(&adapter->hw);
2579 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2580 int i;
2581 for (i = 0; i < adapter->num_msix_vectors; i++)
2582 synchronize_irq(adapter->msix_entries[i].vector);
2583 } else {
2584 synchronize_irq(adapter->pdev->irq);
2585 }
2586}
2587
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002588/**
Auke Kok9a799d72007-09-15 14:07:45 -07002589 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2590 *
2591 **/
2592static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2593{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002594 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002595
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002596 /* rx/tx vector */
2597 if (adapter->rx_itr_setting == 1)
2598 q_vector->itr = IXGBE_20K_ITR;
2599 else
2600 q_vector->itr = adapter->rx_itr_setting;
2601
2602 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002603
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002604 ixgbe_set_ivar(adapter, 0, 0, 0);
2605 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002606
Emil Tantilov396e7992010-07-01 20:05:12 +00002607 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002608}
2609
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002610/**
2611 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2612 * @adapter: board private structure
2613 * @ring: structure containing ring specific data
2614 *
2615 * Configure the Tx descriptor ring after a reset.
2616 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002617void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2618 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002619{
2620 struct ixgbe_hw *hw = &adapter->hw;
2621 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002622 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002623 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002624 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002625
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002626 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002627 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002628 IXGBE_WRITE_FLUSH(hw);
2629
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002630 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002631 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002632 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2633 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2634 ring->count * sizeof(union ixgbe_adv_tx_desc));
2635 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2636 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002637 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002638
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002639 /*
2640 * set WTHRESH to encourage burst writeback, it should not be set
2641 * higher than 1 when ITR is 0 as it could cause false TX hangs
2642 *
2643 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2644 * to or less than the number of on chip descriptors, which is
2645 * currently 40.
2646 */
Alexander Duycke954b372012-02-08 07:49:38 +00002647 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002648 txdctl |= (1 << 16); /* WTHRESH = 1 */
2649 else
2650 txdctl |= (8 << 16); /* WTHRESH = 8 */
2651
Alexander Duycke954b372012-02-08 07:49:38 +00002652 /*
2653 * Setting PTHRESH to 32 both improves performance
2654 * and avoids a TX hang with DFP enabled
2655 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002656 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2657 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002658
2659 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002660 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2661 adapter->atr_sample_rate) {
2662 ring->atr_sample_rate = adapter->atr_sample_rate;
2663 ring->atr_count = 0;
2664 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2665 } else {
2666 ring->atr_sample_rate = 0;
2667 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002668
John Fastabendc84d3242010-11-16 19:27:12 -08002669 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2670
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002671 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002672 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2673
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002674 netdev_tx_reset_queue(txring_txq(ring));
2675
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002676 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2677 if (hw->mac.type == ixgbe_mac_82598EB &&
2678 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2679 return;
2680
2681 /* poll to verify queue is enabled */
2682 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002683 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002684 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2685 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2686 if (!wait_loop)
2687 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002688}
2689
Alexander Duyck120ff942010-08-19 13:34:50 +00002690static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2691{
2692 struct ixgbe_hw *hw = &adapter->hw;
2693 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002694 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002695 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002696
2697 if (hw->mac.type == ixgbe_mac_82598EB)
2698 return;
2699
2700 /* disable the arbiter while setting MTQC */
2701 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2702 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2703 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2704
2705 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002706 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002707 case (IXGBE_FLAG_SRIOV_ENABLED):
2708 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2709 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2710 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002711 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002712 if (!tcs)
2713 reg = IXGBE_MTQC_64Q_1PB;
2714 else if (tcs <= 4)
2715 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2716 else
2717 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2718
2719 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2720
2721 /* Enable Security TX Buffer IFG for multiple pb */
2722 if (tcs) {
2723 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2724 reg |= IXGBE_SECTX_DCB;
2725 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2726 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002727 break;
2728 }
2729
2730 /* re-enable the arbiter */
2731 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2732 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2733}
2734
Auke Kok9a799d72007-09-15 14:07:45 -07002735/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002736 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002737 * @adapter: board private structure
2738 *
2739 * Configure the Tx unit of the MAC after a reset.
2740 **/
2741static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2742{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002743 struct ixgbe_hw *hw = &adapter->hw;
2744 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002745 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002746
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002747 ixgbe_setup_mtqc(adapter);
2748
2749 if (hw->mac.type != ixgbe_mac_82598EB) {
2750 /* DMATXCTL.EN must be before Tx queues are enabled */
2751 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2752 dmatxctl |= IXGBE_DMATXCTL_TE;
2753 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2754 }
2755
Auke Kok9a799d72007-09-15 14:07:45 -07002756 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002757 for (i = 0; i < adapter->num_tx_queues; i++)
2758 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002759}
2760
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002761#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002762
Yi Zoua6616b42009-08-06 13:05:23 +00002763static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002764 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002765{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002766 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002767 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002768
Alexander Duyckbd508172010-11-16 19:27:03 -08002769 switch (adapter->hw.mac.type) {
2770 case ixgbe_mac_82598EB: {
2771 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2772 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002773 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002774 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002775 break;
2776 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002777 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002778 default:
2779 break;
2780 }
2781
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002782 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002783
2784 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2785 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002786 if (adapter->num_vfs)
2787 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002788
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002789 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2790 IXGBE_SRRCTL_BSIZEHDR_MASK;
2791
Alexander Duyckf8003262012-03-03 02:35:52 +00002792#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2793 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002794#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002795 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002796#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002797 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002798
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002799 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002800}
2801
Alexander Duyck05abb122010-08-19 13:35:41 +00002802static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002803{
Alexander Duyck05abb122010-08-19 13:35:41 +00002804 struct ixgbe_hw *hw = &adapter->hw;
2805 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002806 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2807 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002808 u32 mrqc = 0, reta = 0;
2809 u32 rxcsum;
2810 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002811 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002812 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2813
2814 if (tcs)
2815 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002816
Alexander Duyck05abb122010-08-19 13:35:41 +00002817 /* Fill out hash function seeds */
2818 for (i = 0; i < 10; i++)
2819 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002820
Alexander Duyck05abb122010-08-19 13:35:41 +00002821 /* Fill out redirection table */
2822 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002823 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002824 j = 0;
2825 /* reta = 4-byte sliding window of
2826 * 0x00..(indices-1)(indices-1)00..etc. */
2827 reta = (reta << 8) | (j * 0x11);
2828 if ((i & 3) == 3)
2829 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2830 }
2831
2832 /* Disable indicating checksum in descriptor, enables RSS hash */
2833 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2834 rxcsum |= IXGBE_RXCSUM_PCSD;
2835 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2836
John Fastabend8b1c0b22011-05-03 02:26:48 +00002837 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2838 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002839 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002840 } else {
2841 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2842 | IXGBE_FLAG_SRIOV_ENABLED);
2843
2844 switch (mask) {
2845 case (IXGBE_FLAG_RSS_ENABLED):
2846 if (!tcs)
2847 mrqc = IXGBE_MRQC_RSSEN;
2848 else if (tcs <= 4)
2849 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2850 else
2851 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2852 break;
2853 case (IXGBE_FLAG_SRIOV_ENABLED):
2854 mrqc = IXGBE_MRQC_VMDQEN;
2855 break;
2856 default:
2857 break;
2858 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002859 }
2860
Alexander Duyck05abb122010-08-19 13:35:41 +00002861 /* Perform hash on these packet types */
2862 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2863 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2864 | IXGBE_MRQC_RSS_FIELD_IPV6
2865 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2866
Alexander Duyckef6afc02012-02-08 07:51:53 +00002867 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2868 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
2869 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2870 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2871
Alexander Duyck05abb122010-08-19 13:35:41 +00002872 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002873}
2874
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002875/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002876 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2877 * @adapter: address of board private structure
2878 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002879 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002880static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002881 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002882{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002883 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002884 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002885 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002886
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002887 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002888 return;
2889
Alexander Duyck73670962010-08-19 13:38:34 +00002890 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002891 rscctrl |= IXGBE_RSCCTL_RSCEN;
2892 /*
2893 * we must limit the number of descriptors so that the
2894 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002895 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002896 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002897#if (PAGE_SIZE <= 8192)
2898 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2899#elif (PAGE_SIZE <= 16384)
2900 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002901#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002902 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002903#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002904 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002905}
2906
Alexander Duyck9e10e042010-08-19 13:40:06 +00002907/**
2908 * ixgbe_set_uta - Set unicast filter table address
2909 * @adapter: board private structure
2910 *
2911 * The unicast table address is a register array of 32-bit registers.
2912 * The table is meant to be used in a way similar to how the MTA is used
2913 * however due to certain limitations in the hardware it is necessary to
2914 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2915 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2916 **/
2917static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2918{
2919 struct ixgbe_hw *hw = &adapter->hw;
2920 int i;
2921
2922 /* The UTA table only exists on 82599 hardware and newer */
2923 if (hw->mac.type < ixgbe_mac_82599EB)
2924 return;
2925
2926 /* we only need to do this if VMDq is enabled */
2927 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2928 return;
2929
2930 for (i = 0; i < 128; i++)
2931 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2932}
2933
2934#define IXGBE_MAX_RX_DESC_POLL 10
2935static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2936 struct ixgbe_ring *ring)
2937{
2938 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002939 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2940 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002941 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002942
2943 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2944 if (hw->mac.type == ixgbe_mac_82598EB &&
2945 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2946 return;
2947
2948 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002949 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002950 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2951 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2952
2953 if (!wait_loop) {
2954 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2955 "the polling period\n", reg_idx);
2956 }
2957}
2958
Yi Zou2d39d572011-01-06 14:29:56 +00002959void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2960 struct ixgbe_ring *ring)
2961{
2962 struct ixgbe_hw *hw = &adapter->hw;
2963 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2964 u32 rxdctl;
2965 u8 reg_idx = ring->reg_idx;
2966
2967 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2968 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2969
2970 /* write value back with RXDCTL.ENABLE bit cleared */
2971 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2972
2973 if (hw->mac.type == ixgbe_mac_82598EB &&
2974 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2975 return;
2976
2977 /* the hardware may take up to 100us to really disable the rx queue */
2978 do {
2979 udelay(10);
2980 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2981 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2982
2983 if (!wait_loop) {
2984 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2985 "the polling period\n", reg_idx);
2986 }
2987}
2988
Alexander Duyck84418e32010-08-19 13:40:54 +00002989void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2990 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002991{
2992 struct ixgbe_hw *hw = &adapter->hw;
2993 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002994 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002995 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002996
Alexander Duyck9e10e042010-08-19 13:40:06 +00002997 /* disable queue to avoid issues while updating state */
2998 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002999 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003000
Alexander Duyckacd37172010-08-19 13:36:05 +00003001 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3002 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3003 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3004 ring->count * sizeof(union ixgbe_adv_rx_desc));
3005 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3006 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003007 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003008
3009 ixgbe_configure_srrctl(adapter, ring);
3010 ixgbe_configure_rscctl(adapter, ring);
3011
Greg Rosee9f98072011-01-26 01:06:07 +00003012 /* If operating in IOV mode set RLPML for X540 */
3013 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3014 hw->mac.type == ixgbe_mac_X540) {
3015 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3016 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3017 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3018 }
3019
Alexander Duyck9e10e042010-08-19 13:40:06 +00003020 if (hw->mac.type == ixgbe_mac_82598EB) {
3021 /*
3022 * enable cache line friendly hardware writes:
3023 * PTHRESH=32 descriptors (half the internal cache),
3024 * this also removes ugly rx_no_buffer_count increment
3025 * HTHRESH=4 descriptors (to minimize latency on fetch)
3026 * WTHRESH=8 burst writeback up to two cache lines
3027 */
3028 rxdctl &= ~0x3FFFFF;
3029 rxdctl |= 0x080420;
3030 }
3031
3032 /* enable receive descriptor ring */
3033 rxdctl |= IXGBE_RXDCTL_ENABLE;
3034 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3035
3036 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003037 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003038}
3039
Alexander Duyck48654522010-08-19 13:36:27 +00003040static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3041{
3042 struct ixgbe_hw *hw = &adapter->hw;
3043 int p;
3044
3045 /* PSRTYPE must be initialized in non 82598 adapters */
3046 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003047 IXGBE_PSRTYPE_UDPHDR |
3048 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003049 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003050 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003051
3052 if (hw->mac.type == ixgbe_mac_82598EB)
3053 return;
3054
3055 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3056 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3057
3058 for (p = 0; p < adapter->num_rx_pools; p++)
3059 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3060 psrtype);
3061}
3062
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003063static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3064{
3065 struct ixgbe_hw *hw = &adapter->hw;
3066 u32 gcr_ext;
3067 u32 vt_reg_bits;
3068 u32 reg_offset, vf_shift;
3069 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003070 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003071
3072 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3073 return;
3074
3075 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3076 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3077 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3078 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3079
3080 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00003081 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003082
3083 /* Enable only the PF's pool for Tx/Rx */
3084 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3085 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3086 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3087 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3088 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3089
3090 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3091 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3092
3093 /*
3094 * Set up VF register offsets for selected VT Mode,
3095 * i.e. 32 or 64 VFs for SR-IOV
3096 */
3097 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3098 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3099 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3100 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3101
3102 /* enable Tx loopback for VF/PF communication */
3103 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003104 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00003105 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003106 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003107 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003108 /* For VFs that have spoof checking turned off */
3109 for (i = 0; i < adapter->num_vfs; i++) {
3110 if (!adapter->vfinfo[i].spoofchk_enabled)
3111 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3112 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003113}
3114
Alexander Duyck477de6e2010-08-19 13:38:11 +00003115static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003116{
Auke Kok9a799d72007-09-15 14:07:45 -07003117 struct ixgbe_hw *hw = &adapter->hw;
3118 struct net_device *netdev = adapter->netdev;
3119 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003120 struct ixgbe_ring *rx_ring;
3121 int i;
3122 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003123
Alexander Duyck477de6e2010-08-19 13:38:11 +00003124#ifdef IXGBE_FCOE
3125 /* adjust max frame to be able to do baby jumbo for FCoE */
3126 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3127 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3128 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3129
3130#endif /* IXGBE_FCOE */
3131 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3132 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3133 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3134 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3135
3136 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003137 }
3138
Alexander Duyck919e78a2011-08-26 09:52:38 +00003139 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3140 max_frame += VLAN_HLEN;
3141
Auke Kok9a799d72007-09-15 14:07:45 -07003142 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003143 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3144 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003145 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3146
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003147 /*
3148 * Setup the HW Rx Head and Tail Descriptor Pointers and
3149 * the Base and Length of the Rx Descriptor Ring
3150 */
Auke Kok9a799d72007-09-15 14:07:45 -07003151 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003152 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003153 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3154 set_ring_rsc_enabled(rx_ring);
3155 else
3156 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003157 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003158}
3159
Alexander Duyck73670962010-08-19 13:38:34 +00003160static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3161{
3162 struct ixgbe_hw *hw = &adapter->hw;
3163 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3164
3165 switch (hw->mac.type) {
3166 case ixgbe_mac_82598EB:
3167 /*
3168 * For VMDq support of different descriptor types or
3169 * buffer sizes through the use of multiple SRRCTL
3170 * registers, RDRXCTL.MVMEN must be set to 1
3171 *
3172 * also, the manual doesn't mention it clearly but DCA hints
3173 * will only use queue 0's tags unless this bit is set. Side
3174 * effects of setting this bit are only that SRRCTL must be
3175 * fully programmed [0..15]
3176 */
3177 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3178 break;
3179 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003180 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003181 /* Disable RSC for ACK packets */
3182 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3183 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3184 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3185 /* hardware requires some bits to be set by default */
3186 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3187 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3188 break;
3189 default:
3190 /* We should do nothing since we don't know this hardware */
3191 return;
3192 }
3193
3194 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3195}
3196
Alexander Duyck477de6e2010-08-19 13:38:11 +00003197/**
3198 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3199 * @adapter: board private structure
3200 *
3201 * Configure the Rx unit of the MAC after a reset.
3202 **/
3203static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3204{
3205 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003206 int i;
3207 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003208
3209 /* disable receives while setting up the descriptors */
3210 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3211 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3212
3213 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003214 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003215
Alexander Duyck9e10e042010-08-19 13:40:06 +00003216 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003217 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003218
Alexander Duyck9e10e042010-08-19 13:40:06 +00003219 ixgbe_set_uta(adapter);
3220
Alexander Duyck477de6e2010-08-19 13:38:11 +00003221 /* set_rx_buffer_len must be called before ring initialization */
3222 ixgbe_set_rx_buffer_len(adapter);
3223
3224 /*
3225 * Setup the HW Rx Head and Tail Descriptor Pointers and
3226 * the Base and Length of the Rx Descriptor Ring
3227 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003228 for (i = 0; i < adapter->num_rx_queues; i++)
3229 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003230
Alexander Duyck9e10e042010-08-19 13:40:06 +00003231 /* disable drop enable for 82598 parts */
3232 if (hw->mac.type == ixgbe_mac_82598EB)
3233 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3234
3235 /* enable all receives */
3236 rxctrl |= IXGBE_RXCTRL_RXEN;
3237 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003238}
3239
Jiri Pirko8e586132011-12-08 19:52:37 -05003240static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003241{
3242 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003243 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003244 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003245
3246 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003247 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003248 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003249
3250 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003251}
3252
Jiri Pirko8e586132011-12-08 19:52:37 -05003253static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003254{
3255 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003256 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003257 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003258
Auke Kok9a799d72007-09-15 14:07:45 -07003259 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003260 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003261 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003262
3263 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003264}
3265
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003266/**
3267 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3268 * @adapter: driver data
3269 */
3270static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3271{
3272 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003273 u32 vlnctrl;
3274
3275 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3276 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3277 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3278}
3279
3280/**
3281 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3282 * @adapter: driver data
3283 */
3284static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3285{
3286 struct ixgbe_hw *hw = &adapter->hw;
3287 u32 vlnctrl;
3288
3289 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3290 vlnctrl |= IXGBE_VLNCTRL_VFE;
3291 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3292 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3293}
3294
3295/**
3296 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3297 * @adapter: driver data
3298 */
3299static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3300{
3301 struct ixgbe_hw *hw = &adapter->hw;
3302 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003303 int i, j;
3304
3305 switch (hw->mac.type) {
3306 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003307 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3308 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003309 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3310 break;
3311 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003312 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003313 for (i = 0; i < adapter->num_rx_queues; i++) {
3314 j = adapter->rx_ring[i]->reg_idx;
3315 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3316 vlnctrl &= ~IXGBE_RXDCTL_VME;
3317 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3318 }
3319 break;
3320 default:
3321 break;
3322 }
3323}
3324
3325/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003326 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003327 * @adapter: driver data
3328 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003329static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003330{
3331 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003332 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003333 int i, j;
3334
3335 switch (hw->mac.type) {
3336 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003337 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3338 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003339 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3340 break;
3341 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003342 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003343 for (i = 0; i < adapter->num_rx_queues; i++) {
3344 j = adapter->rx_ring[i]->reg_idx;
3345 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3346 vlnctrl |= IXGBE_RXDCTL_VME;
3347 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3348 }
3349 break;
3350 default:
3351 break;
3352 }
3353}
3354
Auke Kok9a799d72007-09-15 14:07:45 -07003355static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3356{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003357 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003358
Jesse Grossf62bbb52010-10-20 13:56:10 +00003359 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3360
3361 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3362 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003363}
3364
3365/**
Alexander Duyck28500622010-06-15 09:25:48 +00003366 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3367 * @netdev: network interface device structure
3368 *
3369 * Writes unicast address list to the RAR table.
3370 * Returns: -ENOMEM on failure/insufficient address space
3371 * 0 on no addresses written
3372 * X on writing X addresses to the RAR table
3373 **/
3374static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3375{
3376 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3377 struct ixgbe_hw *hw = &adapter->hw;
3378 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003379 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003380 int count = 0;
3381
3382 /* return ENOMEM indicating insufficient memory for addresses */
3383 if (netdev_uc_count(netdev) > rar_entries)
3384 return -ENOMEM;
3385
3386 if (!netdev_uc_empty(netdev) && rar_entries) {
3387 struct netdev_hw_addr *ha;
3388 /* return error if we do not support writing to RAR table */
3389 if (!hw->mac.ops.set_rar)
3390 return -ENOMEM;
3391
3392 netdev_for_each_uc_addr(ha, netdev) {
3393 if (!rar_entries)
3394 break;
3395 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3396 vfn, IXGBE_RAH_AV);
3397 count++;
3398 }
3399 }
3400 /* write the addresses in reverse order to avoid write combining */
3401 for (; rar_entries > 0 ; rar_entries--)
3402 hw->mac.ops.clear_rar(hw, rar_entries);
3403
3404 return count;
3405}
3406
3407/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003408 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003409 * @netdev: network interface device structure
3410 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003411 * The set_rx_method entry point is called whenever the unicast/multicast
3412 * address list or the network interface flags are updated. This routine is
3413 * responsible for configuring the hardware for proper unicast, multicast and
3414 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003415 **/
Greg Rose7f870472010-01-09 02:25:29 +00003416void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003417{
3418 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3419 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003420 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3421 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003422
3423 /* Check for Promiscuous and All Multicast modes */
3424
3425 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3426
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003427 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003428 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003429 fctrl |= IXGBE_FCTRL_BAM;
3430 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3431 fctrl |= IXGBE_FCTRL_PMCF;
3432
Alexander Duyck28500622010-06-15 09:25:48 +00003433 /* clear the bits we are changing the status of */
3434 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3435
Auke Kok9a799d72007-09-15 14:07:45 -07003436 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003437 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003438 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003439 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003440 /* don't hardware filter vlans in promisc mode */
3441 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003442 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003443 if (netdev->flags & IFF_ALLMULTI) {
3444 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003445 vmolr |= IXGBE_VMOLR_MPE;
3446 } else {
3447 /*
3448 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003449 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003450 * that we can at least receive multicast traffic
3451 */
3452 hw->mac.ops.update_mc_addr_list(hw, netdev);
3453 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003454 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003455 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003456 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003457 /*
3458 * Write addresses to available RAR registers, if there is not
3459 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003460 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003461 */
3462 count = ixgbe_write_uc_addr_list(netdev);
3463 if (count < 0) {
3464 fctrl |= IXGBE_FCTRL_UPE;
3465 vmolr |= IXGBE_VMOLR_ROPE;
3466 }
3467 }
3468
3469 if (adapter->num_vfs) {
3470 ixgbe_restore_vf_multicasts(adapter);
3471 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3472 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3473 IXGBE_VMOLR_ROPE);
3474 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003475 }
3476
Ben Greear3f2d1c02012-03-08 08:28:41 +00003477 /* This is useful for sniffing bad packets. */
3478 if (adapter->netdev->features & NETIF_F_RXALL) {
3479 /* UPE and MPE will be handled by normal PROMISC logic
3480 * in e1000e_set_rx_mode */
3481 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3482 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3483 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3484
3485 fctrl &= ~(IXGBE_FCTRL_DPF);
3486 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3487 }
3488
Auke Kok9a799d72007-09-15 14:07:45 -07003489 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003490
3491 if (netdev->features & NETIF_F_HW_VLAN_RX)
3492 ixgbe_vlan_strip_enable(adapter);
3493 else
3494 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003495}
3496
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003497static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3498{
3499 int q_idx;
3500 struct ixgbe_q_vector *q_vector;
3501 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3502
3503 /* legacy and MSI only use one vector */
3504 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3505 q_vectors = 1;
3506
3507 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003508 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003509 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003510 }
3511}
3512
3513static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3514{
3515 int q_idx;
3516 struct ixgbe_q_vector *q_vector;
3517 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3518
3519 /* legacy and MSI only use one vector */
3520 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3521 q_vectors = 1;
3522
3523 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003524 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003525 napi_disable(&q_vector->napi);
3526 }
3527}
3528
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003529#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003530/*
3531 * ixgbe_configure_dcb - Configure DCB hardware
3532 * @adapter: ixgbe adapter struct
3533 *
3534 * This is called by the driver on open to configure the DCB hardware.
3535 * This is also called by the gennetlink interface when reconfiguring
3536 * the DCB state.
3537 */
3538static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3539{
3540 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003541 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003542
Alexander Duyck67ebd792010-08-19 13:34:04 +00003543 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3544 if (hw->mac.type == ixgbe_mac_82598EB)
3545 netif_set_gso_max_size(adapter->netdev, 65536);
3546 return;
3547 }
3548
3549 if (hw->mac.type == ixgbe_mac_82598EB)
3550 netif_set_gso_max_size(adapter->netdev, 32768);
3551
Alexander Duyck2f90b862008-11-20 20:52:10 -08003552
Alexander Duyck2f90b862008-11-20 20:52:10 -08003553 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003554 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003555
Alexander Duyck2f90b862008-11-20 20:52:10 -08003556 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003557
John Fastabendb1208182011-10-15 05:00:10 +00003558#ifdef IXGBE_FCOE
3559 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3560 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3561#endif
3562
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003563 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003564 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003565 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3566 DCB_TX_CONFIG);
3567 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3568 DCB_RX_CONFIG);
3569 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003570 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3571 ixgbe_dcb_hw_ets(&adapter->hw,
3572 adapter->ixgbe_ieee_ets,
3573 max_frame);
3574 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3575 adapter->ixgbe_ieee_pfc->pfc_en,
3576 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003577 }
John Fastabend8187cd42011-02-23 05:58:08 +00003578
3579 /* Enable RSS Hash per TC */
3580 if (hw->mac.type != ixgbe_mac_82598EB) {
3581 int i;
3582 u32 reg = 0;
3583
3584 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3585 u8 msb = 0;
3586 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3587
3588 while (cnt >>= 1)
3589 msb++;
3590
3591 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3592 }
3593 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3594 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003595}
John Fastabend9da712d2011-08-23 03:14:22 +00003596#endif
3597
3598/* Additional bittime to account for IXGBE framing */
3599#define IXGBE_ETH_FRAMING 20
3600
3601/*
3602 * ixgbe_hpbthresh - calculate high water mark for flow control
3603 *
3604 * @adapter: board private structure to calculate for
3605 * @pb - packet buffer to calculate
3606 */
3607static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3608{
3609 struct ixgbe_hw *hw = &adapter->hw;
3610 struct net_device *dev = adapter->netdev;
3611 int link, tc, kb, marker;
3612 u32 dv_id, rx_pba;
3613
3614 /* Calculate max LAN frame size */
3615 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3616
3617#ifdef IXGBE_FCOE
3618 /* FCoE traffic class uses FCOE jumbo frames */
3619 if (dev->features & NETIF_F_FCOE_MTU) {
3620 int fcoe_pb = 0;
3621
3622#ifdef CONFIG_IXGBE_DCB
3623 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003624
3625#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003626 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3627 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3628 }
3629#endif
3630
3631 /* Calculate delay value for device */
3632 switch (hw->mac.type) {
3633 case ixgbe_mac_X540:
3634 dv_id = IXGBE_DV_X540(link, tc);
3635 break;
3636 default:
3637 dv_id = IXGBE_DV(link, tc);
3638 break;
3639 }
3640
3641 /* Loopback switch introduces additional latency */
3642 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3643 dv_id += IXGBE_B2BT(tc);
3644
3645 /* Delay value is calculated in bit times convert to KB */
3646 kb = IXGBE_BT2KB(dv_id);
3647 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3648
3649 marker = rx_pba - kb;
3650
3651 /* It is possible that the packet buffer is not large enough
3652 * to provide required headroom. In this case throw an error
3653 * to user and a do the best we can.
3654 */
3655 if (marker < 0) {
3656 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3657 "headroom to support flow control."
3658 "Decrease MTU or number of traffic classes\n", pb);
3659 marker = tc + 1;
3660 }
3661
3662 return marker;
3663}
3664
3665/*
3666 * ixgbe_lpbthresh - calculate low water mark for for flow control
3667 *
3668 * @adapter: board private structure to calculate for
3669 * @pb - packet buffer to calculate
3670 */
3671static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3672{
3673 struct ixgbe_hw *hw = &adapter->hw;
3674 struct net_device *dev = adapter->netdev;
3675 int tc;
3676 u32 dv_id;
3677
3678 /* Calculate max LAN frame size */
3679 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3680
3681 /* Calculate delay value for device */
3682 switch (hw->mac.type) {
3683 case ixgbe_mac_X540:
3684 dv_id = IXGBE_LOW_DV_X540(tc);
3685 break;
3686 default:
3687 dv_id = IXGBE_LOW_DV(tc);
3688 break;
3689 }
3690
3691 /* Delay value is calculated in bit times convert to KB */
3692 return IXGBE_BT2KB(dv_id);
3693}
3694
3695/*
3696 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3697 */
3698static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3699{
3700 struct ixgbe_hw *hw = &adapter->hw;
3701 int num_tc = netdev_get_num_tc(adapter->netdev);
3702 int i;
3703
3704 if (!num_tc)
3705 num_tc = 1;
3706
3707 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3708
3709 for (i = 0; i < num_tc; i++) {
3710 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3711
3712 /* Low water marks must not be larger than high water marks */
3713 if (hw->fc.low_water > hw->fc.high_water[i])
3714 hw->fc.low_water = 0;
3715 }
3716}
John Fastabend80605c652011-05-02 12:34:10 +00003717
3718static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3719{
John Fastabend80605c652011-05-02 12:34:10 +00003720 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003721 int hdrm;
3722 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003723
3724 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3725 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003726 hdrm = 32 << adapter->fdir_pballoc;
3727 else
3728 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003729
Alexander Duyckf7e10272011-07-21 00:40:35 +00003730 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003731 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003732}
3733
Alexander Duycke4911d52011-05-11 07:18:52 +00003734static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3735{
3736 struct ixgbe_hw *hw = &adapter->hw;
3737 struct hlist_node *node, *node2;
3738 struct ixgbe_fdir_filter *filter;
3739
3740 spin_lock(&adapter->fdir_perfect_lock);
3741
3742 if (!hlist_empty(&adapter->fdir_filter_list))
3743 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3744
3745 hlist_for_each_entry_safe(filter, node, node2,
3746 &adapter->fdir_filter_list, fdir_node) {
3747 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003748 &filter->filter,
3749 filter->sw_idx,
3750 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3751 IXGBE_FDIR_DROP_QUEUE :
3752 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003753 }
3754
3755 spin_unlock(&adapter->fdir_perfect_lock);
3756}
3757
Auke Kok9a799d72007-09-15 14:07:45 -07003758static void ixgbe_configure(struct ixgbe_adapter *adapter)
3759{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003760 struct ixgbe_hw *hw = &adapter->hw;
3761
John Fastabend80605c652011-05-02 12:34:10 +00003762 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003763#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003764 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003765#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003766
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003767 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003768 ixgbe_restore_vlan(adapter);
3769
Yi Zoueacd73f2009-05-13 13:11:06 +00003770#ifdef IXGBE_FCOE
3771 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3772 ixgbe_configure_fcoe(adapter);
3773
3774#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003775
3776 switch (hw->mac.type) {
3777 case ixgbe_mac_82599EB:
3778 case ixgbe_mac_X540:
3779 hw->mac.ops.disable_rx_buff(hw);
3780 break;
3781 default:
3782 break;
3783 }
3784
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003785 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003786 ixgbe_init_fdir_signature_82599(&adapter->hw,
3787 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003788 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3789 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3790 adapter->fdir_pballoc);
3791 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003792 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003793
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003794 switch (hw->mac.type) {
3795 case ixgbe_mac_82599EB:
3796 case ixgbe_mac_X540:
3797 hw->mac.ops.enable_rx_buff(hw);
3798 break;
3799 default:
3800 break;
3801 }
3802
Alexander Duyck933d41f2010-09-07 21:34:29 +00003803 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003804
Auke Kok9a799d72007-09-15 14:07:45 -07003805 ixgbe_configure_tx(adapter);
3806 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003807}
3808
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003809static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3810{
3811 switch (hw->phy.type) {
3812 case ixgbe_phy_sfp_avago:
3813 case ixgbe_phy_sfp_ftl:
3814 case ixgbe_phy_sfp_intel:
3815 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003816 case ixgbe_phy_sfp_passive_tyco:
3817 case ixgbe_phy_sfp_passive_unknown:
3818 case ixgbe_phy_sfp_active_unknown:
3819 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003820 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003821 case ixgbe_phy_nl:
3822 if (hw->mac.type == ixgbe_mac_82598EB)
3823 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003824 default:
3825 return false;
3826 }
3827}
3828
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003829/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003830 * ixgbe_sfp_link_config - set up SFP+ link
3831 * @adapter: pointer to private adapter struct
3832 **/
3833static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3834{
Alexander Duyck70864002011-04-27 09:13:56 +00003835 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003836 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003837 * is that an SFP was inserted/removed after the reset
3838 * but before SFP detection was enabled. As such the best
3839 * solution is to just start searching as soon as we start
3840 */
3841 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3842 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003843
Alexander Duyck70864002011-04-27 09:13:56 +00003844 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003845}
3846
3847/**
3848 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003849 * @hw: pointer to private hardware struct
3850 *
3851 * Returns 0 on success, negative on failure
3852 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003853static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003854{
3855 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003856 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003857 u32 ret = IXGBE_ERR_LINK_SETUP;
3858
3859 if (hw->mac.ops.check_link)
3860 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3861
3862 if (ret)
3863 goto link_cfg_out;
3864
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003865 autoneg = hw->phy.autoneg_advertised;
3866 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003867 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3868 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003869 if (ret)
3870 goto link_cfg_out;
3871
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003872 if (hw->mac.ops.setup_link)
3873 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003874link_cfg_out:
3875 return ret;
3876}
3877
Alexander Duycka34bcff2010-08-19 13:39:20 +00003878static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003879{
Auke Kok9a799d72007-09-15 14:07:45 -07003880 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003881 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003882
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003883 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003884 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3885 IXGBE_GPIE_OCD;
3886 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003887 /*
3888 * use EIAM to auto-mask when MSI-X interrupt is asserted
3889 * this saves a register write for every interrupt
3890 */
3891 switch (hw->mac.type) {
3892 case ixgbe_mac_82598EB:
3893 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3894 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003895 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003896 case ixgbe_mac_X540:
3897 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003898 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3899 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3900 break;
3901 }
3902 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003903 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3904 * specifically only auto mask tx and rx interrupts */
3905 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003906 }
3907
Alexander Duycka34bcff2010-08-19 13:39:20 +00003908 /* XXX: to interrupt immediately for EICS writes, enable this */
3909 /* gpie |= IXGBE_GPIE_EIMEN; */
3910
3911 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3912 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3913 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003914 }
3915
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003916 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003917 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3918 switch (adapter->hw.mac.type) {
3919 case ixgbe_mac_82599EB:
3920 gpie |= IXGBE_SDP0_GPIEN;
3921 break;
3922 case ixgbe_mac_X540:
3923 gpie |= IXGBE_EIMS_TS;
3924 break;
3925 default:
3926 break;
3927 }
3928 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003929
Alexander Duycka34bcff2010-08-19 13:39:20 +00003930 /* Enable fan failure interrupt */
3931 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003932 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003933
Don Skidmore2698b202011-04-13 07:01:52 +00003934 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003935 gpie |= IXGBE_SDP1_GPIEN;
3936 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003937 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003938
3939 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3940}
3941
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003942static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003943{
3944 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003945 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003946 u32 ctrl_ext;
3947
3948 ixgbe_get_hw_control(adapter);
3949 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003950
Auke Kok9a799d72007-09-15 14:07:45 -07003951 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3952 ixgbe_configure_msix(adapter);
3953 else
3954 ixgbe_configure_msi_and_legacy(adapter);
3955
Don Skidmorec6ecf392010-12-03 03:31:51 +00003956 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3957 if (hw->mac.ops.enable_tx_laser &&
3958 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003959 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003960 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003961 hw->mac.ops.enable_tx_laser(hw);
3962
Auke Kok9a799d72007-09-15 14:07:45 -07003963 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003964 ixgbe_napi_enable_all(adapter);
3965
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003966 if (ixgbe_is_sfp(hw)) {
3967 ixgbe_sfp_link_config(adapter);
3968 } else {
3969 err = ixgbe_non_sfp_link_config(hw);
3970 if (err)
3971 e_err(probe, "link_config FAILED %d\n", err);
3972 }
3973
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003974 /* clear any pending interrupts, may auto mask */
3975 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003976 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003977
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003978 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003979 * If this adapter has a fan, check to see if we had a failure
3980 * before we enabled the interrupt.
3981 */
3982 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3983 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3984 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003985 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003986 }
3987
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003988 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003989 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003990
Auke Kok9a799d72007-09-15 14:07:45 -07003991 /* bring the link up in the watchdog, this could race with our first
3992 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003993 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3994 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003995 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003996
3997 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3998 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3999 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4000 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004001}
4002
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004003void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4004{
4005 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004006 /* put off any impending NetWatchDogTimeout */
4007 adapter->netdev->trans_start = jiffies;
4008
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004009 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004010 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004011 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004012 /*
4013 * If SR-IOV enabled then wait a bit before bringing the adapter
4014 * back up to give the VFs time to respond to the reset. The
4015 * two second wait is based upon the watchdog timer cycle in
4016 * the VF driver.
4017 */
4018 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4019 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004020 ixgbe_up(adapter);
4021 clear_bit(__IXGBE_RESETTING, &adapter->state);
4022}
4023
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004024void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004025{
4026 /* hardware has been reset, we need to reload some things */
4027 ixgbe_configure(adapter);
4028
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004029 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004030}
4031
4032void ixgbe_reset(struct ixgbe_adapter *adapter)
4033{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004034 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004035 int err;
4036
Alexander Duyck70864002011-04-27 09:13:56 +00004037 /* lock SFP init bit to prevent race conditions with the watchdog */
4038 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4039 usleep_range(1000, 2000);
4040
4041 /* clear all SFP and link config related flags while holding SFP_INIT */
4042 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4043 IXGBE_FLAG2_SFP_NEEDS_RESET);
4044 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4045
Don Skidmore8ca783a2009-05-26 20:40:47 -07004046 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004047 switch (err) {
4048 case 0:
4049 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004050 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004051 break;
4052 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004053 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004054 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004055 case IXGBE_ERR_EEPROM_VERSION:
4056 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004057 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004058 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004059 "your hardware. If you are experiencing problems "
4060 "please contact your Intel or hardware "
4061 "representative who provided you with this "
4062 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004063 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004064 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004065 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004066 }
Auke Kok9a799d72007-09-15 14:07:45 -07004067
Alexander Duyck70864002011-04-27 09:13:56 +00004068 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4069
Auke Kok9a799d72007-09-15 14:07:45 -07004070 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004071 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4072 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004073}
4074
Auke Kok9a799d72007-09-15 14:07:45 -07004075/**
Alexander Duyckf8003262012-03-03 02:35:52 +00004076 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
4077 * @rx_ring: ring to setup
4078 *
4079 * On many IA platforms the L1 cache has a critical stride of 4K, this
4080 * results in each receive buffer starting in the same cache set. To help
4081 * reduce the pressure on this cache set we can interleave the offsets so
4082 * that only every other buffer will be in the same cache set.
4083 **/
4084static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4085{
4086 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4087 u16 i;
4088
4089 for (i = 0; i < rx_ring->count; i += 2) {
4090 rx_buffer[0].page_offset = 0;
4091 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4092 rx_buffer = &rx_buffer[2];
4093 }
4094}
4095
4096/**
Auke Kok9a799d72007-09-15 14:07:45 -07004097 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004098 * @rx_ring: ring to free buffers from
4099 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004100static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004101{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004102 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004103 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004104 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004105
Alexander Duyck84418e32010-08-19 13:40:54 +00004106 /* ring already cleared, nothing to do */
4107 if (!rx_ring->rx_buffer_info)
4108 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004109
Alexander Duyck84418e32010-08-19 13:40:54 +00004110 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004111 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004112 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004113
Alexander Duyckf8003262012-03-03 02:35:52 +00004114 rx_buffer = &rx_ring->rx_buffer_info[i];
4115 if (rx_buffer->skb) {
4116 struct sk_buff *skb = rx_buffer->skb;
4117 if (IXGBE_CB(skb)->page_released) {
4118 dma_unmap_page(dev,
4119 IXGBE_CB(skb)->dma,
4120 ixgbe_rx_bufsz(rx_ring),
4121 DMA_FROM_DEVICE);
4122 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004123 }
4124 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004125 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004126 rx_buffer->skb = NULL;
4127 if (rx_buffer->dma)
4128 dma_unmap_page(dev, rx_buffer->dma,
4129 ixgbe_rx_pg_size(rx_ring),
4130 DMA_FROM_DEVICE);
4131 rx_buffer->dma = 0;
4132 if (rx_buffer->page)
4133 put_page(rx_buffer->page);
4134 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004135 }
4136
4137 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4138 memset(rx_ring->rx_buffer_info, 0, size);
4139
Alexander Duyckf8003262012-03-03 02:35:52 +00004140 ixgbe_init_rx_page_offset(rx_ring);
4141
Auke Kok9a799d72007-09-15 14:07:45 -07004142 /* Zero out the descriptor ring */
4143 memset(rx_ring->desc, 0, rx_ring->size);
4144
Alexander Duyckf8003262012-03-03 02:35:52 +00004145 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004146 rx_ring->next_to_clean = 0;
4147 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004148}
4149
4150/**
4151 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004152 * @tx_ring: ring to be cleaned
4153 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004154static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004155{
4156 struct ixgbe_tx_buffer *tx_buffer_info;
4157 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004158 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004159
Alexander Duyck84418e32010-08-19 13:40:54 +00004160 /* ring already cleared, nothing to do */
4161 if (!tx_ring->tx_buffer_info)
4162 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004163
Alexander Duyck84418e32010-08-19 13:40:54 +00004164 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004165 for (i = 0; i < tx_ring->count; i++) {
4166 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004167 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004168 }
4169
4170 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4171 memset(tx_ring->tx_buffer_info, 0, size);
4172
4173 /* Zero out the descriptor ring */
4174 memset(tx_ring->desc, 0, tx_ring->size);
4175
4176 tx_ring->next_to_use = 0;
4177 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004178}
4179
4180/**
Auke Kok9a799d72007-09-15 14:07:45 -07004181 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4182 * @adapter: board private structure
4183 **/
4184static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4185{
4186 int i;
4187
4188 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004189 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004190}
4191
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004192/**
4193 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4194 * @adapter: board private structure
4195 **/
4196static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4197{
4198 int i;
4199
4200 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004201 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004202}
4203
Alexander Duycke4911d52011-05-11 07:18:52 +00004204static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4205{
4206 struct hlist_node *node, *node2;
4207 struct ixgbe_fdir_filter *filter;
4208
4209 spin_lock(&adapter->fdir_perfect_lock);
4210
4211 hlist_for_each_entry_safe(filter, node, node2,
4212 &adapter->fdir_filter_list, fdir_node) {
4213 hlist_del(&filter->fdir_node);
4214 kfree(filter);
4215 }
4216 adapter->fdir_filter_count = 0;
4217
4218 spin_unlock(&adapter->fdir_perfect_lock);
4219}
4220
Auke Kok9a799d72007-09-15 14:07:45 -07004221void ixgbe_down(struct ixgbe_adapter *adapter)
4222{
4223 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004224 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004225 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004226 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004227
4228 /* signal that we are down to the interrupt handler */
4229 set_bit(__IXGBE_DOWN, &adapter->state);
4230
4231 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004232 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4233 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004234
Yi Zou2d39d572011-01-06 14:29:56 +00004235 /* disable all enabled rx queues */
4236 for (i = 0; i < adapter->num_rx_queues; i++)
4237 /* this call also flushes the previous write */
4238 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4239
Don Skidmore032b4322011-03-18 09:32:53 +00004240 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004241
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004242 netif_tx_stop_all_queues(netdev);
4243
Alexander Duyck70864002011-04-27 09:13:56 +00004244 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004245 netif_carrier_off(netdev);
4246 netif_tx_disable(netdev);
4247
4248 ixgbe_irq_disable(adapter);
4249
4250 ixgbe_napi_disable_all(adapter);
4251
Alexander Duyckd034acf2011-04-27 09:25:34 +00004252 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4253 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004254 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4255
4256 del_timer_sync(&adapter->service_timer);
4257
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004258 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004259 /* Clear EITR Select mapping */
4260 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4261
4262 /* Mark all the VFs as inactive */
4263 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004264 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004265
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004266 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004267 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004268
Auke Kok9a799d72007-09-15 14:07:45 -07004269 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004270 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004271 }
4272
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004273 /* disable transmits in the hardware now that interrupts are off */
4274 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004275 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004276 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004277 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004278
4279 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004280 switch (hw->mac.type) {
4281 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004282 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004283 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004284 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4285 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004286 break;
4287 default:
4288 break;
4289 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004290
Paul Larson6f4a0e42008-06-24 17:00:56 -07004291 if (!pci_channel_offline(adapter->pdev))
4292 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004293
4294 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4295 if (hw->mac.ops.disable_tx_laser &&
4296 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004297 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004298 (hw->mac.type == ixgbe_mac_82599EB))))
4299 hw->mac.ops.disable_tx_laser(hw);
4300
Auke Kok9a799d72007-09-15 14:07:45 -07004301 ixgbe_clean_all_tx_rings(adapter);
4302 ixgbe_clean_all_rx_rings(adapter);
4303
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004304#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004305 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004306 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004307#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004308}
4309
Auke Kok9a799d72007-09-15 14:07:45 -07004310/**
Auke Kok9a799d72007-09-15 14:07:45 -07004311 * ixgbe_tx_timeout - Respond to a Tx Hang
4312 * @netdev: network interface device structure
4313 **/
4314static void ixgbe_tx_timeout(struct net_device *netdev)
4315{
4316 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4317
4318 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004319 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004320}
4321
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004322/**
Auke Kok9a799d72007-09-15 14:07:45 -07004323 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4324 * @adapter: board private structure to initialize
4325 *
4326 * ixgbe_sw_init initializes the Adapter private data structure.
4327 * Fields are initialized based on PCI device information and
4328 * OS network device settings (MTU size).
4329 **/
4330static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4331{
4332 struct ixgbe_hw *hw = &adapter->hw;
4333 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004334 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004335#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004336 int j;
4337 struct tc_configuration *tc;
4338#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004339
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004340 /* PCI config space info */
4341
4342 hw->vendor_id = pdev->vendor;
4343 hw->device_id = pdev->device;
4344 hw->revision_id = pdev->revision;
4345 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4346 hw->subsystem_device_id = pdev->subsystem_device;
4347
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004348 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004349 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004350 adapter->ring_feature[RING_F_RSS].indices = rss;
4351 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08004352 switch (hw->mac.type) {
4353 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004354 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4355 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004356 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004357 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004358 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004359 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4360 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004361 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004362 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4363 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004364 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4365 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004366 /* Flow Director hash filters enabled */
4367 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4368 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004369 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00004370 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004371 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004372#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004373 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4374 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4375 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00004376#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004377 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004378 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004379#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004380#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004381 break;
4382 default:
4383 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004384 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004385
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004386 /* n-tuple support exists, always init our spinlock */
4387 spin_lock_init(&adapter->fdir_perfect_lock);
4388
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004389#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004390 switch (hw->mac.type) {
4391 case ixgbe_mac_X540:
4392 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4393 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4394 break;
4395 default:
4396 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4397 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4398 break;
4399 }
4400
Alexander Duyck2f90b862008-11-20 20:52:10 -08004401 /* Configure DCB traffic classes */
4402 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4403 tc = &adapter->dcb_cfg.tc_config[j];
4404 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4405 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4406 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4407 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4408 tc->dcb_pfc = pfc_disabled;
4409 }
John Fastabend4de2a022011-09-27 03:52:01 +00004410
4411 /* Initialize default user to priority mapping, UPx->TC0 */
4412 tc = &adapter->dcb_cfg.tc_config[0];
4413 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4414 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4415
Alexander Duyck2f90b862008-11-20 20:52:10 -08004416 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4417 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004418 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004419 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004420 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004421 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00004422 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004423
4424#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004425
4426 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004427 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004428 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004429#ifdef CONFIG_DCB
4430 adapter->last_lfc_mode = hw->fc.current_mode;
4431#endif
John Fastabend9da712d2011-08-23 03:14:22 +00004432 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004433 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4434 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004435 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004436
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004437 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004438 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004439 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004440
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004441 /* set default ring sizes */
4442 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4443 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4444
Alexander Duyckbd198052011-06-11 01:45:08 +00004445 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004446 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004447
Auke Kok9a799d72007-09-15 14:07:45 -07004448 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004449 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004450 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004451 return -EIO;
4452 }
4453
Auke Kok9a799d72007-09-15 14:07:45 -07004454 set_bit(__IXGBE_DOWN, &adapter->state);
4455
4456 return 0;
4457}
4458
4459/**
4460 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004461 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004462 *
4463 * Return 0 on success, negative on failure
4464 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004465int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004466{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004467 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004468 int orig_node = dev_to_node(dev);
4469 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004470 int size;
4471
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004472 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004473
4474 if (tx_ring->q_vector)
4475 numa_node = tx_ring->q_vector->numa_node;
4476
4477 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004478 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004479 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004480 if (!tx_ring->tx_buffer_info)
4481 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004482
4483 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004484 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004485 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004486
Alexander Duyckde88eee2012-02-08 07:49:59 +00004487 set_dev_node(dev, numa_node);
4488 tx_ring->desc = dma_alloc_coherent(dev,
4489 tx_ring->size,
4490 &tx_ring->dma,
4491 GFP_KERNEL);
4492 set_dev_node(dev, orig_node);
4493 if (!tx_ring->desc)
4494 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4495 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004496 if (!tx_ring->desc)
4497 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004498
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004499 tx_ring->next_to_use = 0;
4500 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004501 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004502
4503err:
4504 vfree(tx_ring->tx_buffer_info);
4505 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004506 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004507 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004508}
4509
4510/**
Alexander Duyck69888672008-09-11 20:05:39 -07004511 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4512 * @adapter: board private structure
4513 *
4514 * If this function returns with an error, then it's possible one or
4515 * more of the rings is populated (while the rest are not). It is the
4516 * callers duty to clean those orphaned rings.
4517 *
4518 * Return 0 on success, negative on failure
4519 **/
4520static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4521{
4522 int i, err = 0;
4523
4524 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004525 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004526 if (!err)
4527 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00004528 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07004529 break;
4530 }
4531
4532 return err;
4533}
4534
4535/**
Auke Kok9a799d72007-09-15 14:07:45 -07004536 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004537 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004538 *
4539 * Returns 0 on success, negative on failure
4540 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004541int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004542{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004543 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004544 int orig_node = dev_to_node(dev);
4545 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004546 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004547
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004548 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004549
4550 if (rx_ring->q_vector)
4551 numa_node = rx_ring->q_vector->numa_node;
4552
4553 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004554 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004555 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004556 if (!rx_ring->rx_buffer_info)
4557 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004558
Auke Kok9a799d72007-09-15 14:07:45 -07004559 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004560 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4561 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004562
Alexander Duyckde88eee2012-02-08 07:49:59 +00004563 set_dev_node(dev, numa_node);
4564 rx_ring->desc = dma_alloc_coherent(dev,
4565 rx_ring->size,
4566 &rx_ring->dma,
4567 GFP_KERNEL);
4568 set_dev_node(dev, orig_node);
4569 if (!rx_ring->desc)
4570 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4571 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004572 if (!rx_ring->desc)
4573 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004574
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004575 rx_ring->next_to_clean = 0;
4576 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004577
Alexander Duyckf8003262012-03-03 02:35:52 +00004578 ixgbe_init_rx_page_offset(rx_ring);
4579
Auke Kok9a799d72007-09-15 14:07:45 -07004580 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004581err:
4582 vfree(rx_ring->rx_buffer_info);
4583 rx_ring->rx_buffer_info = NULL;
4584 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004585 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004586}
4587
4588/**
Alexander Duyck69888672008-09-11 20:05:39 -07004589 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4590 * @adapter: board private structure
4591 *
4592 * If this function returns with an error, then it's possible one or
4593 * more of the rings is populated (while the rest are not). It is the
4594 * callers duty to clean those orphaned rings.
4595 *
4596 * Return 0 on success, negative on failure
4597 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004598static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4599{
4600 int i, err = 0;
4601
4602 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004603 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004604 if (!err)
4605 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00004606 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07004607 break;
4608 }
4609
4610 return err;
4611}
4612
4613/**
Auke Kok9a799d72007-09-15 14:07:45 -07004614 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004615 * @tx_ring: Tx descriptor ring for a specific queue
4616 *
4617 * Free all transmit software resources
4618 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004619void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004620{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004621 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004622
4623 vfree(tx_ring->tx_buffer_info);
4624 tx_ring->tx_buffer_info = NULL;
4625
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004626 /* if not set, then don't free */
4627 if (!tx_ring->desc)
4628 return;
4629
4630 dma_free_coherent(tx_ring->dev, tx_ring->size,
4631 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004632
4633 tx_ring->desc = NULL;
4634}
4635
4636/**
4637 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4638 * @adapter: board private structure
4639 *
4640 * Free all transmit software resources
4641 **/
4642static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4643{
4644 int i;
4645
4646 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004647 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004648 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004649}
4650
4651/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004652 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004653 * @rx_ring: ring to clean the resources from
4654 *
4655 * Free all receive software resources
4656 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004657void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004658{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004659 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004660
4661 vfree(rx_ring->rx_buffer_info);
4662 rx_ring->rx_buffer_info = NULL;
4663
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004664 /* if not set, then don't free */
4665 if (!rx_ring->desc)
4666 return;
4667
4668 dma_free_coherent(rx_ring->dev, rx_ring->size,
4669 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004670
4671 rx_ring->desc = NULL;
4672}
4673
4674/**
4675 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4676 * @adapter: board private structure
4677 *
4678 * Free all receive software resources
4679 **/
4680static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4681{
4682 int i;
4683
4684 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004685 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004686 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004687}
4688
4689/**
Auke Kok9a799d72007-09-15 14:07:45 -07004690 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4691 * @netdev: network interface device structure
4692 * @new_mtu: new value for maximum frame size
4693 *
4694 * Returns 0 on success, negative on failure
4695 **/
4696static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4697{
4698 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4699 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4700
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004701 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004702 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4703 return -EINVAL;
4704
4705 /*
4706 * For 82599EB we cannot allow PF to change MTU greater than 1500
4707 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
4708 * don't allocate and chain buffers correctly.
4709 */
4710 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4711 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4712 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00004713 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07004714
Emil Tantilov396e7992010-07-01 20:05:12 +00004715 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004716
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004717 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004718 netdev->mtu = new_mtu;
4719
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004720 if (netif_running(netdev))
4721 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004722
4723 return 0;
4724}
4725
4726/**
4727 * ixgbe_open - Called when a network interface is made active
4728 * @netdev: network interface device structure
4729 *
4730 * Returns 0 on success, negative value on failure
4731 *
4732 * The open entry point is called when a network interface is made
4733 * active by the system (IFF_UP). At this point all resources needed
4734 * for transmit and receive operations are allocated, the interrupt
4735 * handler is registered with the OS, the watchdog timer is started,
4736 * and the stack is notified that the interface is ready.
4737 **/
4738static int ixgbe_open(struct net_device *netdev)
4739{
4740 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4741 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004742
Auke Kok4bebfaa2008-02-11 09:26:01 -08004743 /* disallow open during test */
4744 if (test_bit(__IXGBE_TESTING, &adapter->state))
4745 return -EBUSY;
4746
Jesse Brandeburg54386462009-04-17 20:44:27 +00004747 netif_carrier_off(netdev);
4748
Auke Kok9a799d72007-09-15 14:07:45 -07004749 /* allocate transmit descriptors */
4750 err = ixgbe_setup_all_tx_resources(adapter);
4751 if (err)
4752 goto err_setup_tx;
4753
Auke Kok9a799d72007-09-15 14:07:45 -07004754 /* allocate receive descriptors */
4755 err = ixgbe_setup_all_rx_resources(adapter);
4756 if (err)
4757 goto err_setup_rx;
4758
4759 ixgbe_configure(adapter);
4760
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004761 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004762 if (err)
4763 goto err_req_irq;
4764
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004765 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004766
4767 return 0;
4768
Auke Kok9a799d72007-09-15 14:07:45 -07004769err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004770err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004771 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004772err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004773 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004774 ixgbe_reset(adapter);
4775
4776 return err;
4777}
4778
4779/**
4780 * ixgbe_close - Disables a network interface
4781 * @netdev: network interface device structure
4782 *
4783 * Returns 0, this is not allowed to fail
4784 *
4785 * The close entry point is called when an interface is de-activated
4786 * by the OS. The hardware is still under the drivers control, but
4787 * needs to be disabled. A global MAC reset is issued to stop the
4788 * hardware, and all transmit and receive resources are freed.
4789 **/
4790static int ixgbe_close(struct net_device *netdev)
4791{
4792 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004793
4794 ixgbe_down(adapter);
4795 ixgbe_free_irq(adapter);
4796
Alexander Duycke4911d52011-05-11 07:18:52 +00004797 ixgbe_fdir_filter_exit(adapter);
4798
Auke Kok9a799d72007-09-15 14:07:45 -07004799 ixgbe_free_all_tx_resources(adapter);
4800 ixgbe_free_all_rx_resources(adapter);
4801
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004802 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004803
4804 return 0;
4805}
4806
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004807#ifdef CONFIG_PM
4808static int ixgbe_resume(struct pci_dev *pdev)
4809{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004810 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4811 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004812 u32 err;
4813
4814 pci_set_power_state(pdev, PCI_D0);
4815 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004816 /*
4817 * pci_restore_state clears dev->state_saved so call
4818 * pci_save_state to restore it.
4819 */
4820 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004821
4822 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004823 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004824 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004825 return err;
4826 }
4827 pci_set_master(pdev);
4828
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004829 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004830
Benjamin Poirier34948a92012-04-06 07:20:21 +00004831 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004832 err = ixgbe_init_interrupt_scheme(adapter);
Benjamin Poirier34948a92012-04-06 07:20:21 +00004833 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004834 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004835 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004836 return err;
4837 }
4838
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004839 ixgbe_reset(adapter);
4840
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004841 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4842
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004843 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004844 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004845 if (err)
4846 return err;
4847 }
4848
4849 netif_device_attach(netdev);
4850
4851 return 0;
4852}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004853#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004854
4855static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004856{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004857 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4858 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004859 struct ixgbe_hw *hw = &adapter->hw;
4860 u32 ctrl, fctrl;
4861 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004862#ifdef CONFIG_PM
4863 int retval = 0;
4864#endif
4865
4866 netif_device_detach(netdev);
4867
4868 if (netif_running(netdev)) {
4869 ixgbe_down(adapter);
4870 ixgbe_free_irq(adapter);
4871 ixgbe_free_all_tx_resources(adapter);
4872 ixgbe_free_all_rx_resources(adapter);
4873 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004874
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08004875 ixgbe_clear_interrupt_scheme(adapter);
4876
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004877#ifdef CONFIG_PM
4878 retval = pci_save_state(pdev);
4879 if (retval)
4880 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004881
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004882#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004883 if (wufc) {
4884 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004885
Don Skidmorec509e752012-04-05 08:12:05 +00004886 /*
4887 * enable the optics for both mult-speed fiber and
4888 * 82599 SFP+ fiber as we can WoL.
4889 */
4890 if (hw->mac.ops.enable_tx_laser &&
4891 (hw->phy.multispeed_fiber ||
4892 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
4893 hw->mac.type == ixgbe_mac_82599EB)))
4894 hw->mac.ops.enable_tx_laser(hw);
4895
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004896 /* turn on all-multi mode if wake on multicast is enabled */
4897 if (wufc & IXGBE_WUFC_MC) {
4898 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4899 fctrl |= IXGBE_FCTRL_MPE;
4900 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4901 }
4902
4903 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4904 ctrl |= IXGBE_CTRL_GIO_DIS;
4905 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4906
4907 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4908 } else {
4909 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4910 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4911 }
4912
Alexander Duyckbd508172010-11-16 19:27:03 -08004913 switch (hw->mac.type) {
4914 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004915 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08004916 break;
4917 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004918 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08004919 pci_wake_from_d3(pdev, !!wufc);
4920 break;
4921 default:
4922 break;
4923 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004924
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004925 *enable_wake = !!wufc;
4926
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004927 ixgbe_release_hw_control(adapter);
4928
4929 pci_disable_device(pdev);
4930
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004931 return 0;
4932}
4933
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004934#ifdef CONFIG_PM
4935static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4936{
4937 int retval;
4938 bool wake;
4939
4940 retval = __ixgbe_shutdown(pdev, &wake);
4941 if (retval)
4942 return retval;
4943
4944 if (wake) {
4945 pci_prepare_to_sleep(pdev);
4946 } else {
4947 pci_wake_from_d3(pdev, false);
4948 pci_set_power_state(pdev, PCI_D3hot);
4949 }
4950
4951 return 0;
4952}
4953#endif /* CONFIG_PM */
4954
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004955static void ixgbe_shutdown(struct pci_dev *pdev)
4956{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004957 bool wake;
4958
4959 __ixgbe_shutdown(pdev, &wake);
4960
4961 if (system_state == SYSTEM_POWER_OFF) {
4962 pci_wake_from_d3(pdev, wake);
4963 pci_set_power_state(pdev, PCI_D3hot);
4964 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004965}
4966
4967/**
Auke Kok9a799d72007-09-15 14:07:45 -07004968 * ixgbe_update_stats - Update the board statistics counters.
4969 * @adapter: board private structure
4970 **/
4971void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4972{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004973 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07004974 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004975 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004976 u64 total_mpc = 0;
4977 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004978 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
4979 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00004980 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00004981#ifdef IXGBE_FCOE
4982 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
4983 unsigned int cpu;
4984 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
4985#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004986
Don Skidmored08935c2010-06-11 13:20:29 +00004987 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
4988 test_bit(__IXGBE_RESETTING, &adapter->state))
4989 return;
4990
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004991 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004992 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004993 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004994 for (i = 0; i < 16; i++)
4995 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00004996 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004997 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08004998 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
4999 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005000 }
5001 adapter->rsc_total_count = rsc_count;
5002 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005003 }
5004
Alexander Duyck5b7da512010-11-16 19:26:50 -08005005 for (i = 0; i < adapter->num_rx_queues; i++) {
5006 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5007 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5008 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5009 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005010 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005011 bytes += rx_ring->stats.bytes;
5012 packets += rx_ring->stats.packets;
5013 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005014 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005015 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5016 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005017 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005018 netdev->stats.rx_bytes = bytes;
5019 netdev->stats.rx_packets = packets;
5020
5021 bytes = 0;
5022 packets = 0;
5023 /* gather some stats to the adapter struct that are per queue */
5024 for (i = 0; i < adapter->num_tx_queues; i++) {
5025 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5026 restart_queue += tx_ring->tx_stats.restart_queue;
5027 tx_busy += tx_ring->tx_stats.tx_busy;
5028 bytes += tx_ring->stats.bytes;
5029 packets += tx_ring->stats.packets;
5030 }
5031 adapter->restart_queue = restart_queue;
5032 adapter->tx_busy = tx_busy;
5033 netdev->stats.tx_bytes = bytes;
5034 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005035
Joe Perches7ca647b2010-09-07 21:35:40 +00005036 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005037
5038 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005039 for (i = 0; i < 8; i++) {
5040 /* for packet buffers not used, the register should read 0 */
5041 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5042 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005043 hwstats->mpc[i] += mpc;
5044 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005045 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5046 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005047 switch (hw->mac.type) {
5048 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005049 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5050 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5051 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005052 hwstats->pxonrxc[i] +=
5053 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005054 break;
5055 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005056 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005057 hwstats->pxonrxc[i] +=
5058 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005059 break;
5060 default:
5061 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005062 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005063 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005064
5065 /*16 register reads */
5066 for (i = 0; i < 16; i++) {
5067 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5068 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5069 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5070 (hw->mac.type == ixgbe_mac_X540)) {
5071 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5072 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5073 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5074 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5075 }
5076 }
5077
Joe Perches7ca647b2010-09-07 21:35:40 +00005078 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005079 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005080 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005081
John Fastabendc84d3242010-11-16 19:27:12 -08005082 ixgbe_update_xoff_received(adapter);
5083
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005084 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005085 switch (hw->mac.type) {
5086 case ixgbe_mac_82598EB:
5087 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005088 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5089 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5090 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5091 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005092 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005093 /* OS2BMC stats are X540 only*/
5094 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5095 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5096 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5097 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5098 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005099 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005100 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005101 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005102 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005103 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005104 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005105 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005106 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5107 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005108#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005109 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5110 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5111 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5112 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5113 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5114 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005115 /* Add up per cpu counters for total ddp aloc fail */
5116 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5117 for_each_possible_cpu(cpu) {
5118 fcoe_noddp_counts_sum +=
5119 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5120 fcoe_noddp_ext_buff_counts_sum +=
5121 *per_cpu_ptr(fcoe->
5122 pcpu_noddp_ext_buff, cpu);
5123 }
5124 }
5125 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5126 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005127#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005128 break;
5129 default:
5130 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005131 }
Auke Kok9a799d72007-09-15 14:07:45 -07005132 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005133 hwstats->bprc += bprc;
5134 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005135 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005136 hwstats->mprc -= bprc;
5137 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5138 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5139 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5140 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5141 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5142 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5143 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5144 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005145 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005146 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005147 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005148 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005149 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5150 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005151 /*
5152 * 82598 errata - tx of flow control packets is included in tx counters
5153 */
5154 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005155 hwstats->gptc -= xon_off_tot;
5156 hwstats->mptc -= xon_off_tot;
5157 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5158 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5159 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5160 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5161 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5162 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5163 hwstats->ptc64 -= xon_off_tot;
5164 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5165 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5166 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5167 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5168 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5169 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005170
5171 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005172 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005173
5174 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005175 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005176 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005177 netdev->stats.rx_length_errors = hwstats->rlec;
5178 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005179 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005180}
5181
5182/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005183 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5184 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005185 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005186static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005187{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005188 struct ixgbe_hw *hw = &adapter->hw;
5189 int i;
5190
Alexander Duyckd034acf2011-04-27 09:25:34 +00005191 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5192 return;
5193
5194 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5195
5196 /* if interface is down do nothing */
5197 if (test_bit(__IXGBE_DOWN, &adapter->state))
5198 return;
5199
5200 /* do nothing if we are not using signature filters */
5201 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5202 return;
5203
5204 adapter->fdir_overflow++;
5205
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005206 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5207 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005208 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005209 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005210 /* re-enable flow director interrupts */
5211 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005212 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005213 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005214 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005215 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005216}
5217
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005218/**
5219 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5220 * @adapter - pointer to the device adapter structure
5221 *
5222 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005223 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005224 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005225 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005226 */
5227static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5228{
Auke Kok9a799d72007-09-15 14:07:45 -07005229 struct ixgbe_hw *hw = &adapter->hw;
5230 u64 eics = 0;
5231 int i;
5232
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005233 /* If we're down or resetting, just bail */
5234 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5235 test_bit(__IXGBE_RESETTING, &adapter->state))
5236 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005237
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005238 /* Force detection of hung controller */
5239 if (netif_carrier_ok(adapter->netdev)) {
5240 for (i = 0; i < adapter->num_tx_queues; i++)
5241 set_check_for_tx_hang(adapter->tx_ring[i]);
5242 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005243
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005244 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005245 /*
5246 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005247 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005248 * would set *both* EIMS and EICS for any bit in EIAM
5249 */
5250 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5251 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005252 } else {
5253 /* get one bit for every active tx/rx interrupt vector */
5254 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5255 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005256 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005257 eics |= ((u64)1 << i);
5258 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005259 }
5260
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005261 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005262 ixgbe_irq_rearm_queues(adapter, eics);
5263
Alexander Duyckfe49f042009-06-04 16:00:09 +00005264}
5265
5266/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005267 * ixgbe_watchdog_update_link - update the link status
5268 * @adapter - pointer to the device adapter structure
5269 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005270 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005271static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005272{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005273 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005274 u32 link_speed = adapter->link_speed;
5275 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005276 int i;
5277
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005278 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5279 return;
5280
5281 if (hw->mac.ops.check_link) {
5282 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005283 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005284 /* always assume link is up, if no check link function */
5285 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5286 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005287 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005288 if (link_up) {
5289 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5290 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5291 hw->mac.ops.fc_enable(hw, i);
5292 } else {
5293 hw->mac.ops.fc_enable(hw, 0);
5294 }
5295 }
5296
5297 if (link_up ||
5298 time_after(jiffies, (adapter->link_check_timeout +
5299 IXGBE_TRY_LINK_TIMEOUT))) {
5300 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5301 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5302 IXGBE_WRITE_FLUSH(hw);
5303 }
5304
5305 adapter->link_up = link_up;
5306 adapter->link_speed = link_speed;
5307}
5308
5309/**
5310 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5311 * print link up message
5312 * @adapter - pointer to the device adapter structure
5313 **/
5314static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5315{
5316 struct net_device *netdev = adapter->netdev;
5317 struct ixgbe_hw *hw = &adapter->hw;
5318 u32 link_speed = adapter->link_speed;
5319 bool flow_rx, flow_tx;
5320
5321 /* only continue if link was previously down */
5322 if (netif_carrier_ok(netdev))
5323 return;
5324
5325 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5326
5327 switch (hw->mac.type) {
5328 case ixgbe_mac_82598EB: {
5329 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5330 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5331 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5332 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5333 }
5334 break;
5335 case ixgbe_mac_X540:
5336 case ixgbe_mac_82599EB: {
5337 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5338 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5339 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5340 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5341 }
5342 break;
5343 default:
5344 flow_tx = false;
5345 flow_rx = false;
5346 break;
5347 }
5348 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5349 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5350 "10 Gbps" :
5351 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5352 "1 Gbps" :
5353 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5354 "100 Mbps" :
5355 "unknown speed"))),
5356 ((flow_rx && flow_tx) ? "RX/TX" :
5357 (flow_rx ? "RX" :
5358 (flow_tx ? "TX" : "None"))));
5359
5360 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005361 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005362}
5363
5364/**
5365 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5366 * print link down message
5367 * @adapter - pointer to the adapter structure
5368 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005369static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005370{
5371 struct net_device *netdev = adapter->netdev;
5372 struct ixgbe_hw *hw = &adapter->hw;
5373
5374 adapter->link_up = false;
5375 adapter->link_speed = 0;
5376
5377 /* only continue if link was up previously */
5378 if (!netif_carrier_ok(netdev))
5379 return;
5380
5381 /* poll for SFP+ cable when link is down */
5382 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5383 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5384
5385 e_info(drv, "NIC Link is Down\n");
5386 netif_carrier_off(netdev);
5387}
5388
5389/**
5390 * ixgbe_watchdog_flush_tx - flush queues on link down
5391 * @adapter - pointer to the device adapter structure
5392 **/
5393static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5394{
5395 int i;
5396 int some_tx_pending = 0;
5397
5398 if (!netif_carrier_ok(adapter->netdev)) {
5399 for (i = 0; i < adapter->num_tx_queues; i++) {
5400 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5401 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5402 some_tx_pending = 1;
5403 break;
5404 }
5405 }
5406
5407 if (some_tx_pending) {
5408 /* We've lost link, so the controller stops DMA,
5409 * but we've got queued Tx work that's never going
5410 * to get done, so reset controller to flush Tx.
5411 * (Do the reset outside of interrupt context).
5412 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005413 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005414 }
5415 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005416}
5417
Greg Rosea985b6c32010-11-18 03:02:52 +00005418static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5419{
5420 u32 ssvpc;
5421
5422 /* Do not perform spoof check for 82598 */
5423 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5424 return;
5425
5426 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5427
5428 /*
5429 * ssvpc register is cleared on read, if zero then no
5430 * spoofed packets in the last interval.
5431 */
5432 if (!ssvpc)
5433 return;
5434
5435 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
5436}
5437
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005438/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005439 * ixgbe_watchdog_subtask - check and bring link up
5440 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005441 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005442static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005443{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005444 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005445 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5446 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005447 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005448
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005449 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005450
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005451 if (adapter->link_up)
5452 ixgbe_watchdog_link_is_up(adapter);
5453 else
5454 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005455
Greg Rosea985b6c32010-11-18 03:02:52 +00005456 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005457 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005458
5459 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005460}
5461
Alexander Duyck70864002011-04-27 09:13:56 +00005462/**
5463 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5464 * @adapter - the ixgbe adapter structure
5465 **/
5466static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5467{
5468 struct ixgbe_hw *hw = &adapter->hw;
5469 s32 err;
5470
5471 /* not searching for SFP so there is nothing to do here */
5472 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5473 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5474 return;
5475
5476 /* someone else is in init, wait until next service event */
5477 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5478 return;
5479
5480 err = hw->phy.ops.identify_sfp(hw);
5481 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5482 goto sfp_out;
5483
5484 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5485 /* If no cable is present, then we need to reset
5486 * the next time we find a good cable. */
5487 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5488 }
5489
5490 /* exit on error */
5491 if (err)
5492 goto sfp_out;
5493
5494 /* exit if reset not needed */
5495 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5496 goto sfp_out;
5497
5498 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5499
5500 /*
5501 * A module may be identified correctly, but the EEPROM may not have
5502 * support for that module. setup_sfp() will fail in that case, so
5503 * we should not allow that module to load.
5504 */
5505 if (hw->mac.type == ixgbe_mac_82598EB)
5506 err = hw->phy.ops.reset(hw);
5507 else
5508 err = hw->mac.ops.setup_sfp(hw);
5509
5510 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5511 goto sfp_out;
5512
5513 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5514 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5515
5516sfp_out:
5517 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5518
5519 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5520 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5521 e_dev_err("failed to initialize because an unsupported "
5522 "SFP+ module type was detected.\n");
5523 e_dev_err("Reload the driver after installing a "
5524 "supported module.\n");
5525 unregister_netdev(adapter->netdev);
5526 }
5527}
5528
5529/**
5530 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
5531 * @adapter - the ixgbe adapter structure
5532 **/
5533static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5534{
5535 struct ixgbe_hw *hw = &adapter->hw;
5536 u32 autoneg;
5537 bool negotiation;
5538
5539 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5540 return;
5541
5542 /* someone else is in init, wait until next service event */
5543 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5544 return;
5545
5546 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5547
5548 autoneg = hw->phy.autoneg_advertised;
5549 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5550 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005551 if (hw->mac.ops.setup_link)
5552 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5553
5554 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5555 adapter->link_check_timeout = jiffies;
5556 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5557}
5558
Greg Rose83c61fa2011-09-07 05:59:35 +00005559#ifdef CONFIG_PCI_IOV
5560static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5561{
5562 int vf;
5563 struct ixgbe_hw *hw = &adapter->hw;
5564 struct net_device *netdev = adapter->netdev;
5565 u32 gpc;
5566 u32 ciaa, ciad;
5567
5568 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5569 if (gpc) /* If incrementing then no need for the check below */
5570 return;
5571 /*
5572 * Check to see if a bad DMA write target from an errant or
5573 * malicious VF has caused a PCIe error. If so then we can
5574 * issue a VFLR to the offending VF(s) and then resume without
5575 * requesting a full slot reset.
5576 */
5577
5578 for (vf = 0; vf < adapter->num_vfs; vf++) {
5579 ciaa = (vf << 16) | 0x80000000;
5580 /* 32 bit read so align, we really want status at offset 6 */
5581 ciaa |= PCI_COMMAND;
5582 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5583 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5584 ciaa &= 0x7FFFFFFF;
5585 /* disable debug mode asap after reading data */
5586 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5587 /* Get the upper 16 bits which will be the PCI status reg */
5588 ciad >>= 16;
5589 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5590 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5591 /* Issue VFLR */
5592 ciaa = (vf << 16) | 0x80000000;
5593 ciaa |= 0xA8;
5594 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5595 ciad = 0x00008000; /* VFLR */
5596 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5597 ciaa &= 0x7FFFFFFF;
5598 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5599 }
5600 }
5601}
5602
5603#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005604/**
5605 * ixgbe_service_timer - Timer Call-back
5606 * @data: pointer to adapter cast into an unsigned long
5607 **/
5608static void ixgbe_service_timer(unsigned long data)
5609{
5610 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5611 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005612 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005613
5614 /* poll faster when waiting for link */
5615 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5616 next_event_offset = HZ / 10;
5617 else
5618 next_event_offset = HZ * 2;
5619
Greg Rose83c61fa2011-09-07 05:59:35 +00005620#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005621 /*
5622 * don't bother with SR-IOV VF DMA hang check if there are
5623 * no VFs or the link is down
5624 */
5625 if (!adapter->num_vfs ||
5626 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5627 goto normal_timer_service;
5628
5629 /* If we have VFs allocated then we must check for DMA hangs */
5630 ixgbe_check_for_bad_vf(adapter);
5631 next_event_offset = HZ / 50;
5632 adapter->timer_event_accumulator++;
5633
5634 if (adapter->timer_event_accumulator >= 100)
5635 adapter->timer_event_accumulator = 0;
5636 else
5637 ready = false;
5638
5639normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005640#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005641 /* Reset the timer */
5642 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5643
Greg Rose83c61fa2011-09-07 05:59:35 +00005644 if (ready)
5645 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005646}
5647
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005648static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5649{
5650 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5651 return;
5652
5653 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5654
5655 /* If we're already down or resetting, just bail */
5656 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5657 test_bit(__IXGBE_RESETTING, &adapter->state))
5658 return;
5659
5660 ixgbe_dump(adapter);
5661 netdev_err(adapter->netdev, "Reset adapter\n");
5662 adapter->tx_timeout_count++;
5663
5664 ixgbe_reinit_locked(adapter);
5665}
5666
Alexander Duyck70864002011-04-27 09:13:56 +00005667/**
5668 * ixgbe_service_task - manages and runs subtasks
5669 * @work: pointer to work_struct containing our data
5670 **/
5671static void ixgbe_service_task(struct work_struct *work)
5672{
5673 struct ixgbe_adapter *adapter = container_of(work,
5674 struct ixgbe_adapter,
5675 service_task);
5676
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005677 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005678 ixgbe_sfp_detection_subtask(adapter);
5679 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005680 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005681 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005682 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005683 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005684
5685 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005686}
5687
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005688static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5689 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005690 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005691{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005692 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005693 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005694 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005695
Alexander Duyck897ab152011-05-27 05:31:47 +00005696 if (!skb_is_gso(skb))
5697 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005698
Alexander Duyck897ab152011-05-27 05:31:47 +00005699 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005700 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005701 if (err)
5702 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005703 }
5704
Alexander Duyck897ab152011-05-27 05:31:47 +00005705 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5706 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5707
Alexander Duyck244e27a2012-02-08 07:51:11 +00005708 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005709 struct iphdr *iph = ip_hdr(skb);
5710 iph->tot_len = 0;
5711 iph->check = 0;
5712 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5713 iph->daddr, 0,
5714 IPPROTO_TCP,
5715 0);
5716 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005717 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5718 IXGBE_TX_FLAGS_CSUM |
5719 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005720 } else if (skb_is_gso_v6(skb)) {
5721 ipv6_hdr(skb)->payload_len = 0;
5722 tcp_hdr(skb)->check =
5723 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5724 &ipv6_hdr(skb)->daddr,
5725 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005726 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5727 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005728 }
5729
Alexander Duyck091a6242012-02-08 07:51:01 +00005730 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005731 l4len = tcp_hdrlen(skb);
5732 *hdr_len = skb_transport_offset(skb) + l4len;
5733
Alexander Duyck091a6242012-02-08 07:51:01 +00005734 /* update gso size and bytecount with header size */
5735 first->gso_segs = skb_shinfo(skb)->gso_segs;
5736 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5737
Alexander Duyck897ab152011-05-27 05:31:47 +00005738 /* mss_l4len_id: use 1 as index for TSO */
5739 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5740 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5741 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5742
5743 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5744 vlan_macip_lens = skb_network_header_len(skb);
5745 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005746 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005747
5748 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005749 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005750
5751 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005752}
5753
Alexander Duyck244e27a2012-02-08 07:51:11 +00005754static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5755 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005756{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005757 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005758 u32 vlan_macip_lens = 0;
5759 u32 mss_l4len_idx = 0;
5760 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005761
Alexander Duyck897ab152011-05-27 05:31:47 +00005762 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005763 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
5764 !(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5765 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00005766 } else {
5767 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005768 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005769 case __constant_htons(ETH_P_IP):
5770 vlan_macip_lens |= skb_network_header_len(skb);
5771 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5772 l4_hdr = ip_hdr(skb)->protocol;
5773 break;
5774 case __constant_htons(ETH_P_IPV6):
5775 vlan_macip_lens |= skb_network_header_len(skb);
5776 l4_hdr = ipv6_hdr(skb)->nexthdr;
5777 break;
5778 default:
5779 if (unlikely(net_ratelimit())) {
5780 dev_warn(tx_ring->dev,
5781 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005782 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005783 }
5784 break;
5785 }
Auke Kok9a799d72007-09-15 14:07:45 -07005786
Alexander Duyck897ab152011-05-27 05:31:47 +00005787 switch (l4_hdr) {
5788 case IPPROTO_TCP:
5789 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5790 mss_l4len_idx = tcp_hdrlen(skb) <<
5791 IXGBE_ADVTXD_L4LEN_SHIFT;
5792 break;
5793 case IPPROTO_SCTP:
5794 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
5795 mss_l4len_idx = sizeof(struct sctphdr) <<
5796 IXGBE_ADVTXD_L4LEN_SHIFT;
5797 break;
5798 case IPPROTO_UDP:
5799 mss_l4len_idx = sizeof(struct udphdr) <<
5800 IXGBE_ADVTXD_L4LEN_SHIFT;
5801 break;
5802 default:
5803 if (unlikely(net_ratelimit())) {
5804 dev_warn(tx_ring->dev,
5805 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005806 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00005807 }
5808 break;
5809 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00005810
5811 /* update TX checksum flag */
5812 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005813 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005814
Alexander Duyck244e27a2012-02-08 07:51:11 +00005815 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00005816 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005817 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005818
5819 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
5820 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07005821}
5822
Alexander Duyckd3d00232011-07-15 02:31:25 +00005823static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
5824{
5825 /* set type for advanced descriptor with frame checksum insertion */
5826 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
5827 IXGBE_ADVTXD_DCMD_IFCS |
5828 IXGBE_ADVTXD_DCMD_DEXT);
5829
5830 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00005831 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005832 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
5833
5834 /* set segmentation enable bits for TSO/FSO */
5835#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005836 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005837#else
5838 if (tx_flags & IXGBE_TX_FLAGS_TSO)
5839#endif
5840 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
5841
5842 return cmd_type;
5843}
5844
Alexander Duyck729739b2012-02-08 07:51:06 +00005845static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
5846 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005847{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005848 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005849
5850 /* enable L4 checksum for TSO and TX checksum offload */
5851 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5852 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
5853
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005854 /* enble IPv4 checksum for TSO */
5855 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5856 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005857
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005858 /* use index 1 context for TSO/FSO/FCOE */
5859#ifdef IXGBE_FCOE
5860 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
5861#else
5862 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005863#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005864 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
5865
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005866 /*
5867 * Check Context must be set if Tx switch is enabled, which it
5868 * always is for case where virtual functions are running
5869 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005870#ifdef IXGBE_FCOE
5871 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
5872#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005873 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005874#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005875 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
5876
Alexander Duyck729739b2012-02-08 07:51:06 +00005877 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005878}
5879
5880#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
5881 IXGBE_TXD_CMD_RS)
5882
5883static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00005884 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00005885 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07005886{
Alexander Duyckd3d00232011-07-15 02:31:25 +00005887 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00005888 struct sk_buff *skb = first->skb;
5889 struct ixgbe_tx_buffer *tx_buffer;
5890 union ixgbe_adv_tx_desc *tx_desc;
5891 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00005892 unsigned int data_len = skb->data_len;
5893 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00005894 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005895 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00005896 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005897 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07005898
Alexander Duyck729739b2012-02-08 07:51:06 +00005899 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5900
5901 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
5902 cmd_type = ixgbe_tx_cmd_type(tx_flags);
5903
Alexander Duyckd3d00232011-07-15 02:31:25 +00005904#ifdef IXGBE_FCOE
5905 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005906 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00005907 size -= sizeof(struct fcoe_crc_eof) - data_len;
5908 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00005909 } else {
5910 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005911 }
Auke Kok9a799d72007-09-15 14:07:45 -07005912 }
5913
Alexander Duyckd3d00232011-07-15 02:31:25 +00005914#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00005915 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5916 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005917 goto dma_error;
5918
Alexander Duyck729739b2012-02-08 07:51:06 +00005919 /* record length, and DMA address */
5920 dma_unmap_len_set(first, len, size);
5921 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005922
Alexander Duyck729739b2012-02-08 07:51:06 +00005923 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005924
5925 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005926 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00005927 tx_desc->read.cmd_type_len =
5928 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005929
Alexander Duyckd3d00232011-07-15 02:31:25 +00005930 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00005931 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005932 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00005933 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005934 i = 0;
5935 }
Alexander Duyck729739b2012-02-08 07:51:06 +00005936
5937 dma += IXGBE_MAX_DATA_PER_TXD;
5938 size -= IXGBE_MAX_DATA_PER_TXD;
5939
5940 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5941 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005942 }
5943
Alexander Duyck729739b2012-02-08 07:51:06 +00005944 if (likely(!data_len))
5945 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005946
Ben Greearf43f3132012-03-06 09:42:04 +00005947 if (unlikely(skb->no_fcs))
5948 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00005949 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005950
Alexander Duyck729739b2012-02-08 07:51:06 +00005951 i++;
5952 tx_desc++;
5953 if (i == tx_ring->count) {
5954 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5955 i = 0;
5956 }
Auke Kok9a799d72007-09-15 14:07:45 -07005957
Alexander Duyckd3d00232011-07-15 02:31:25 +00005958#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00005959 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00005960#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00005961 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005962#endif
5963 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005964
Alexander Duyck729739b2012-02-08 07:51:06 +00005965 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
5966 DMA_TO_DEVICE);
5967 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005968 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005969
Alexander Duyck729739b2012-02-08 07:51:06 +00005970 tx_buffer = &tx_ring->tx_buffer_info[i];
5971 dma_unmap_len_set(tx_buffer, len, size);
5972 dma_unmap_addr_set(tx_buffer, dma, dma);
5973
5974 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5975 tx_desc->read.olinfo_status = 0;
5976
5977 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07005978 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005979
Alexander Duyck729739b2012-02-08 07:51:06 +00005980 /* write last descriptor with RS and EOP bits */
5981 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
5982 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005983
Alexander Duyck091a6242012-02-08 07:51:01 +00005984 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00005985
Alexander Duyckd3d00232011-07-15 02:31:25 +00005986 /* set the timestamp */
5987 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07005988
5989 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00005990 * Force memory writes to complete before letting h/w know there
5991 * are new descriptors to fetch. (Only applicable for weak-ordered
5992 * memory model archs, such as IA-64).
5993 *
5994 * We also need this memory barrier to make certain all of the
5995 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07005996 */
5997 wmb();
5998
Alexander Duyckd3d00232011-07-15 02:31:25 +00005999 /* set next_to_watch value indicating a packet is present */
6000 first->next_to_watch = tx_desc;
6001
Alexander Duyck729739b2012-02-08 07:51:06 +00006002 i++;
6003 if (i == tx_ring->count)
6004 i = 0;
6005
6006 tx_ring->next_to_use = i;
6007
Alexander Duyckd3d00232011-07-15 02:31:25 +00006008 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006009 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006010
6011 return;
6012dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006013 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006014
6015 /* clear dma mappings for failed tx_buffer_info map */
6016 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006017 tx_buffer = &tx_ring->tx_buffer_info[i];
6018 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6019 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006020 break;
6021 if (i == 0)
6022 i = tx_ring->count;
6023 i--;
6024 }
6025
Alexander Duyckd3d00232011-07-15 02:31:25 +00006026 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006027}
6028
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006029static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006030 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006031{
Alexander Duyck69830522011-01-06 14:29:58 +00006032 struct ixgbe_q_vector *q_vector = ring->q_vector;
6033 union ixgbe_atr_hash_dword input = { .dword = 0 };
6034 union ixgbe_atr_hash_dword common = { .dword = 0 };
6035 union {
6036 unsigned char *network;
6037 struct iphdr *ipv4;
6038 struct ipv6hdr *ipv6;
6039 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006040 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006041 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006042
Alexander Duyck69830522011-01-06 14:29:58 +00006043 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6044 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006045 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006046
Alexander Duyck69830522011-01-06 14:29:58 +00006047 /* do nothing if sampling is disabled */
6048 if (!ring->atr_sample_rate)
6049 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006050
Alexander Duyck69830522011-01-06 14:29:58 +00006051 ring->atr_count++;
6052
6053 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006054 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006055
6056 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006057 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006058 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006059 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006060 hdr.ipv4->protocol != IPPROTO_TCP))
6061 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006062
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006063 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006064
Alexander Duyck66f32a82011-06-29 05:43:22 +00006065 /* skip this packet since it is invalid or the socket is closing */
6066 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006067 return;
6068
6069 /* sample on all syn packets or once every atr sample count */
6070 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6071 return;
6072
6073 /* reset sample count */
6074 ring->atr_count = 0;
6075
Alexander Duyck244e27a2012-02-08 07:51:11 +00006076 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006077
6078 /*
6079 * src and dst are inverted, think how the receiver sees them
6080 *
6081 * The input is broken into two sections, a non-compressed section
6082 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6083 * is XORed together and stored in the compressed dword.
6084 */
6085 input.formatted.vlan_id = vlan_id;
6086
6087 /*
6088 * since src port and flex bytes occupy the same word XOR them together
6089 * and write the value to source port portion of compressed dword
6090 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006091 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006092 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6093 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006094 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006095 common.port.dst ^= th->source;
6096
Alexander Duyck244e27a2012-02-08 07:51:11 +00006097 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006098 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6099 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6100 } else {
6101 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6102 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6103 hdr.ipv6->saddr.s6_addr32[1] ^
6104 hdr.ipv6->saddr.s6_addr32[2] ^
6105 hdr.ipv6->saddr.s6_addr32[3] ^
6106 hdr.ipv6->daddr.s6_addr32[0] ^
6107 hdr.ipv6->daddr.s6_addr32[1] ^
6108 hdr.ipv6->daddr.s6_addr32[2] ^
6109 hdr.ipv6->daddr.s6_addr32[3];
6110 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006111
6112 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006113 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6114 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006115}
6116
Alexander Duyck63544e92011-05-27 05:31:42 +00006117static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006118{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006119 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006120 /* Herbert's original patch had:
6121 * smp_mb__after_netif_stop_queue();
6122 * but since that doesn't exist yet, just open code it. */
6123 smp_mb();
6124
6125 /* We need to check again in a case another CPU has just
6126 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006127 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006128 return -EBUSY;
6129
6130 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006131 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006132 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006133 return 0;
6134}
6135
Alexander Duyck82d4e462011-06-11 01:44:58 +00006136static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006137{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006138 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006139 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006140 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006141}
6142
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006143static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6144{
6145 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006146 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6147 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006148#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006149 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006150
John Fastabende5b64632011-03-08 03:44:52 +00006151 if (((protocol == htons(ETH_P_FCOE)) ||
6152 (protocol == htons(ETH_P_FIP))) &&
6153 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6154 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6155 txq += adapter->ring_feature[RING_F_FCOE].mask;
6156 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006157 }
6158#endif
6159
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006160 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6161 while (unlikely(txq >= dev->real_num_tx_queues))
6162 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006163 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006164 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006165
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006166 return skb_tx_hash(dev, skb);
6167}
6168
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006169netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006170 struct ixgbe_adapter *adapter,
6171 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006172{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006173 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006174 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006175 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006176#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6177 unsigned short f;
6178#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006179 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006180 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006181 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006182
Alexander Duycka535c302011-05-27 05:31:52 +00006183 /*
6184 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006185 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006186 * + 2 desc gap to keep tail from touching head,
6187 * + 1 desc for context descriptor,
6188 * otherwise try next time
6189 */
6190#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6191 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6192 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6193#else
6194 count += skb_shinfo(skb)->nr_frags;
6195#endif
6196 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6197 tx_ring->tx_stats.tx_busy++;
6198 return NETDEV_TX_BUSY;
6199 }
6200
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006201 /* record the location of the first descriptor for this packet */
6202 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6203 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006204 first->bytecount = skb->len;
6205 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006206
Alexander Duyck66f32a82011-06-29 05:43:22 +00006207 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006208 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006209 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6210 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6211 /* else if it is a SW VLAN check the next protocol and store the tag */
6212 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6213 struct vlan_hdr *vhdr, _vhdr;
6214 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6215 if (!vhdr)
6216 goto out_drop;
6217
6218 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006219 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6220 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006221 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006222 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006223
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006224#ifdef CONFIG_PCI_IOV
6225 /*
6226 * Use the l2switch_enable flag - would be false if the DMA
6227 * Tx switch had been disabled.
6228 */
6229 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6230 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6231
6232#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006233 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006234 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006235 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6236 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006237 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006238 tx_flags |= (skb->priority & 0x7) <<
6239 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006240 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6241 struct vlan_ethhdr *vhdr;
6242 if (skb_header_cloned(skb) &&
6243 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6244 goto out_drop;
6245 vhdr = (struct vlan_ethhdr *)skb->data;
6246 vhdr->h_vlan_TCI = htons(tx_flags >>
6247 IXGBE_TX_FLAGS_VLAN_SHIFT);
6248 } else {
6249 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6250 }
6251 }
Alexander Duycka535c302011-05-27 05:31:52 +00006252
Alexander Duyck244e27a2012-02-08 07:51:11 +00006253 /* record initial flags and protocol */
6254 first->tx_flags = tx_flags;
6255 first->protocol = protocol;
6256
Yi Zoueacd73f2009-05-13 13:11:06 +00006257#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006258 /* setup tx offload for FCoE */
6259 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6260 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006261 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006262 if (tso < 0)
6263 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006264
Alexander Duyck66f32a82011-06-29 05:43:22 +00006265 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006266 }
Auke Kok9a799d72007-09-15 14:07:45 -07006267
Auke Kok9a799d72007-09-15 14:07:45 -07006268#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006269 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006270 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006271 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006272 else if (!tso)
6273 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006274
6275 /* add the ATR filter if ATR is on */
6276 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006277 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006278
6279#ifdef IXGBE_FCOE
6280xmit_fcoe:
6281#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006282 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006283
6284 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006285
6286 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006287
6288out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006289 dev_kfree_skb_any(first->skb);
6290 first->skb = NULL;
6291
Alexander Duyck897ab152011-05-27 05:31:47 +00006292 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006293}
6294
Alexander Duycka50c29d2012-02-08 07:50:40 +00006295static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6296 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006297{
6298 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006299 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006300
Alexander Duycka50c29d2012-02-08 07:50:40 +00006301 if (skb->len <= 0) {
6302 dev_kfree_skb_any(skb);
6303 return NETDEV_TX_OK;
6304 }
6305
6306 /*
6307 * The minimum packet size for olinfo paylen is 17 so pad the skb
6308 * in order to meet this minimum size requirement.
6309 */
6310 if (skb->len < 17) {
6311 if (skb_padto(skb, 17))
6312 return NETDEV_TX_OK;
6313 skb->len = 17;
6314 }
6315
Auke Kok9a799d72007-09-15 14:07:45 -07006316 tx_ring = adapter->tx_ring[skb->queue_mapping];
6317 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6318}
6319
6320/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006321 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006322 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006323 * @p: pointer to an address structure
6324 *
Auke Kok9a799d72007-09-15 14:07:45 -07006325 * Returns 0 on success, negative on failure
6326 **/
6327static int ixgbe_set_mac(struct net_device *netdev, void *p)
6328{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006329 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6330 struct ixgbe_hw *hw = &adapter->hw;
6331 struct sockaddr *addr = p;
6332
6333 if (!is_valid_ether_addr(addr->sa_data))
6334 return -EADDRNOTAVAIL;
6335
6336 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6337 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6338
6339 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6340 IXGBE_RAH_AV);
6341
6342 return 0;
6343}
6344
6345static int
6346ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6347{
6348 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6349 struct ixgbe_hw *hw = &adapter->hw;
6350 u16 value;
6351 int rc;
6352
6353 if (prtad != hw->phy.mdio.prtad)
6354 return -EINVAL;
6355 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6356 if (!rc)
6357 rc = value;
6358 return rc;
6359}
6360
6361static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6362 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006363{
6364 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00006365 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006366
6367 if (prtad != hw->phy.mdio.prtad)
6368 return -EINVAL;
6369 return hw->phy.ops.write_reg(hw, addr, devad, value);
6370}
6371
6372static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6373{
6374 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6375
6376 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6377}
6378
6379/**
6380 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6381 * netdev->dev_addrs
6382 * @netdev: network interface device structure
6383 *
6384 * Returns non-zero on failure
6385 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00006386static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006387{
6388 int err = 0;
6389 struct ixgbe_adapter *adapter = netdev_priv(dev);
6390 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6391
6392 if (is_valid_ether_addr(mac->san_addr)) {
6393 rtnl_lock();
6394 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6395 rtnl_unlock();
6396 }
6397 return err;
6398}
6399
6400/**
6401 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6402 * netdev->dev_addrs
6403 * @netdev: network interface device structure
6404 *
Auke Kok9a799d72007-09-15 14:07:45 -07006405 * Returns non-zero on failure
6406 **/
6407static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6408{
6409 int err = 0;
6410 struct ixgbe_adapter *adapter = netdev_priv(dev);
6411 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6412
6413 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006414 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07006415 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006416 rtnl_unlock();
6417 }
6418 return err;
6419}
Auke Kok9a799d72007-09-15 14:07:45 -07006420
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006421#ifdef CONFIG_NET_POLL_CONTROLLER
6422/*
6423 * Polling 'interrupt' - used by things like netconsole to send skbs
6424 * without having to re-enable interrupts. It's not called while
6425 * the interrupt routine is executing.
6426 */
6427static void ixgbe_netpoll(struct net_device *netdev)
6428{
6429 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006430 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006431
6432 /* if interface is down do nothing */
6433 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006434 return;
6435
6436 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08006437 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006438 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00006439 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006440 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00006441 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006442 }
6443 } else {
6444 ixgbe_intr(adapter->pdev->irq, netdev);
6445 }
6446 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6447}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006448
Alexander Duyck581330b2012-02-08 07:51:47 +00006449#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006450static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6451 struct rtnl_link_stats64 *stats)
6452{
6453 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6454 int i;
6455
Eric Dumazet1a515022010-11-16 19:26:42 -08006456 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006457 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006458 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006459 u64 bytes, packets;
6460 unsigned int start;
6461
Eric Dumazet1a515022010-11-16 19:26:42 -08006462 if (ring) {
6463 do {
6464 start = u64_stats_fetch_begin_bh(&ring->syncp);
6465 packets = ring->stats.packets;
6466 bytes = ring->stats.bytes;
6467 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6468 stats->rx_packets += packets;
6469 stats->rx_bytes += bytes;
6470 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006471 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006472
6473 for (i = 0; i < adapter->num_tx_queues; i++) {
6474 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6475 u64 bytes, packets;
6476 unsigned int start;
6477
6478 if (ring) {
6479 do {
6480 start = u64_stats_fetch_begin_bh(&ring->syncp);
6481 packets = ring->stats.packets;
6482 bytes = ring->stats.bytes;
6483 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6484 stats->tx_packets += packets;
6485 stats->tx_bytes += bytes;
6486 }
6487 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006488 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006489 /* following stats updated by ixgbe_watchdog_task() */
6490 stats->multicast = netdev->stats.multicast;
6491 stats->rx_errors = netdev->stats.rx_errors;
6492 stats->rx_length_errors = netdev->stats.rx_length_errors;
6493 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6494 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6495 return stats;
6496}
6497
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006498#ifdef CONFIG_IXGBE_DCB
John Fastabend8b1c0b22011-05-03 02:26:48 +00006499/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6500 * #adapter: pointer to ixgbe_adapter
6501 * @tc: number of traffic classes currently enabled
6502 *
6503 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6504 * 802.1Q priority maps to a packet buffer that exists.
6505 */
6506static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6507{
6508 struct ixgbe_hw *hw = &adapter->hw;
6509 u32 reg, rsave;
6510 int i;
6511
6512 /* 82598 have a static priority to TC mapping that can not
6513 * be changed so no validation is needed.
6514 */
6515 if (hw->mac.type == ixgbe_mac_82598EB)
6516 return;
6517
6518 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6519 rsave = reg;
6520
6521 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6522 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6523
6524 /* If up2tc is out of bounds default to zero */
6525 if (up2tc > tc)
6526 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6527 }
6528
6529 if (reg != rsave)
6530 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6531
6532 return;
6533}
6534
John Fastabend8b1c0b22011-05-03 02:26:48 +00006535/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
6536 * classes.
6537 *
6538 * @netdev: net device to configure
6539 * @tc: number of traffic classes to enable
6540 */
6541int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6542{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006543 struct ixgbe_adapter *adapter = netdev_priv(dev);
6544 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006545
John Fastabende7589ea2011-07-18 22:38:36 +00006546 /* Multiple traffic classes requires multiple queues */
6547 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6548 e_err(drv, "Enable failed, needs MSI-X\n");
6549 return -EINVAL;
6550 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00006551
6552 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006553 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006554 (hw->mac.type == ixgbe_mac_82598EB &&
6555 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006556 return -EINVAL;
6557
6558 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006559 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006560 * hardware is not flexible enough to do this dynamically.
6561 */
6562 if (netif_running(dev))
6563 ixgbe_close(dev);
6564 ixgbe_clear_interrupt_scheme(adapter);
6565
John Fastabende7589ea2011-07-18 22:38:36 +00006566 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006567 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00006568 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006569 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
6570 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6571
6572 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6573 adapter->hw.fc.requested_mode = ixgbe_fc_none;
6574 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006575 netdev_reset_tc(dev);
John Fastabende7589ea2011-07-18 22:38:36 +00006576 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
6577
6578 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6579 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6580
6581 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6582 adapter->dcb_cfg.pfc_mode_enable = false;
6583 }
6584
John Fastabend8b1c0b22011-05-03 02:26:48 +00006585 ixgbe_init_interrupt_scheme(adapter);
6586 ixgbe_validate_rtr(adapter, tc);
6587 if (netif_running(dev))
6588 ixgbe_open(dev);
6589
6590 return 0;
6591}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006592
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006593#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006594void ixgbe_do_reset(struct net_device *netdev)
6595{
6596 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6597
6598 if (netif_running(netdev))
6599 ixgbe_reinit_locked(adapter);
6600 else
6601 ixgbe_reset(adapter);
6602}
6603
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006604static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006605 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006606{
6607 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6608
6609#ifdef CONFIG_DCB
6610 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Alexander Duyck567d2de2012-02-11 07:18:57 +00006611 features &= ~NETIF_F_HW_VLAN_RX;
Don Skidmore082757a2011-07-21 05:55:00 +00006612#endif
6613
6614 /* return error if RXHASH is being enabled when RSS is not supported */
6615 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
Alexander Duyck567d2de2012-02-11 07:18:57 +00006616 features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00006617
6618 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006619 if (!(features & NETIF_F_RXCSUM))
6620 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006621
Alexander Duyck567d2de2012-02-11 07:18:57 +00006622 /* Turn off LRO if not RSC capable */
6623 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6624 features &= ~NETIF_F_LRO;
6625
Don Skidmore082757a2011-07-21 05:55:00 +00006626
Alexander Duyck567d2de2012-02-11 07:18:57 +00006627 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006628}
6629
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006630static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006631 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006632{
6633 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006634 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006635 bool need_reset = false;
6636
Don Skidmore082757a2011-07-21 05:55:00 +00006637 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006638 if (!(features & NETIF_F_LRO)) {
6639 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006640 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006641 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6642 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6643 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6644 if (adapter->rx_itr_setting == 1 ||
6645 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6646 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6647 need_reset = true;
6648 } else if ((changed ^ features) & NETIF_F_LRO) {
6649 e_info(probe, "rx-usecs set too low, "
6650 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006651 }
6652 }
6653
6654 /*
6655 * Check if Flow Director n-tuple support was enabled or disabled. If
6656 * the state changed, we need to reset.
6657 */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006658 if (!(features & NETIF_F_NTUPLE)) {
6659 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
6660 /* turn off Flow Director, set ATR and reset */
6661 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
6662 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
6663 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00006664 need_reset = true;
6665 }
Don Skidmore082757a2011-07-21 05:55:00 +00006666 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006667 } else if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
6668 /* turn off ATR, enable perfect filters and reset */
6669 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6670 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00006671 need_reset = true;
6672 }
6673
Ben Greear3f2d1c02012-03-08 08:28:41 +00006674 if (changed & NETIF_F_RXALL)
6675 need_reset = true;
6676
Alexander Duyck567d2de2012-02-11 07:18:57 +00006677 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006678 if (need_reset)
6679 ixgbe_do_reset(netdev);
6680
6681 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006682}
6683
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006684static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00006685 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006686 .ndo_stop = ixgbe_close,
6687 .ndo_start_xmit = ixgbe_xmit_frame,
6688 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00006689 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006690 .ndo_validate_addr = eth_validate_addr,
6691 .ndo_set_mac_address = ixgbe_set_mac,
6692 .ndo_change_mtu = ixgbe_change_mtu,
6693 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006694 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
6695 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00006696 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00006697 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
6698 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
6699 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00006700 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00006701 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00006702 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006703#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00006704 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006705#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006706#ifdef CONFIG_NET_POLL_CONTROLLER
6707 .ndo_poll_controller = ixgbe_netpoll,
6708#endif
Yi Zou332d4a72009-05-13 13:11:53 +00006709#ifdef IXGBE_FCOE
6710 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00006711 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00006712 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00006713 .ndo_fcoe_enable = ixgbe_fcoe_enable,
6714 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00006715 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00006716 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00006717#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00006718 .ndo_set_features = ixgbe_set_features,
6719 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006720};
6721
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006722static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006723 const struct ixgbe_info *ii)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006724{
6725#ifdef CONFIG_PCI_IOV
6726 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006727
Greg Rosec6bda302011-08-24 02:37:55 +00006728 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006729 return;
6730
6731 /* The 82599 supports up to 64 VFs per physical function
6732 * but this implementation limits allocation to 63 so that
6733 * basic networking resources are still available to the
6734 * physical function
6735 */
6736 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00006737 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006738#endif /* CONFIG_PCI_IOV */
6739}
6740
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006741/**
Auke Kok9a799d72007-09-15 14:07:45 -07006742 * ixgbe_probe - Device Initialization Routine
6743 * @pdev: PCI device information struct
6744 * @ent: entry in ixgbe_pci_tbl
6745 *
6746 * Returns 0 on success, negative on failure
6747 *
6748 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
6749 * The OS initialization, configuring of the adapter private structure,
6750 * and a hardware reset occur.
6751 **/
6752static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00006753 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07006754{
6755 struct net_device *netdev;
6756 struct ixgbe_adapter *adapter = NULL;
6757 struct ixgbe_hw *hw;
6758 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07006759 static int cards_found;
6760 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00006761 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00006762 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00006763#ifdef IXGBE_FCOE
6764 u16 device_caps;
6765#endif
Don Skidmore289700db2010-12-03 03:32:58 +00006766 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00006767 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07006768
Andy Gospodarekbded64a2010-07-21 06:40:31 +00006769 /* Catch broken hardware that put the wrong VF device ID in
6770 * the PCIe SR-IOV capability.
6771 */
6772 if (pdev->is_virtfn) {
6773 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
6774 pci_name(pdev), pdev->vendor, pdev->device);
6775 return -EINVAL;
6776 }
6777
gouji-new9ce77662009-05-06 10:44:45 +00006778 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006779 if (err)
6780 return err;
6781
Nick Nunley1b507732010-04-27 13:10:27 +00006782 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
6783 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07006784 pci_using_dac = 1;
6785 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00006786 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07006787 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00006788 err = dma_set_coherent_mask(&pdev->dev,
6789 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07006790 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00006791 dev_err(&pdev->dev,
6792 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006793 goto err_dma;
6794 }
6795 }
6796 pci_using_dac = 0;
6797 }
6798
gouji-new9ce77662009-05-06 10:44:45 +00006799 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00006800 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07006801 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00006802 dev_err(&pdev->dev,
6803 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07006804 goto err_pci_reg;
6805 }
6806
Frans Pop19d5afd2009-10-02 10:04:12 -07006807 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006808
Auke Kok9a799d72007-09-15 14:07:45 -07006809 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07006810 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006811
John Fastabende901acd2011-04-26 07:26:08 +00006812#ifdef CONFIG_IXGBE_DCB
6813 indices *= MAX_TRAFFIC_CLASS;
6814#endif
6815
John Fastabendc85a2612010-02-25 23:15:21 +00006816 if (ii->mac == ixgbe_mac_82598EB)
6817 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
6818 else
6819 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
6820
John Fastabende901acd2011-04-26 07:26:08 +00006821#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00006822 indices += min_t(unsigned int, num_possible_cpus(),
6823 IXGBE_MAX_FCOE_INDICES);
6824#endif
John Fastabendc85a2612010-02-25 23:15:21 +00006825 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07006826 if (!netdev) {
6827 err = -ENOMEM;
6828 goto err_alloc_etherdev;
6829 }
6830
Auke Kok9a799d72007-09-15 14:07:45 -07006831 SET_NETDEV_DEV(netdev, &pdev->dev);
6832
Auke Kok9a799d72007-09-15 14:07:45 -07006833 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006834 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006835
6836 adapter->netdev = netdev;
6837 adapter->pdev = pdev;
6838 hw = &adapter->hw;
6839 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006840 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07006841
Jeff Kirsher05857982008-09-11 19:57:00 -07006842 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00006843 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07006844 if (!hw->hw_addr) {
6845 err = -EIO;
6846 goto err_ioremap;
6847 }
6848
6849 for (i = 1; i <= 5; i++) {
6850 if (pci_resource_len(pdev, i) == 0)
6851 continue;
6852 }
6853
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006854 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07006855 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006856 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00006857 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07006858
Auke Kok9a799d72007-09-15 14:07:45 -07006859 adapter->bd_number = cards_found;
6860
Auke Kok9a799d72007-09-15 14:07:45 -07006861 /* Setup hw api */
6862 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006863 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07006864
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006865 /* EEPROM */
6866 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
6867 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
6868 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
6869 if (!(eec & (1 << 8)))
6870 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
6871
6872 /* PHY */
6873 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08006874 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00006875 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
6876 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
6877 hw->phy.mdio.mmds = 0;
6878 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
6879 hw->phy.mdio.dev = netdev;
6880 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
6881 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08006882
Don Skidmore8ca783a2009-05-26 20:40:47 -07006883 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006884
6885 /* setup the private structure */
6886 err = ixgbe_sw_init(adapter);
6887 if (err)
6888 goto err_sw_init;
6889
Don Skidmoree86bff02010-02-11 04:14:08 +00006890 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08006891 switch (adapter->hw.mac.type) {
6892 case ixgbe_mac_82599EB:
6893 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00006894 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08006895 break;
6896 default:
6897 break;
6898 }
Don Skidmoree86bff02010-02-11 04:14:08 +00006899
Don Skidmorebf069c92009-05-07 10:39:54 +00006900 /*
6901 * If there is a fan on this device and it has failed log the
6902 * failure.
6903 */
6904 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
6905 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
6906 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00006907 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00006908 }
6909
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00006910 if (allow_unsupported_sfp)
6911 hw->allow_unsupported_sfp = allow_unsupported_sfp;
6912
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006913 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07006914 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006915 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07006916 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07006917 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
6918 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07006919 err = 0;
6920 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00006921 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00006922 "module type was detected.\n");
6923 e_dev_err("Reload the driver after installing a supported "
6924 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00006925 goto err_sw_init;
6926 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006927 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006928 goto err_sw_init;
6929 }
6930
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006931 ixgbe_probe_vf(adapter, ii);
6932
Emil Tantilov396e7992010-07-01 20:05:12 +00006933 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00006934 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00006935 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00006936 NETIF_F_HW_VLAN_TX |
6937 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00006938 NETIF_F_HW_VLAN_FILTER |
6939 NETIF_F_TSO |
6940 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00006941 NETIF_F_RXHASH |
6942 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006943
Don Skidmore082757a2011-07-21 05:55:00 +00006944 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07006945
Don Skidmore58be7662011-04-12 09:42:11 +00006946 switch (adapter->hw.mac.type) {
6947 case ixgbe_mac_82599EB:
6948 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00006949 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00006950 netdev->hw_features |= NETIF_F_SCTP_CSUM |
6951 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00006952 break;
6953 default:
6954 break;
6955 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00006956
Ben Greear3f2d1c02012-03-08 08:28:41 +00006957 netdev->hw_features |= NETIF_F_RXALL;
6958
Jeff Kirsherad31c402008-06-05 04:05:30 -07006959 netdev->vlan_features |= NETIF_F_TSO;
6960 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07006961 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00006962 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07006963 netdev->vlan_features |= NETIF_F_SG;
6964
Jiri Pirko01789342011-08-16 06:29:00 +00006965 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00006966 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00006967
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006968 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6969 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
6970 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006971
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006972#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08006973 netdev->dcbnl_ops = &dcbnl_ops;
6974#endif
6975
Yi Zoueacd73f2009-05-13 13:11:06 +00006976#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00006977 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00006978 if (hw->mac.ops.get_device_caps) {
6979 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00006980 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
6981 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00006982 }
6983 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00006984 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
6985 netdev->vlan_features |= NETIF_F_FCOE_CRC;
6986 netdev->vlan_features |= NETIF_F_FSO;
6987 netdev->vlan_features |= NETIF_F_FCOE_MTU;
6988 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006989#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00006990 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07006991 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00006992 netdev->vlan_features |= NETIF_F_HIGHDMA;
6993 }
Auke Kok9a799d72007-09-15 14:07:45 -07006994
Don Skidmore082757a2011-07-21 05:55:00 +00006995 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
6996 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00006997 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00006998 netdev->features |= NETIF_F_LRO;
6999
Auke Kok9a799d72007-09-15 14:07:45 -07007000 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007001 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007002 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007003 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007004 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007005 }
7006
7007 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7008 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7009
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007010 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007011 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007012 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007013 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007014 }
7015
Alexander Duyck70864002011-04-27 09:13:56 +00007016 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007017 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007018
Alexander Duyck70864002011-04-27 09:13:56 +00007019 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7020 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007021
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007022 err = ixgbe_init_interrupt_scheme(adapter);
7023 if (err)
7024 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007025
Don Skidmore082757a2011-07-21 05:55:00 +00007026 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7027 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007028 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007029 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007030
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007031 /* WOL not supported for all but the following */
7032 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007033 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007034 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007035 /* Only these subdevice supports WOL */
7036 switch (pdev->subsystem_device) {
7037 case IXGBE_SUBDEV_ID_82599_560FLR:
7038 /* only support first port */
7039 if (hw->bus.func != 0)
7040 break;
7041 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007042 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007043 break;
7044 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007045 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007046 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7047 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007048 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007049 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007050 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007051 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007052 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007053 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007054 case IXGBE_DEV_ID_X540T:
7055 /* Check eeprom to see if it is enabled */
7056 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7057 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7058
7059 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7060 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7061 (hw->bus.func == 0)))
7062 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007063 break;
7064 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007065 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7066
Emil Tantilov15e52092011-09-29 05:01:29 +00007067 /* save off EEPROM version number */
7068 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7069 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7070
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007071 /* pick up the PCI bus settings for reporting later */
7072 hw->mac.ops.get_bus_info(hw);
7073
Auke Kok9a799d72007-09-15 14:07:45 -07007074 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007075 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007076 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7077 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007078 "Unknown"),
7079 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7080 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7081 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7082 "Unknown"),
7083 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007084
7085 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7086 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007087 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007088 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007089 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007090 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007091 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007092 else
Don Skidmore289700db2010-12-03 03:32:58 +00007093 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7094 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007095
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007096 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007097 e_dev_warn("PCI-Express bandwidth available for this card is "
7098 "not sufficient for optimal performance.\n");
7099 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7100 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007101 }
7102
Auke Kok9a799d72007-09-15 14:07:45 -07007103 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007104 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007105 if (err == IXGBE_ERR_EEPROM_VERSION) {
7106 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007107 e_dev_warn("This device is a pre-production adapter/LOM. "
7108 "Please be aware there may be issues associated "
7109 "with your hardware. If you are experiencing "
7110 "problems please contact your Intel or hardware "
7111 "representative who provided you with this "
7112 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007113 }
Auke Kok9a799d72007-09-15 14:07:45 -07007114 strcpy(netdev->name, "eth%d");
7115 err = register_netdev(netdev);
7116 if (err)
7117 goto err_register;
7118
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007119 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7120 if (hw->mac.ops.disable_tx_laser &&
7121 ((hw->phy.multispeed_fiber) ||
7122 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7123 (hw->mac.type == ixgbe_mac_82599EB))))
7124 hw->mac.ops.disable_tx_laser(hw);
7125
Jesse Brandeburg54386462009-04-17 20:44:27 +00007126 /* carrier off reporting is important to ethtool even BEFORE open */
7127 netif_carrier_off(netdev);
7128
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007129#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007130 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007131 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007132 ixgbe_setup_dca(adapter);
7133 }
7134#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007135 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007136 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007137 for (i = 0; i < adapter->num_vfs; i++)
7138 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7139 }
7140
Jacob Keller2466dd92011-09-08 03:50:54 +00007141 /* firmware requires driver version to be 0xFFFFFFFF
7142 * since os does not support feature
7143 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007144 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007145 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7146 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007147
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007148 /* add san mac addr to netdev */
7149 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007150
Neerav Parikhea818752012-01-04 20:23:40 +00007151 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007152 cards_found++;
7153 return 0;
7154
7155err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007156 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007157 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007158err_sw_init:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007159 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7160 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007161 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007162 iounmap(hw->hw_addr);
7163err_ioremap:
7164 free_netdev(netdev);
7165err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007166 pci_release_selected_regions(pdev,
7167 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007168err_pci_reg:
7169err_dma:
7170 pci_disable_device(pdev);
7171 return err;
7172}
7173
7174/**
7175 * ixgbe_remove - Device Removal Routine
7176 * @pdev: PCI device information struct
7177 *
7178 * ixgbe_remove is called by the PCI subsystem to alert the driver
7179 * that it should release a PCI device. The could be caused by a
7180 * Hot-Plug event, or because the driver is going to be removed from
7181 * memory.
7182 **/
7183static void __devexit ixgbe_remove(struct pci_dev *pdev)
7184{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007185 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7186 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007187
7188 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007189 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007190
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007191#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007192 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7193 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7194 dca_remove_requester(&pdev->dev);
7195 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7196 }
7197
7198#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007199#ifdef IXGBE_FCOE
7200 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7201 ixgbe_cleanup_fcoe(adapter);
7202
7203#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007204
7205 /* remove the added san mac */
7206 ixgbe_del_sanmac_netdev(netdev);
7207
Donald Skidmorec4900be2008-11-20 21:11:42 -08007208 if (netdev->reg_state == NETREG_REGISTERED)
7209 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007210
Greg Rosec6bda302011-08-24 02:37:55 +00007211 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7212 if (!(ixgbe_check_vf_assignment(adapter)))
7213 ixgbe_disable_sriov(adapter);
7214 else
7215 e_dev_warn("Unloading driver while VFs are assigned "
7216 "- VFs will not be deallocated\n");
7217 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007218
Alexander Duyck7a921c92009-05-06 10:43:28 +00007219 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007220
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007221 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007222
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007223#ifdef CONFIG_DCB
7224 kfree(adapter->ixgbe_ieee_pfc);
7225 kfree(adapter->ixgbe_ieee_ets);
7226
7227#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007228 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007229 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007230 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007231
Emil Tantilov849c4542010-06-03 16:53:41 +00007232 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007233
Auke Kok9a799d72007-09-15 14:07:45 -07007234 free_netdev(netdev);
7235
Frans Pop19d5afd2009-10-02 10:04:12 -07007236 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007237
Auke Kok9a799d72007-09-15 14:07:45 -07007238 pci_disable_device(pdev);
7239}
7240
7241/**
7242 * ixgbe_io_error_detected - called when PCI error is detected
7243 * @pdev: Pointer to PCI device
7244 * @state: The current pci connection state
7245 *
7246 * This function is called after a PCI bus error affecting
7247 * this device has been detected.
7248 */
7249static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007250 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007251{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007252 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7253 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007254
Greg Rose83c61fa2011-09-07 05:59:35 +00007255#ifdef CONFIG_PCI_IOV
7256 struct pci_dev *bdev, *vfdev;
7257 u32 dw0, dw1, dw2, dw3;
7258 int vf, pos;
7259 u16 req_id, pf_func;
7260
7261 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7262 adapter->num_vfs == 0)
7263 goto skip_bad_vf_detection;
7264
7265 bdev = pdev->bus->self;
7266 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
7267 bdev = bdev->bus->self;
7268
7269 if (!bdev)
7270 goto skip_bad_vf_detection;
7271
7272 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7273 if (!pos)
7274 goto skip_bad_vf_detection;
7275
7276 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7277 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7278 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7279 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7280
7281 req_id = dw1 >> 16;
7282 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7283 if (!(req_id & 0x0080))
7284 goto skip_bad_vf_detection;
7285
7286 pf_func = req_id & 0x01;
7287 if ((pf_func & 1) == (pdev->devfn & 1)) {
7288 unsigned int device_id;
7289
7290 vf = (req_id & 0x7F) >> 1;
7291 e_dev_err("VF %d has caused a PCIe error\n", vf);
7292 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7293 "%8.8x\tdw3: %8.8x\n",
7294 dw0, dw1, dw2, dw3);
7295 switch (adapter->hw.mac.type) {
7296 case ixgbe_mac_82599EB:
7297 device_id = IXGBE_82599_VF_DEVICE_ID;
7298 break;
7299 case ixgbe_mac_X540:
7300 device_id = IXGBE_X540_VF_DEVICE_ID;
7301 break;
7302 default:
7303 device_id = 0;
7304 break;
7305 }
7306
7307 /* Find the pci device of the offending VF */
7308 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
7309 while (vfdev) {
7310 if (vfdev->devfn == (req_id & 0xFF))
7311 break;
7312 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
7313 device_id, vfdev);
7314 }
7315 /*
7316 * There's a slim chance the VF could have been hot plugged,
7317 * so if it is no longer present we don't need to issue the
7318 * VFLR. Just clean up the AER in that case.
7319 */
7320 if (vfdev) {
7321 e_dev_err("Issuing VFLR to VF %d\n", vf);
7322 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7323 }
7324
7325 pci_cleanup_aer_uncorrect_error_status(pdev);
7326 }
7327
7328 /*
7329 * Even though the error may have occurred on the other port
7330 * we still need to increment the vf error reference count for
7331 * both ports because the I/O resume function will be called
7332 * for both of them.
7333 */
7334 adapter->vferr_refcount++;
7335
7336 return PCI_ERS_RESULT_RECOVERED;
7337
7338skip_bad_vf_detection:
7339#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007340 netif_device_detach(netdev);
7341
Breno Leitao3044b8d2009-05-06 10:44:26 +00007342 if (state == pci_channel_io_perm_failure)
7343 return PCI_ERS_RESULT_DISCONNECT;
7344
Auke Kok9a799d72007-09-15 14:07:45 -07007345 if (netif_running(netdev))
7346 ixgbe_down(adapter);
7347 pci_disable_device(pdev);
7348
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007349 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007350 return PCI_ERS_RESULT_NEED_RESET;
7351}
7352
7353/**
7354 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7355 * @pdev: Pointer to PCI device
7356 *
7357 * Restart the card from scratch, as if from a cold-boot.
7358 */
7359static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7360{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007361 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007362 pci_ers_result_t result;
7363 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007364
gouji-new9ce77662009-05-06 10:44:45 +00007365 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007366 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007367 result = PCI_ERS_RESULT_DISCONNECT;
7368 } else {
7369 pci_set_master(pdev);
7370 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007371 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007372
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007373 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007374
7375 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007376 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007377 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007378 }
Auke Kok9a799d72007-09-15 14:07:45 -07007379
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007380 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7381 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007382 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7383 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007384 /* non-fatal, continue */
7385 }
Auke Kok9a799d72007-09-15 14:07:45 -07007386
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007387 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007388}
7389
7390/**
7391 * ixgbe_io_resume - called when traffic can start flowing again.
7392 * @pdev: Pointer to PCI device
7393 *
7394 * This callback is called when the error recovery driver tells us that
7395 * its OK to resume normal operation.
7396 */
7397static void ixgbe_io_resume(struct pci_dev *pdev)
7398{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007399 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7400 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007401
Greg Rose83c61fa2011-09-07 05:59:35 +00007402#ifdef CONFIG_PCI_IOV
7403 if (adapter->vferr_refcount) {
7404 e_info(drv, "Resuming after VF err\n");
7405 adapter->vferr_refcount--;
7406 return;
7407 }
7408
7409#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007410 if (netif_running(netdev))
7411 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007412
7413 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007414}
7415
7416static struct pci_error_handlers ixgbe_err_handler = {
7417 .error_detected = ixgbe_io_error_detected,
7418 .slot_reset = ixgbe_io_slot_reset,
7419 .resume = ixgbe_io_resume,
7420};
7421
7422static struct pci_driver ixgbe_driver = {
7423 .name = ixgbe_driver_name,
7424 .id_table = ixgbe_pci_tbl,
7425 .probe = ixgbe_probe,
7426 .remove = __devexit_p(ixgbe_remove),
7427#ifdef CONFIG_PM
7428 .suspend = ixgbe_suspend,
7429 .resume = ixgbe_resume,
7430#endif
7431 .shutdown = ixgbe_shutdown,
7432 .err_handler = &ixgbe_err_handler
7433};
7434
7435/**
7436 * ixgbe_init_module - Driver Registration Routine
7437 *
7438 * ixgbe_init_module is the first routine called when the driver is
7439 * loaded. All it does is register with the PCI subsystem.
7440 **/
7441static int __init ixgbe_init_module(void)
7442{
7443 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007444 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007445 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007446
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007447#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007448 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007449#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007450
Auke Kok9a799d72007-09-15 14:07:45 -07007451 ret = pci_register_driver(&ixgbe_driver);
7452 return ret;
7453}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007454
Auke Kok9a799d72007-09-15 14:07:45 -07007455module_init(ixgbe_init_module);
7456
7457/**
7458 * ixgbe_exit_module - Driver Exit Cleanup Routine
7459 *
7460 * ixgbe_exit_module is called just before the driver is removed
7461 * from memory.
7462 **/
7463static void __exit ixgbe_exit_module(void)
7464{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007465#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007466 dca_unregister_notify(&dca_notifier);
7467#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007468 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007469 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007470}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007471
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007472#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007473static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007474 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007475{
7476 int ret_val;
7477
7478 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007479 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007480
7481 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7482}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007483
Alexander Duyckb4533682009-03-31 21:32:42 +00007484#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007485
Auke Kok9a799d72007-09-15 14:07:45 -07007486module_exit(ixgbe_exit_module);
7487
7488/* ixgbe_main.c */