blob: ea3cb710c2dd22bf118bbb3fa4634478d110097c [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 Skidmorefe15e8e12010-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,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000136 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
Greg Rose1cdd1ec2010-01-09 02:26:46 +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;
John Fastabende1abc1b2012-04-23 22:27:28 +0000640 } else if (((adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) &&
641 !(adapter->dcb_cfg.pfc_mode_enable)) ||
642 ((adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) &&
643 adapter->ixgbe_ieee_pfc &&
644 !(adapter->ixgbe_ieee_pfc->pfc_en)))
John Fastabendc84d3242010-11-16 19:27:12 -0800645 return;
646
647 /* update stats for each tc, only valid with PFC enabled */
648 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
649 switch (hw->mac.type) {
650 case ixgbe_mac_82598EB:
651 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
652 break;
653 default:
654 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
655 }
656 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700657 }
658
John Fastabendc84d3242010-11-16 19:27:12 -0800659 /* disarm tx queues that have received xoff frames */
660 for (i = 0; i < adapter->num_tx_queues; i++) {
661 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000662 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800663
664 if (xoff[tc])
665 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
666 }
667}
668
669static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
670{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000671 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800672}
673
674static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
675{
676 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
677 struct ixgbe_hw *hw = &adapter->hw;
678
679 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
680 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
681
682 if (head != tail)
683 return (head < tail) ?
684 tail - head : (tail + ring->count - head);
685
686 return 0;
687}
688
689static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
690{
691 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
692 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
693 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
694 bool ret = false;
695
696 clear_check_for_tx_hang(tx_ring);
697
698 /*
699 * Check for a hung queue, but be thorough. This verifies
700 * that a transmit has been completed since the previous
701 * check AND there is at least one packet pending. The
702 * ARMED bit is set to indicate a potential hang. The
703 * bit is cleared if a pause frame is received to remove
704 * false hang detection due to PFC or 802.3x frames. By
705 * requiring this to fail twice we avoid races with
706 * pfc clearing the ARMED bit and conditions where we
707 * run the check_tx_hang logic with a transmit completion
708 * pending but without time to complete it yet.
709 */
710 if ((tx_done_old == tx_done) && tx_pending) {
711 /* make sure it is true for two checks in a row */
712 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
713 &tx_ring->state);
714 } else {
715 /* update completed stats and continue */
716 tx_ring->tx_stats.tx_done_old = tx_done;
717 /* reset the countdown */
718 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
719 }
720
721 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700722}
723
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000724/**
725 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
726 * @adapter: driver private struct
727 **/
728static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
729{
730
731 /* Do the reset outside of interrupt context */
732 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
733 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
734 ixgbe_service_event_schedule(adapter);
735 }
736}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700737
Auke Kok9a799d72007-09-15 14:07:45 -0700738/**
739 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000740 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700741 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700742 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000743static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000744 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700745{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000746 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000747 struct ixgbe_tx_buffer *tx_buffer;
748 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700749 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000750 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000751 unsigned int i = tx_ring->next_to_clean;
752
753 if (test_bit(__IXGBE_DOWN, &adapter->state))
754 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700755
Alexander Duyckd3d00232011-07-15 02:31:25 +0000756 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000757 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000758 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800759
Alexander Duyck729739b2012-02-08 07:51:06 +0000760 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000761 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700762
Alexander Duyckd3d00232011-07-15 02:31:25 +0000763 /* if next_to_watch is not set then there is no work pending */
764 if (!eop_desc)
765 break;
766
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000767 /* prevent any other reads prior to eop_desc */
768 rmb();
769
Alexander Duyckd3d00232011-07-15 02:31:25 +0000770 /* if DD is not set pending work has not been completed */
771 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
772 break;
773
Alexander Duyckd3d00232011-07-15 02:31:25 +0000774 /* clear next_to_watch to prevent false hangs */
775 tx_buffer->next_to_watch = NULL;
776
Alexander Duyck091a6242012-02-08 07:51:01 +0000777 /* update the statistics for this packet */
778 total_bytes += tx_buffer->bytecount;
779 total_packets += tx_buffer->gso_segs;
780
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000781 /* free the skb */
782 dev_kfree_skb_any(tx_buffer->skb);
783
Alexander Duyck729739b2012-02-08 07:51:06 +0000784 /* unmap skb header data */
785 dma_unmap_single(tx_ring->dev,
786 dma_unmap_addr(tx_buffer, dma),
787 dma_unmap_len(tx_buffer, len),
788 DMA_TO_DEVICE);
789
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000790 /* clear tx_buffer data */
791 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000792 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000793
Alexander Duyck729739b2012-02-08 07:51:06 +0000794 /* unmap remaining buffers */
795 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000796 tx_buffer++;
797 tx_desc++;
798 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000799 if (unlikely(!i)) {
800 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000801 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000802 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000803 }
804
Alexander Duyck729739b2012-02-08 07:51:06 +0000805 /* unmap any remaining paged data */
806 if (dma_unmap_len(tx_buffer, len)) {
807 dma_unmap_page(tx_ring->dev,
808 dma_unmap_addr(tx_buffer, dma),
809 dma_unmap_len(tx_buffer, len),
810 DMA_TO_DEVICE);
811 dma_unmap_len_set(tx_buffer, len, 0);
812 }
813 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800814
Alexander Duyck729739b2012-02-08 07:51:06 +0000815 /* move us one more past the eop_desc for start of next pkt */
816 tx_buffer++;
817 tx_desc++;
818 i++;
819 if (unlikely(!i)) {
820 i -= tx_ring->count;
821 tx_buffer = tx_ring->tx_buffer_info;
822 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
823 }
824
825 /* issue prefetch for next Tx descriptor */
826 prefetch(tx_desc);
827
828 /* update budget accounting */
829 budget--;
830 } while (likely(budget));
831
832 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700833 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000834 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800835 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000836 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000837 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000838 q_vector->tx.total_bytes += total_bytes;
839 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800840
John Fastabendc84d3242010-11-16 19:27:12 -0800841 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800842 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800843 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800844 e_err(drv, "Detected Tx Unit Hang\n"
845 " Tx Queue <%d>\n"
846 " TDH, TDT <%x>, <%x>\n"
847 " next_to_use <%x>\n"
848 " next_to_clean <%x>\n"
849 "tx_buffer_info[next_to_clean]\n"
850 " time_stamp <%lx>\n"
851 " jiffies <%lx>\n",
852 tx_ring->queue_index,
853 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
854 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000855 tx_ring->next_to_use, i,
856 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800857
858 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
859
860 e_info(probe,
861 "tx hang %d detected on queue %d, resetting adapter\n",
862 adapter->tx_timeout_count + 1, tx_ring->queue_index);
863
864 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000865 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800866
867 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000868 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800869 }
Auke Kok9a799d72007-09-15 14:07:45 -0700870
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000871 netdev_tx_completed_queue(txring_txq(tx_ring),
872 total_packets, total_bytes);
873
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800874#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000875 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000876 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800877 /* Make sure that anybody stopping the queue after this
878 * sees the new next_to_clean.
879 */
880 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000881 if (__netif_subqueue_stopped(tx_ring->netdev,
882 tx_ring->queue_index)
883 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
884 netif_wake_subqueue(tx_ring->netdev,
885 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800886 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800887 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800888 }
Auke Kok9a799d72007-09-15 14:07:45 -0700889
Alexander Duyck59224552011-08-31 00:01:06 +0000890 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700891}
892
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400893#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800894static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800895 struct ixgbe_ring *tx_ring,
896 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800897{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000898 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000899 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
900 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800901
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800902 switch (hw->mac.type) {
903 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000904 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800905 break;
906 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800907 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000908 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
909 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
910 break;
911 default:
912 /* for unknown hardware do not write register */
913 return;
914 }
915
916 /*
917 * We can enable relaxed ordering for reads, but not writes when
918 * DCA is enabled. This is due to a known issue in some chipsets
919 * which will cause the DCA tag to be cleared.
920 */
921 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
922 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
923 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
924
925 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
926}
927
928static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
929 struct ixgbe_ring *rx_ring,
930 int cpu)
931{
932 struct ixgbe_hw *hw = &adapter->hw;
933 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
934 u8 reg_idx = rx_ring->reg_idx;
935
936
937 switch (hw->mac.type) {
938 case ixgbe_mac_82599EB:
939 case ixgbe_mac_X540:
940 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800941 break;
942 default:
943 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800944 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000945
946 /*
947 * We can enable relaxed ordering for reads, but not writes when
948 * DCA is enabled. This is due to a known issue in some chipsets
949 * which will cause the DCA tag to be cleared.
950 */
951 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
952 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
953 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
954
955 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800956}
957
958static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
959{
960 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000961 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800962 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800963
964 if (q_vector->cpu == cpu)
965 goto out_no_update;
966
Alexander Duycka5579282012-02-08 07:50:04 +0000967 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000968 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800969
Alexander Duycka5579282012-02-08 07:50:04 +0000970 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000971 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800972
973 q_vector->cpu = cpu;
974out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800975 put_cpu();
976}
977
978static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
979{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800980 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800981 int i;
982
983 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
984 return;
985
Alexander Duycke35ec122009-05-21 13:07:12 +0000986 /* always use CB2 mode, difference is masked in the CB driver */
987 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
988
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800989 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
990 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
991 else
992 num_q_vectors = 1;
993
994 for (i = 0; i < num_q_vectors; i++) {
995 adapter->q_vector[i]->cpu = -1;
996 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800997 }
998}
999
1000static int __ixgbe_notify_dca(struct device *dev, void *data)
1001{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001002 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001003 unsigned long event = *(unsigned long *)data;
1004
Don Skidmore2a72c312011-07-20 02:27:05 +00001005 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001006 return 0;
1007
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001008 switch (event) {
1009 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001010 /* if we're already enabled, don't do it again */
1011 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1012 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001013 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001014 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001015 ixgbe_setup_dca(adapter);
1016 break;
1017 }
1018 /* Fall Through since DCA is disabled. */
1019 case DCA_PROVIDER_REMOVE:
1020 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1021 dca_remove_requester(dev);
1022 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1023 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1024 }
1025 break;
1026 }
1027
Denis V. Lunev652f0932008-03-27 14:39:17 +03001028 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001029}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001030
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001031#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001032static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1033 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001034 struct sk_buff *skb)
1035{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001036 if (ring->netdev->features & NETIF_F_RXHASH)
1037 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001038}
1039
Alexander Duyckf8003262012-03-03 02:35:52 +00001040#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001041/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001042 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1043 * @adapter: address of board private structure
1044 * @rx_desc: advanced rx descriptor
1045 *
1046 * Returns : true if it is FCoE pkt
1047 */
1048static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1049 union ixgbe_adv_rx_desc *rx_desc)
1050{
1051 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1052
1053 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1054 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1055 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1056 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1057}
1058
Alexander Duyckf8003262012-03-03 02:35:52 +00001059#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001060/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001061 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001062 * @ring: structure containing ring specific data
1063 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001064 * @skb: skb currently being received and modified
1065 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001066static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001067 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001068 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001069{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001070 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001071
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001072 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001073 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001074 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001075
1076 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001077 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1078 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001079 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001080 return;
1081 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001082
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001083 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001084 return;
1085
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001086 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001087 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001088
1089 /*
1090 * 82599 errata, UDP frames with a 0 checksum can be marked as
1091 * checksum errors.
1092 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001093 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1094 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001095 return;
1096
Alexander Duyck8a0da212012-01-31 02:59:49 +00001097 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001098 return;
1099 }
1100
Auke Kok9a799d72007-09-15 14:07:45 -07001101 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001102 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001103}
1104
Alexander Duyck84ea2592010-11-16 19:26:49 -08001105static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001106{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001107 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001108
1109 /* update next to alloc since we have filled the ring */
1110 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001111 /*
1112 * Force memory writes to complete before letting h/w
1113 * know there are new descriptors to fetch. (Only
1114 * applicable for weak-ordered memory model archs,
1115 * such as IA-64).
1116 */
1117 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001118 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001119}
1120
Alexander Duyckf990b792012-01-31 02:59:34 +00001121static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1122 struct ixgbe_rx_buffer *bi)
1123{
1124 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001125 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001126
Alexander Duyckf8003262012-03-03 02:35:52 +00001127 /* since we are recycling buffers we should seldom need to alloc */
1128 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001129 return true;
1130
Alexander Duyckf8003262012-03-03 02:35:52 +00001131 /* alloc new page for storage */
1132 if (likely(!page)) {
1133 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1134 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001135 if (unlikely(!page)) {
1136 rx_ring->rx_stats.alloc_rx_page_failed++;
1137 return false;
1138 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001139 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001140 }
1141
Alexander Duyckf8003262012-03-03 02:35:52 +00001142 /* map page for use */
1143 dma = dma_map_page(rx_ring->dev, page, 0,
1144 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001145
Alexander Duyckf8003262012-03-03 02:35:52 +00001146 /*
1147 * if mapping failed free memory back to system since
1148 * there isn't much point in holding memory we can't use
1149 */
1150 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001151 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001152 bi->page = NULL;
1153
Alexander Duyckf990b792012-01-31 02:59:34 +00001154 rx_ring->rx_stats.alloc_rx_page_failed++;
1155 return false;
1156 }
1157
Alexander Duyckf8003262012-03-03 02:35:52 +00001158 bi->dma = dma;
1159 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1160
Alexander Duyckf990b792012-01-31 02:59:34 +00001161 return true;
1162}
1163
Auke Kok9a799d72007-09-15 14:07:45 -07001164/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001165 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001166 * @rx_ring: ring to place buffers on
1167 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001168 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001169void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001170{
Auke Kok9a799d72007-09-15 14:07:45 -07001171 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001172 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001173 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001174
Alexander Duyckf8003262012-03-03 02:35:52 +00001175 /* nothing to do */
1176 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001177 return;
1178
Alexander Duycke4f74022012-01-31 02:59:44 +00001179 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001180 bi = &rx_ring->rx_buffer_info[i];
1181 i -= rx_ring->count;
1182
Alexander Duyckf8003262012-03-03 02:35:52 +00001183 do {
1184 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001185 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001186
Alexander Duyckf8003262012-03-03 02:35:52 +00001187 /*
1188 * Refresh the desc even if buffer_addrs didn't change
1189 * because each write-back erases this info.
1190 */
1191 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001192
Alexander Duyckf990b792012-01-31 02:59:34 +00001193 rx_desc++;
1194 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001195 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001196 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001197 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001198 bi = rx_ring->rx_buffer_info;
1199 i -= rx_ring->count;
1200 }
1201
1202 /* clear the hdr_addr for the next_to_use descriptor */
1203 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001204
1205 cleaned_count--;
1206 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001207
Alexander Duyckf990b792012-01-31 02:59:34 +00001208 i += rx_ring->count;
1209
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001210 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001211 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001212}
1213
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001214/**
1215 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1216 * @data: pointer to the start of the headers
1217 * @max_len: total length of section to find headers in
1218 *
1219 * This function is meant to determine the length of headers that will
1220 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1221 * motivation of doing this is to only perform one pull for IPv4 TCP
1222 * packets so that we can do basic things like calculating the gso_size
1223 * based on the average data per packet.
1224 **/
1225static unsigned int ixgbe_get_headlen(unsigned char *data,
1226 unsigned int max_len)
1227{
1228 union {
1229 unsigned char *network;
1230 /* l2 headers */
1231 struct ethhdr *eth;
1232 struct vlan_hdr *vlan;
1233 /* l3 headers */
1234 struct iphdr *ipv4;
1235 } hdr;
1236 __be16 protocol;
1237 u8 nexthdr = 0; /* default to not TCP */
1238 u8 hlen;
1239
1240 /* this should never happen, but better safe than sorry */
1241 if (max_len < ETH_HLEN)
1242 return max_len;
1243
1244 /* initialize network frame pointer */
1245 hdr.network = data;
1246
1247 /* set first protocol and move network header forward */
1248 protocol = hdr.eth->h_proto;
1249 hdr.network += ETH_HLEN;
1250
1251 /* handle any vlan tag if present */
1252 if (protocol == __constant_htons(ETH_P_8021Q)) {
1253 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1254 return max_len;
1255
1256 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1257 hdr.network += VLAN_HLEN;
1258 }
1259
1260 /* handle L3 protocols */
1261 if (protocol == __constant_htons(ETH_P_IP)) {
1262 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1263 return max_len;
1264
1265 /* access ihl as a u8 to avoid unaligned access on ia64 */
1266 hlen = (hdr.network[0] & 0x0F) << 2;
1267
1268 /* verify hlen meets minimum size requirements */
1269 if (hlen < sizeof(struct iphdr))
1270 return hdr.network - data;
1271
1272 /* record next protocol */
1273 nexthdr = hdr.ipv4->protocol;
1274 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001275#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001276 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1277 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1278 return max_len;
1279 hdr.network += FCOE_HEADER_LEN;
1280#endif
1281 } else {
1282 return hdr.network - data;
1283 }
1284
1285 /* finally sort out TCP */
1286 if (nexthdr == IPPROTO_TCP) {
1287 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1288 return max_len;
1289
1290 /* access doff as a u8 to avoid unaligned access on ia64 */
1291 hlen = (hdr.network[12] & 0xF0) >> 2;
1292
1293 /* verify hlen meets minimum size requirements */
1294 if (hlen < sizeof(struct tcphdr))
1295 return hdr.network - data;
1296
1297 hdr.network += hlen;
1298 }
1299
1300 /*
1301 * If everything has gone correctly hdr.network should be the
1302 * data section of the packet and will be the end of the header.
1303 * If not then it probably represents the end of the last recognized
1304 * header.
1305 */
1306 if ((hdr.network - data) < max_len)
1307 return hdr.network - data;
1308 else
1309 return max_len;
1310}
1311
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001312static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1313 union ixgbe_adv_rx_desc *rx_desc,
1314 struct sk_buff *skb)
1315{
1316 __le32 rsc_enabled;
1317 u32 rsc_cnt;
1318
1319 if (!ring_is_rsc_enabled(rx_ring))
1320 return;
1321
1322 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1323 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1324
1325 /* If this is an RSC frame rsc_cnt should be non-zero */
1326 if (!rsc_enabled)
1327 return;
1328
1329 rsc_cnt = le32_to_cpu(rsc_enabled);
1330 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1331
1332 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001333}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001334
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001335static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1336 struct sk_buff *skb)
1337{
Alexander Duyckf8003262012-03-03 02:35:52 +00001338 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001339
1340 /* set gso_size to avoid messing up TCP MSS */
1341 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1342 IXGBE_CB(skb)->append_cnt);
1343}
1344
1345static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1346 struct sk_buff *skb)
1347{
1348 /* if append_cnt is 0 then frame is not RSC */
1349 if (!IXGBE_CB(skb)->append_cnt)
1350 return;
1351
1352 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1353 rx_ring->rx_stats.rsc_flush++;
1354
1355 ixgbe_set_rsc_gso_size(rx_ring, skb);
1356
1357 /* gso_size is computed using append_cnt so always clear it last */
1358 IXGBE_CB(skb)->append_cnt = 0;
1359}
1360
Alexander Duyck8a0da212012-01-31 02:59:49 +00001361/**
1362 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1363 * @rx_ring: rx descriptor ring packet is being transacted on
1364 * @rx_desc: pointer to the EOP Rx descriptor
1365 * @skb: pointer to current skb being populated
1366 *
1367 * This function checks the ring, descriptor, and packet information in
1368 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1369 * other fields within the skb.
1370 **/
1371static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1372 union ixgbe_adv_rx_desc *rx_desc,
1373 struct sk_buff *skb)
1374{
1375 ixgbe_update_rsc_stats(rx_ring, skb);
1376
1377 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1378
1379 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1380
1381 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1382 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1383 __vlan_hwaccel_put_tag(skb, vid);
1384 }
1385
1386 skb_record_rx_queue(skb, rx_ring->queue_index);
1387
1388 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1389}
1390
1391static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1392 struct sk_buff *skb)
1393{
1394 struct ixgbe_adapter *adapter = q_vector->adapter;
1395
1396 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1397 napi_gro_receive(&q_vector->napi, skb);
1398 else
1399 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001400}
1401
Alexander Duyckf8003262012-03-03 02:35:52 +00001402/**
1403 * ixgbe_is_non_eop - process handling of non-EOP buffers
1404 * @rx_ring: Rx ring being processed
1405 * @rx_desc: Rx descriptor for current buffer
1406 * @skb: Current socket buffer containing buffer in progress
1407 *
1408 * This function updates next to clean. If the buffer is an EOP buffer
1409 * this function exits returning false, otherwise it will place the
1410 * sk_buff in the next buffer to be chained and return true indicating
1411 * that this is in fact a non-EOP buffer.
1412 **/
1413static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1414 union ixgbe_adv_rx_desc *rx_desc,
1415 struct sk_buff *skb)
1416{
1417 u32 ntc = rx_ring->next_to_clean + 1;
1418
1419 /* fetch, update, and store next to clean */
1420 ntc = (ntc < rx_ring->count) ? ntc : 0;
1421 rx_ring->next_to_clean = ntc;
1422
1423 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1424
1425 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1426 return false;
1427
1428 /* append_cnt indicates packet is RSC, if so fetch nextp */
1429 if (IXGBE_CB(skb)->append_cnt) {
1430 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1431 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1432 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1433 }
1434
1435 /* place skb in next buffer to be received */
1436 rx_ring->rx_buffer_info[ntc].skb = skb;
1437 rx_ring->rx_stats.non_eop_descs++;
1438
1439 return true;
1440}
1441
1442/**
1443 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1444 * @rx_ring: rx descriptor ring packet is being transacted on
1445 * @rx_desc: pointer to the EOP Rx descriptor
1446 * @skb: pointer to current skb being fixed
1447 *
1448 * Check for corrupted packet headers caused by senders on the local L2
1449 * embedded NIC switch not setting up their Tx Descriptors right. These
1450 * should be very rare.
1451 *
1452 * Also address the case where we are pulling data in on pages only
1453 * and as such no data is present in the skb header.
1454 *
1455 * In addition if skb is not at least 60 bytes we need to pad it so that
1456 * it is large enough to qualify as a valid Ethernet frame.
1457 *
1458 * Returns true if an error was encountered and skb was freed.
1459 **/
1460static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1461 union ixgbe_adv_rx_desc *rx_desc,
1462 struct sk_buff *skb)
1463{
1464 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1465 struct net_device *netdev = rx_ring->netdev;
1466 unsigned char *va;
1467 unsigned int pull_len;
1468
1469 /* if the page was released unmap it, else just sync our portion */
1470 if (unlikely(IXGBE_CB(skb)->page_released)) {
1471 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1472 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1473 IXGBE_CB(skb)->page_released = false;
1474 } else {
1475 dma_sync_single_range_for_cpu(rx_ring->dev,
1476 IXGBE_CB(skb)->dma,
1477 frag->page_offset,
1478 ixgbe_rx_bufsz(rx_ring),
1479 DMA_FROM_DEVICE);
1480 }
1481 IXGBE_CB(skb)->dma = 0;
1482
1483 /* verify that the packet does not have any known errors */
1484 if (unlikely(ixgbe_test_staterr(rx_desc,
1485 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1486 !(netdev->features & NETIF_F_RXALL))) {
1487 dev_kfree_skb_any(skb);
1488 return true;
1489 }
1490
1491 /*
1492 * it is valid to use page_address instead of kmap since we are
1493 * working with pages allocated out of the lomem pool per
1494 * alloc_page(GFP_ATOMIC)
1495 */
1496 va = skb_frag_address(frag);
1497
1498 /*
1499 * we need the header to contain the greater of either ETH_HLEN or
1500 * 60 bytes if the skb->len is less than 60 for skb_pad.
1501 */
1502 pull_len = skb_frag_size(frag);
1503 if (pull_len > 256)
1504 pull_len = ixgbe_get_headlen(va, pull_len);
1505
1506 /* align pull length to size of long to optimize memcpy performance */
1507 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1508
1509 /* update all of the pointers */
1510 skb_frag_size_sub(frag, pull_len);
1511 frag->page_offset += pull_len;
1512 skb->data_len -= pull_len;
1513 skb->tail += pull_len;
1514
1515 /*
1516 * if we sucked the frag empty then we should free it,
1517 * if there are other frags here something is screwed up in hardware
1518 */
1519 if (skb_frag_size(frag) == 0) {
1520 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1521 skb_shinfo(skb)->nr_frags = 0;
1522 __skb_frag_unref(frag);
1523 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1524 }
1525
1526 /* if skb_pad returns an error the skb was freed */
1527 if (unlikely(skb->len < 60)) {
1528 int pad_len = 60 - skb->len;
1529
1530 if (skb_pad(skb, pad_len))
1531 return true;
1532 __skb_put(skb, pad_len);
1533 }
1534
1535 return false;
1536}
1537
1538/**
1539 * ixgbe_can_reuse_page - determine if we can reuse a page
1540 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1541 *
1542 * Returns true if page can be reused in another Rx buffer
1543 **/
1544static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1545{
1546 struct page *page = rx_buffer->page;
1547
1548 /* if we are only owner of page and it is local we can reuse it */
1549 return likely(page_count(page) == 1) &&
1550 likely(page_to_nid(page) == numa_node_id());
1551}
1552
1553/**
1554 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1555 * @rx_ring: rx descriptor ring to store buffers on
1556 * @old_buff: donor buffer to have page reused
1557 *
1558 * Syncronizes page for reuse by the adapter
1559 **/
1560static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1561 struct ixgbe_rx_buffer *old_buff)
1562{
1563 struct ixgbe_rx_buffer *new_buff;
1564 u16 nta = rx_ring->next_to_alloc;
1565 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1566
1567 new_buff = &rx_ring->rx_buffer_info[nta];
1568
1569 /* update, and store next to alloc */
1570 nta++;
1571 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1572
1573 /* transfer page from old buffer to new buffer */
1574 new_buff->page = old_buff->page;
1575 new_buff->dma = old_buff->dma;
1576
1577 /* flip page offset to other buffer and store to new_buff */
1578 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1579
1580 /* sync the buffer for use by the device */
1581 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1582 new_buff->page_offset, bufsz,
1583 DMA_FROM_DEVICE);
1584
1585 /* bump ref count on page before it is given to the stack */
1586 get_page(new_buff->page);
1587}
1588
1589/**
1590 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1591 * @rx_ring: rx descriptor ring to transact packets on
1592 * @rx_buffer: buffer containing page to add
1593 * @rx_desc: descriptor containing length of buffer written by hardware
1594 * @skb: sk_buff to place the data into
1595 *
1596 * This function is based on skb_add_rx_frag. I would have used that
1597 * function however it doesn't handle the truesize case correctly since we
1598 * are allocating more memory than might be used for a single receive.
1599 **/
1600static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1601 struct ixgbe_rx_buffer *rx_buffer,
1602 struct sk_buff *skb, int size)
1603{
1604 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1605 rx_buffer->page, rx_buffer->page_offset,
1606 size);
1607 skb->len += size;
1608 skb->data_len += size;
1609 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1610}
1611
1612/**
1613 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1614 * @q_vector: structure containing interrupt and ring information
1615 * @rx_ring: rx descriptor ring to transact packets on
1616 * @budget: Total limit on number of packets to process
1617 *
1618 * This function provides a "bounce buffer" approach to Rx interrupt
1619 * processing. The advantage to this is that on systems that have
1620 * expensive overhead for IOMMU access this provides a means of avoiding
1621 * it by maintaining the mapping of the page to the syste.
1622 *
1623 * Returns true if all work is completed without reaching budget
1624 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001625static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001626 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001627 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001628{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001629 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001630#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001631 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001632 int ddp_bytes = 0;
1633#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001634 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001635
Alexander Duyckf8003262012-03-03 02:35:52 +00001636 do {
1637 struct ixgbe_rx_buffer *rx_buffer;
1638 union ixgbe_adv_rx_desc *rx_desc;
1639 struct sk_buff *skb;
1640 struct page *page;
1641 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001642
Alexander Duyckf8003262012-03-03 02:35:52 +00001643 /* return some buffers to hardware, one at a time is too slow */
1644 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1645 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1646 cleaned_count = 0;
1647 }
Auke Kok9a799d72007-09-15 14:07:45 -07001648
Alexander Duyckf8003262012-03-03 02:35:52 +00001649 ntc = rx_ring->next_to_clean;
1650 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1651 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001652
Alexander Duyckf8003262012-03-03 02:35:52 +00001653 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1654 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001655
Alexander Duyckf8003262012-03-03 02:35:52 +00001656 /*
1657 * This memory barrier is needed to keep us from reading
1658 * any other fields out of the rx_desc until we know the
1659 * RXD_STAT_DD bit is set
1660 */
1661 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001662
Alexander Duyckf8003262012-03-03 02:35:52 +00001663 page = rx_buffer->page;
1664 prefetchw(page);
1665
1666 skb = rx_buffer->skb;
1667
1668 if (likely(!skb)) {
1669 void *page_addr = page_address(page) +
1670 rx_buffer->page_offset;
1671
1672 /* prefetch first cache line of first page */
1673 prefetch(page_addr);
1674#if L1_CACHE_BYTES < 128
1675 prefetch(page_addr + L1_CACHE_BYTES);
1676#endif
1677
1678 /* allocate a skb to store the frags */
1679 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1680 IXGBE_RX_HDR_SIZE);
1681 if (unlikely(!skb)) {
1682 rx_ring->rx_stats.alloc_rx_buff_failed++;
1683 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001684 }
1685
Alexander Duyckf8003262012-03-03 02:35:52 +00001686 /*
1687 * we will be copying header into skb->data in
1688 * pskb_may_pull so it is in our interest to prefetch
1689 * it now to avoid a possible cache miss
1690 */
1691 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001692
1693 /*
1694 * Delay unmapping of the first packet. It carries the
1695 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001696 * after the writeback. Only unmap it when EOP is
1697 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001698 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001699 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001700 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001701 /* we are reusing so sync this buffer for CPU use */
1702 dma_sync_single_range_for_cpu(rx_ring->dev,
1703 rx_buffer->dma,
1704 rx_buffer->page_offset,
1705 ixgbe_rx_bufsz(rx_ring),
1706 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001707 }
1708
Alexander Duyckf8003262012-03-03 02:35:52 +00001709 /* pull page into skb */
1710 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1711 le16_to_cpu(rx_desc->wb.upper.length));
1712
1713 if (ixgbe_can_reuse_page(rx_buffer)) {
1714 /* hand second half of page back to the ring */
1715 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1716 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1717 /* the page has been released from the ring */
1718 IXGBE_CB(skb)->page_released = true;
1719 } else {
1720 /* we are not reusing the buffer so unmap it */
1721 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1722 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001723 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001724 }
1725
Alexander Duyckf8003262012-03-03 02:35:52 +00001726 /* clear contents of buffer_info */
1727 rx_buffer->skb = NULL;
1728 rx_buffer->dma = 0;
1729 rx_buffer->page = NULL;
1730
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001731 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1732
Auke Kok9a799d72007-09-15 14:07:45 -07001733 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001734
Alexander Duyckf8003262012-03-03 02:35:52 +00001735 /* place incomplete frames back on ring for completion */
1736 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1737 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001738
Alexander Duyckf8003262012-03-03 02:35:52 +00001739 /* verify the packet layout is correct */
1740 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1741 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001742
1743 /* probably a little skewed due to removing CRC */
1744 total_rx_bytes += skb->len;
1745 total_rx_packets++;
1746
Alexander Duyck8a0da212012-01-31 02:59:49 +00001747 /* populate checksum, timestamp, VLAN, and protocol */
1748 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1749
Yi Zou332d4a72009-05-13 13:11:53 +00001750#ifdef IXGBE_FCOE
1751 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001752 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001753 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001754 if (!ddp_bytes) {
1755 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001756 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001757 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001758 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001759
Yi Zou332d4a72009-05-13 13:11:53 +00001760#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001761 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001762
Alexander Duyckf8003262012-03-03 02:35:52 +00001763 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001764 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001765 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001766
Yi Zou3d8fd382009-06-08 14:38:44 +00001767#ifdef IXGBE_FCOE
1768 /* include DDPed FCoE data */
1769 if (ddp_bytes > 0) {
1770 unsigned int mss;
1771
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001772 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001773 sizeof(struct fc_frame_header) -
1774 sizeof(struct fcoe_crc_eof);
1775 if (mss > 512)
1776 mss &= ~511;
1777 total_rx_bytes += ddp_bytes;
1778 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1779 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001780
Alexander Duyckf8003262012-03-03 02:35:52 +00001781#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001782 u64_stats_update_begin(&rx_ring->syncp);
1783 rx_ring->stats.packets += total_rx_packets;
1784 rx_ring->stats.bytes += total_rx_bytes;
1785 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001786 q_vector->rx.total_packets += total_rx_packets;
1787 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001788
Alexander Duyckf8003262012-03-03 02:35:52 +00001789 if (cleaned_count)
1790 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1791
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001792 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001793}
1794
Auke Kok9a799d72007-09-15 14:07:45 -07001795/**
1796 * ixgbe_configure_msix - Configure MSI-X hardware
1797 * @adapter: board private structure
1798 *
1799 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1800 * interrupts.
1801 **/
1802static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1803{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001804 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001805 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001806 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001807
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001808 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1809
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001810 /* Populate MSIX to EITR Select */
1811 if (adapter->num_vfs > 32) {
1812 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1813 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1814 }
1815
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001816 /*
1817 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001818 * corresponding register.
1819 */
1820 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001821 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001822 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001823
Alexander Duycka5579282012-02-08 07:50:04 +00001824 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001825 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001826
Alexander Duycka5579282012-02-08 07:50:04 +00001827 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001828 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001829
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001830 if (q_vector->tx.ring && !q_vector->rx.ring) {
1831 /* tx only vector */
1832 if (adapter->tx_itr_setting == 1)
1833 q_vector->itr = IXGBE_10K_ITR;
1834 else
1835 q_vector->itr = adapter->tx_itr_setting;
1836 } else {
1837 /* rx or rx/tx vector */
1838 if (adapter->rx_itr_setting == 1)
1839 q_vector->itr = IXGBE_20K_ITR;
1840 else
1841 q_vector->itr = adapter->rx_itr_setting;
1842 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001843
Alexander Duyckfe49f042009-06-04 16:00:09 +00001844 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001845 }
1846
Alexander Duyckbd508172010-11-16 19:27:03 -08001847 switch (adapter->hw.mac.type) {
1848 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001849 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001850 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001851 break;
1852 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001853 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001854 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001855 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001856 default:
1857 break;
1858 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001859 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001860
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001861 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001862 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001863 mask &= ~(IXGBE_EIMS_OTHER |
1864 IXGBE_EIMS_MAILBOX |
1865 IXGBE_EIMS_LSC);
1866
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001867 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001868}
1869
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001870enum latency_range {
1871 lowest_latency = 0,
1872 low_latency = 1,
1873 bulk_latency = 2,
1874 latency_invalid = 255
1875};
1876
1877/**
1878 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001879 * @q_vector: structure containing interrupt and ring information
1880 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001881 *
1882 * Stores a new ITR value based on packets and byte
1883 * counts during the last interrupt. The advantage of per interrupt
1884 * computation is faster updates and more accurate ITR for the current
1885 * traffic pattern. Constants in this function were computed
1886 * based on theoretical maximum wire speed and thresholds were set based
1887 * on testing data as well as attempting to minimize response time
1888 * while increasing bulk throughput.
1889 * this functionality is controlled by the InterruptThrottleRate module
1890 * parameter (see ixgbe_param.c)
1891 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001892static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1893 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001894{
Alexander Duyckbd198052011-06-11 01:45:08 +00001895 int bytes = ring_container->total_bytes;
1896 int packets = ring_container->total_packets;
1897 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001898 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001899 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001900
1901 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001902 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001903
1904 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001905 * 0-10MB/s lowest (100000 ints/s)
1906 * 10-20MB/s low (20000 ints/s)
1907 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001908 */
1909 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001910 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001911 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1912
1913 switch (itr_setting) {
1914 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001915 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001916 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001917 break;
1918 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001919 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001920 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001921 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001922 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001923 break;
1924 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001925 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001926 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001927 break;
1928 }
1929
Alexander Duyckbd198052011-06-11 01:45:08 +00001930 /* clear work counters since we have the values we need */
1931 ring_container->total_bytes = 0;
1932 ring_container->total_packets = 0;
1933
1934 /* write updated itr to ring container */
1935 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001936}
1937
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001938/**
1939 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001940 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001941 *
1942 * This function is made to be called by ethtool and by the driver
1943 * when it needs to update EITR registers at runtime. Hardware
1944 * specific quirks/differences are taken care of here.
1945 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001946void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001947{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001948 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001949 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001950 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001951 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001952
Alexander Duyckbd508172010-11-16 19:27:03 -08001953 switch (adapter->hw.mac.type) {
1954 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001955 /* must write high and low 16 bits to reset counter */
1956 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001957 break;
1958 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001959 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001960 /*
1961 * set the WDIS bit to not clear the timer bits and cause an
1962 * immediate assertion of the interrupt
1963 */
1964 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001965 break;
1966 default:
1967 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001968 }
1969 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1970}
1971
Alexander Duyckbd198052011-06-11 01:45:08 +00001972static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001973{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001974 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001975 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001976
Alexander Duyckbd198052011-06-11 01:45:08 +00001977 ixgbe_update_itr(q_vector, &q_vector->tx);
1978 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001979
Alexander Duyck08c88332011-06-11 01:45:03 +00001980 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001981
1982 switch (current_itr) {
1983 /* counts and packets in update_itr are dependent on these numbers */
1984 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001985 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001986 break;
1987 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001988 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001989 break;
1990 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001991 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001992 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001993 default:
1994 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001995 }
1996
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001997 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001998 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001999 new_itr = (10 * new_itr * q_vector->itr) /
2000 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002001
Alexander Duyckbd198052011-06-11 01:45:08 +00002002 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002003 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002004
2005 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002006 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002007}
2008
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002009/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002010 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002011 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002012 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002013static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002014{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002015 struct ixgbe_hw *hw = &adapter->hw;
2016 u32 eicr = adapter->interrupt_event;
2017
Alexander Duyckf0f97782011-04-22 04:08:09 +00002018 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002019 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002020
Alexander Duyckf0f97782011-04-22 04:08:09 +00002021 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2022 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2023 return;
2024
2025 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2026
Joe Perches7ca647b2010-09-07 21:35:40 +00002027 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002028 case IXGBE_DEV_ID_82599_T3_LOM:
2029 /*
2030 * Since the warning interrupt is for both ports
2031 * we don't have to check if:
2032 * - This interrupt wasn't for our port.
2033 * - We may have missed the interrupt so always have to
2034 * check if we got a LSC
2035 */
2036 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2037 !(eicr & IXGBE_EICR_LSC))
2038 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002039
Alexander Duyckf0f97782011-04-22 04:08:09 +00002040 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2041 u32 autoneg;
2042 bool link_up = false;
2043
Joe Perches7ca647b2010-09-07 21:35:40 +00002044 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2045
Alexander Duyckf0f97782011-04-22 04:08:09 +00002046 if (link_up)
2047 return;
2048 }
2049
2050 /* Check if this is not due to overtemp */
2051 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2052 return;
2053
2054 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002055 default:
2056 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2057 return;
2058 break;
2059 }
2060 e_crit(drv,
2061 "Network adapter has been stopped because it has over heated. "
2062 "Restart the computer. If the problem persists, "
2063 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002064
2065 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002066}
2067
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002068static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2069{
2070 struct ixgbe_hw *hw = &adapter->hw;
2071
2072 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2073 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002074 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002075 /* write to clear the interrupt */
2076 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2077 }
2078}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002079
Jacob Keller4f51bf72011-08-20 04:49:45 +00002080static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2081{
2082 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2083 return;
2084
2085 switch (adapter->hw.mac.type) {
2086 case ixgbe_mac_82599EB:
2087 /*
2088 * Need to check link state so complete overtemp check
2089 * on service task
2090 */
2091 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2092 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2093 adapter->interrupt_event = eicr;
2094 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2095 ixgbe_service_event_schedule(adapter);
2096 return;
2097 }
2098 return;
2099 case ixgbe_mac_X540:
2100 if (!(eicr & IXGBE_EICR_TS))
2101 return;
2102 break;
2103 default:
2104 return;
2105 }
2106
2107 e_crit(drv,
2108 "Network adapter has been stopped because it has over heated. "
2109 "Restart the computer. If the problem persists, "
2110 "power off the system and replace the adapter\n");
2111}
2112
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002113static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2114{
2115 struct ixgbe_hw *hw = &adapter->hw;
2116
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002117 if (eicr & IXGBE_EICR_GPI_SDP2) {
2118 /* Clear the interrupt */
2119 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002120 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2121 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2122 ixgbe_service_event_schedule(adapter);
2123 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002124 }
2125
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002126 if (eicr & IXGBE_EICR_GPI_SDP1) {
2127 /* Clear the interrupt */
2128 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002129 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2130 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2131 ixgbe_service_event_schedule(adapter);
2132 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002133 }
2134}
2135
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002136static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2137{
2138 struct ixgbe_hw *hw = &adapter->hw;
2139
2140 adapter->lsc_int++;
2141 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2142 adapter->link_check_timeout = jiffies;
2143 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2144 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002145 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002146 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002147 }
2148}
2149
Alexander Duyckfe49f042009-06-04 16:00:09 +00002150static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2151 u64 qmask)
2152{
2153 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002154 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002155
Alexander Duyckbd508172010-11-16 19:27:03 -08002156 switch (hw->mac.type) {
2157 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002158 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002159 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2160 break;
2161 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002162 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002163 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002164 if (mask)
2165 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002166 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002167 if (mask)
2168 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2169 break;
2170 default:
2171 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002172 }
2173 /* skip the flush */
2174}
2175
2176static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002177 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002178{
2179 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002180 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002181
Alexander Duyckbd508172010-11-16 19:27:03 -08002182 switch (hw->mac.type) {
2183 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002184 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002185 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2186 break;
2187 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002188 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002189 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002190 if (mask)
2191 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002192 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002193 if (mask)
2194 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2195 break;
2196 default:
2197 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002198 }
2199 /* skip the flush */
2200}
2201
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002202/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002203 * ixgbe_irq_enable - Enable default interrupt generation settings
2204 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002205 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002206static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2207 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002208{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002209 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002210
Alexander Duyck2c4af692011-07-15 07:29:55 +00002211 /* don't reenable LSC while waiting for link */
2212 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2213 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002214
Alexander Duyck2c4af692011-07-15 07:29:55 +00002215 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002216 switch (adapter->hw.mac.type) {
2217 case ixgbe_mac_82599EB:
2218 mask |= IXGBE_EIMS_GPI_SDP0;
2219 break;
2220 case ixgbe_mac_X540:
2221 mask |= IXGBE_EIMS_TS;
2222 break;
2223 default:
2224 break;
2225 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002226 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2227 mask |= IXGBE_EIMS_GPI_SDP1;
2228 switch (adapter->hw.mac.type) {
2229 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002230 mask |= IXGBE_EIMS_GPI_SDP1;
2231 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002232 case ixgbe_mac_X540:
2233 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002234 mask |= IXGBE_EIMS_MAILBOX;
2235 break;
2236 default:
2237 break;
2238 }
2239 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2240 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2241 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002242
Alexander Duyck2c4af692011-07-15 07:29:55 +00002243 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2244 if (queues)
2245 ixgbe_irq_enable_queues(adapter, ~0);
2246 if (flush)
2247 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002248}
2249
Alexander Duyck2c4af692011-07-15 07:29:55 +00002250static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002251{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002252 struct ixgbe_adapter *adapter = data;
2253 struct ixgbe_hw *hw = &adapter->hw;
2254 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002255
Alexander Duyck2c4af692011-07-15 07:29:55 +00002256 /*
2257 * Workaround for Silicon errata. Use clear-by-write instead
2258 * of clear-by-read. Reading with EICS will return the
2259 * interrupt causes without clearing, which later be done
2260 * with the write to EICR.
2261 */
2262 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2263 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002264
Alexander Duyck2c4af692011-07-15 07:29:55 +00002265 if (eicr & IXGBE_EICR_LSC)
2266 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002267
Alexander Duyck2c4af692011-07-15 07:29:55 +00002268 if (eicr & IXGBE_EICR_MAILBOX)
2269 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002270
Alexander Duyck2c4af692011-07-15 07:29:55 +00002271 switch (hw->mac.type) {
2272 case ixgbe_mac_82599EB:
2273 case ixgbe_mac_X540:
2274 if (eicr & IXGBE_EICR_ECC)
2275 e_info(link, "Received unrecoverable ECC Err, please "
2276 "reboot\n");
2277 /* Handle Flow Director Full threshold interrupt */
2278 if (eicr & IXGBE_EICR_FLOW_DIR) {
2279 int reinit_count = 0;
2280 int i;
2281 for (i = 0; i < adapter->num_tx_queues; i++) {
2282 struct ixgbe_ring *ring = adapter->tx_ring[i];
2283 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2284 &ring->state))
2285 reinit_count++;
2286 }
2287 if (reinit_count) {
2288 /* no more flow director interrupts until after init */
2289 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2290 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2291 ixgbe_service_event_schedule(adapter);
2292 }
2293 }
2294 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002295 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002296 break;
2297 default:
2298 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002299 }
2300
Alexander Duyck2c4af692011-07-15 07:29:55 +00002301 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002302
Alexander Duyck2c4af692011-07-15 07:29:55 +00002303 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002304 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002305 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002306
Alexander Duyck2c4af692011-07-15 07:29:55 +00002307 return IRQ_HANDLED;
2308}
2309
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002310static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002311{
2312 struct ixgbe_q_vector *q_vector = data;
2313
Auke Kok9a799d72007-09-15 14:07:45 -07002314 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002315
2316 if (q_vector->rx.ring || q_vector->tx.ring)
2317 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002318
2319 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002320}
2321
Auke Kok9a799d72007-09-15 14:07:45 -07002322/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002323 * ixgbe_poll - NAPI Rx polling callback
2324 * @napi: structure for representing this polling device
2325 * @budget: how many packets driver is allowed to clean
2326 *
2327 * This function is used for legacy and MSI, NAPI mode
2328 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002329int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002330{
2331 struct ixgbe_q_vector *q_vector =
2332 container_of(napi, struct ixgbe_q_vector, napi);
2333 struct ixgbe_adapter *adapter = q_vector->adapter;
2334 struct ixgbe_ring *ring;
2335 int per_ring_budget;
2336 bool clean_complete = true;
2337
2338#ifdef CONFIG_IXGBE_DCA
2339 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2340 ixgbe_update_dca(q_vector);
2341#endif
2342
2343 ixgbe_for_each_ring(ring, q_vector->tx)
2344 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2345
2346 /* attempt to distribute budget to each queue fairly, but don't allow
2347 * the budget to go below 1 because we'll exit polling */
2348 if (q_vector->rx.count > 1)
2349 per_ring_budget = max(budget/q_vector->rx.count, 1);
2350 else
2351 per_ring_budget = budget;
2352
2353 ixgbe_for_each_ring(ring, q_vector->rx)
2354 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2355 per_ring_budget);
2356
2357 /* If all work not completed, return budget and keep polling */
2358 if (!clean_complete)
2359 return budget;
2360
2361 /* all work done, exit the polling mode */
2362 napi_complete(napi);
2363 if (adapter->rx_itr_setting & 1)
2364 ixgbe_set_itr(q_vector);
2365 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2366 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2367
2368 return 0;
2369}
2370
2371/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002372 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2373 * @adapter: board private structure
2374 *
2375 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2376 * interrupts from the kernel.
2377 **/
2378static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2379{
2380 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002381 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2382 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002383 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002384
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002385 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002386 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002387 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002388
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002389 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002390 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002391 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002392 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002393 } else if (q_vector->rx.ring) {
2394 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2395 "%s-%s-%d", netdev->name, "rx", ri++);
2396 } else if (q_vector->tx.ring) {
2397 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2398 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002399 } else {
2400 /* skip this unused q_vector */
2401 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002402 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002403 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2404 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002405 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002406 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002407 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002408 goto free_queue_irqs;
2409 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002410 /* If Flow Director is enabled, set interrupt affinity */
2411 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2412 /* assign the mask for this irq */
2413 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002414 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002415 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002416 }
2417
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002418 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002419 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002420 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002421 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002422 goto free_queue_irqs;
2423 }
2424
2425 return 0;
2426
2427free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002428 while (vector) {
2429 vector--;
2430 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2431 NULL);
2432 free_irq(adapter->msix_entries[vector].vector,
2433 adapter->q_vector[vector]);
2434 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2436 pci_disable_msix(adapter->pdev);
2437 kfree(adapter->msix_entries);
2438 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002439 return err;
2440}
2441
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002442/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002443 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002444 * @irq: interrupt number
2445 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002446 **/
2447static irqreturn_t ixgbe_intr(int irq, void *data)
2448{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002449 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002450 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002451 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002452 u32 eicr;
2453
Don Skidmore54037502009-02-21 15:42:56 -08002454 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002455 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002456 * before the read of EICR.
2457 */
2458 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2459
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002460 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002461 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002462 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002463 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002464 /*
2465 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002466 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002467 * have disabled interrupts due to EIAM
2468 * finish the workaround of silicon errata on 82598. Unmask
2469 * the interrupt that we masked before the EICR read.
2470 */
2471 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2472 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002473 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002474 }
Auke Kok9a799d72007-09-15 14:07:45 -07002475
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002476 if (eicr & IXGBE_EICR_LSC)
2477 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002478
Alexander Duyckbd508172010-11-16 19:27:03 -08002479 switch (hw->mac.type) {
2480 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002481 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002482 /* Fall through */
2483 case ixgbe_mac_X540:
2484 if (eicr & IXGBE_EICR_ECC)
2485 e_info(link, "Received unrecoverable ECC err, please "
2486 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002487 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002488 break;
2489 default:
2490 break;
2491 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002492
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002493 ixgbe_check_fan_failure(adapter, eicr);
2494
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002495 /* would disable interrupts here but EIAM disabled it */
2496 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002497
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002498 /*
2499 * re-enable link(maybe) and non-queue interrupts, no flush.
2500 * ixgbe_poll will re-enable the queue interrupts
2501 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002502 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2503 ixgbe_irq_enable(adapter, false, false);
2504
Auke Kok9a799d72007-09-15 14:07:45 -07002505 return IRQ_HANDLED;
2506}
2507
2508/**
2509 * ixgbe_request_irq - initialize interrupts
2510 * @adapter: board private structure
2511 *
2512 * Attempts to configure interrupts using the best available
2513 * capabilities of the hardware and kernel.
2514 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002515static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002516{
2517 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002518 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002519
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002520 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002521 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002522 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002523 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002524 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002525 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002526 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002527 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002528
Alexander Duyckde88eee2012-02-08 07:49:59 +00002529 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002530 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002531
Auke Kok9a799d72007-09-15 14:07:45 -07002532 return err;
2533}
2534
2535static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2536{
Auke Kok9a799d72007-09-15 14:07:45 -07002537 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002538 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002539
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002540 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002541 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002542 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002543 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002544
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002545 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002546 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002547 if (!adapter->q_vector[i]->rx.ring &&
2548 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002549 continue;
2550
Alexander Duyck207867f2011-07-15 03:05:37 +00002551 /* clear the affinity_mask in the IRQ descriptor */
2552 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2553 NULL);
2554
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002555 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002556 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002559 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002560 }
2561}
2562
2563/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002564 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2565 * @adapter: board private structure
2566 **/
2567static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2568{
Alexander Duyckbd508172010-11-16 19:27:03 -08002569 switch (adapter->hw.mac.type) {
2570 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002571 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002572 break;
2573 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002574 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002575 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2576 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002577 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002578 break;
2579 default:
2580 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002581 }
2582 IXGBE_WRITE_FLUSH(&adapter->hw);
2583 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2584 int i;
2585 for (i = 0; i < adapter->num_msix_vectors; i++)
2586 synchronize_irq(adapter->msix_entries[i].vector);
2587 } else {
2588 synchronize_irq(adapter->pdev->irq);
2589 }
2590}
2591
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002592/**
Auke Kok9a799d72007-09-15 14:07:45 -07002593 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2594 *
2595 **/
2596static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2597{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002598 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002599
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002600 /* rx/tx vector */
2601 if (adapter->rx_itr_setting == 1)
2602 q_vector->itr = IXGBE_20K_ITR;
2603 else
2604 q_vector->itr = adapter->rx_itr_setting;
2605
2606 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002607
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002608 ixgbe_set_ivar(adapter, 0, 0, 0);
2609 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002610
Emil Tantilov396e7992010-07-01 20:05:12 +00002611 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002612}
2613
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002614/**
2615 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2616 * @adapter: board private structure
2617 * @ring: structure containing ring specific data
2618 *
2619 * Configure the Tx descriptor ring after a reset.
2620 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002621void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2622 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002623{
2624 struct ixgbe_hw *hw = &adapter->hw;
2625 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002626 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002627 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002628 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002629
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002630 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002631 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002632 IXGBE_WRITE_FLUSH(hw);
2633
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002634 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002635 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002636 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2637 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2638 ring->count * sizeof(union ixgbe_adv_tx_desc));
2639 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2640 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002641 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002642
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002643 /*
2644 * set WTHRESH to encourage burst writeback, it should not be set
2645 * higher than 1 when ITR is 0 as it could cause false TX hangs
2646 *
2647 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2648 * to or less than the number of on chip descriptors, which is
2649 * currently 40.
2650 */
Alexander Duycke954b372012-02-08 07:49:38 +00002651 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002652 txdctl |= (1 << 16); /* WTHRESH = 1 */
2653 else
2654 txdctl |= (8 << 16); /* WTHRESH = 8 */
2655
Alexander Duycke954b372012-02-08 07:49:38 +00002656 /*
2657 * Setting PTHRESH to 32 both improves performance
2658 * and avoids a TX hang with DFP enabled
2659 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002660 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2661 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002662
2663 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002664 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2665 adapter->atr_sample_rate) {
2666 ring->atr_sample_rate = adapter->atr_sample_rate;
2667 ring->atr_count = 0;
2668 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2669 } else {
2670 ring->atr_sample_rate = 0;
2671 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002672
John Fastabendc84d3242010-11-16 19:27:12 -08002673 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2674
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002675 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002676 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2677
2678 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2679 if (hw->mac.type == ixgbe_mac_82598EB &&
2680 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2681 return;
2682
2683 /* poll to verify queue is enabled */
2684 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002685 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002686 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2687 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2688 if (!wait_loop)
2689 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002690}
2691
Alexander Duyck120ff942010-08-19 13:34:50 +00002692static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2693{
2694 struct ixgbe_hw *hw = &adapter->hw;
2695 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002696 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002697 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002698
2699 if (hw->mac.type == ixgbe_mac_82598EB)
2700 return;
2701
2702 /* disable the arbiter while setting MTQC */
2703 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2704 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2705 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2706
2707 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002708 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002709 case (IXGBE_FLAG_SRIOV_ENABLED):
2710 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2711 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2712 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002713 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002714 if (!tcs)
2715 reg = IXGBE_MTQC_64Q_1PB;
2716 else if (tcs <= 4)
2717 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2718 else
2719 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2720
2721 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2722
2723 /* Enable Security TX Buffer IFG for multiple pb */
2724 if (tcs) {
2725 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2726 reg |= IXGBE_SECTX_DCB;
2727 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2728 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002729 break;
2730 }
2731
2732 /* re-enable the arbiter */
2733 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2734 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2735}
2736
Auke Kok9a799d72007-09-15 14:07:45 -07002737/**
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07002738 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002739 * @adapter: board private structure
2740 *
2741 * Configure the Tx unit of the MAC after a reset.
2742 **/
2743static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2744{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002745 struct ixgbe_hw *hw = &adapter->hw;
2746 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002747 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002748
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002749 ixgbe_setup_mtqc(adapter);
2750
2751 if (hw->mac.type != ixgbe_mac_82598EB) {
2752 /* DMATXCTL.EN must be before Tx queues are enabled */
2753 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2754 dmatxctl |= IXGBE_DMATXCTL_TE;
2755 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2756 }
2757
Auke Kok9a799d72007-09-15 14:07:45 -07002758 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002759 for (i = 0; i < adapter->num_tx_queues; i++)
2760 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002761}
2762
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002763#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002764
Yi Zoua6616b42009-08-06 13:05:23 +00002765static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002766 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002767{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002768 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002769 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002770
Alexander Duyckbd508172010-11-16 19:27:03 -08002771 switch (adapter->hw.mac.type) {
2772 case ixgbe_mac_82598EB: {
2773 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2774 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002775 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002776 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002777 break;
2778 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002779 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002780 default:
2781 break;
2782 }
2783
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002784 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002785
2786 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2787 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002788 if (adapter->num_vfs)
2789 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002790
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002791 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2792 IXGBE_SRRCTL_BSIZEHDR_MASK;
2793
Alexander Duyckf8003262012-03-03 02:35:52 +00002794#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2795 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002796#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002797 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002798#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002799 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002800
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002801 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002802}
2803
Alexander Duyck05abb122010-08-19 13:35:41 +00002804static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002805{
Alexander Duyck05abb122010-08-19 13:35:41 +00002806 struct ixgbe_hw *hw = &adapter->hw;
2807 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002808 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2809 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002810 u32 mrqc = 0, reta = 0;
2811 u32 rxcsum;
2812 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002813 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002814 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2815
2816 if (tcs)
2817 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002818
Alexander Duyck05abb122010-08-19 13:35:41 +00002819 /* Fill out hash function seeds */
2820 for (i = 0; i < 10; i++)
2821 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002822
Alexander Duyck05abb122010-08-19 13:35:41 +00002823 /* Fill out redirection table */
2824 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002825 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002826 j = 0;
2827 /* reta = 4-byte sliding window of
2828 * 0x00..(indices-1)(indices-1)00..etc. */
2829 reta = (reta << 8) | (j * 0x11);
2830 if ((i & 3) == 3)
2831 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2832 }
2833
2834 /* Disable indicating checksum in descriptor, enables RSS hash */
2835 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2836 rxcsum |= IXGBE_RXCSUM_PCSD;
2837 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2838
John Fastabend8b1c0b22011-05-03 02:26:48 +00002839 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2840 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002841 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002842 } else {
2843 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2844 | IXGBE_FLAG_SRIOV_ENABLED);
2845
2846 switch (mask) {
2847 case (IXGBE_FLAG_RSS_ENABLED):
2848 if (!tcs)
2849 mrqc = IXGBE_MRQC_RSSEN;
2850 else if (tcs <= 4)
2851 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2852 else
2853 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2854 break;
2855 case (IXGBE_FLAG_SRIOV_ENABLED):
2856 mrqc = IXGBE_MRQC_VMDQEN;
2857 break;
2858 default:
2859 break;
2860 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002861 }
2862
Alexander Duyck05abb122010-08-19 13:35:41 +00002863 /* Perform hash on these packet types */
2864 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2865 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2866 | IXGBE_MRQC_RSS_FIELD_IPV6
2867 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2868
Alexander Duyckef6afc02012-02-08 07:51:53 +00002869 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2870 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
2871 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2872 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2873
Alexander Duyck05abb122010-08-19 13:35:41 +00002874 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002875}
2876
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002877/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002878 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2879 * @adapter: address of board private structure
2880 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002881 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002882static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002883 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002884{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002885 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002886 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002887 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002888
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002889 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002890 return;
2891
Alexander Duyck73670962010-08-19 13:38:34 +00002892 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002893 rscctrl |= IXGBE_RSCCTL_RSCEN;
2894 /*
2895 * we must limit the number of descriptors so that the
2896 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002897 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002898 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002899#if (PAGE_SIZE <= 8192)
2900 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2901#elif (PAGE_SIZE <= 16384)
2902 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002903#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002904 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002905#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002906 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002907}
2908
Alexander Duyck9e10e042010-08-19 13:40:06 +00002909#define IXGBE_MAX_RX_DESC_POLL 10
2910static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2911 struct ixgbe_ring *ring)
2912{
2913 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002914 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2915 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002916 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002917
2918 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2919 if (hw->mac.type == ixgbe_mac_82598EB &&
2920 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2921 return;
2922
2923 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002924 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002925 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2926 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2927
2928 if (!wait_loop) {
2929 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2930 "the polling period\n", reg_idx);
2931 }
2932}
2933
Yi Zou2d39d572011-01-06 14:29:56 +00002934void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2935 struct ixgbe_ring *ring)
2936{
2937 struct ixgbe_hw *hw = &adapter->hw;
2938 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2939 u32 rxdctl;
2940 u8 reg_idx = ring->reg_idx;
2941
2942 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2943 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2944
2945 /* write value back with RXDCTL.ENABLE bit cleared */
2946 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2947
2948 if (hw->mac.type == ixgbe_mac_82598EB &&
2949 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2950 return;
2951
2952 /* the hardware may take up to 100us to really disable the rx queue */
2953 do {
2954 udelay(10);
2955 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2956 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2957
2958 if (!wait_loop) {
2959 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2960 "the polling period\n", reg_idx);
2961 }
2962}
2963
Alexander Duyck84418e32010-08-19 13:40:54 +00002964void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2965 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002966{
2967 struct ixgbe_hw *hw = &adapter->hw;
2968 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002969 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002970 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002971
Alexander Duyck9e10e042010-08-19 13:40:06 +00002972 /* disable queue to avoid issues while updating state */
2973 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002974 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002975
Alexander Duyckacd37172010-08-19 13:36:05 +00002976 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2977 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2978 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2979 ring->count * sizeof(union ixgbe_adv_rx_desc));
2980 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2981 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002982 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002983
2984 ixgbe_configure_srrctl(adapter, ring);
2985 ixgbe_configure_rscctl(adapter, ring);
2986
Greg Rosee9f98072011-01-26 01:06:07 +00002987 /* If operating in IOV mode set RLPML for X540 */
2988 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2989 hw->mac.type == ixgbe_mac_X540) {
2990 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2991 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2992 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2993 }
2994
Alexander Duyck9e10e042010-08-19 13:40:06 +00002995 if (hw->mac.type == ixgbe_mac_82598EB) {
2996 /*
2997 * enable cache line friendly hardware writes:
2998 * PTHRESH=32 descriptors (half the internal cache),
2999 * this also removes ugly rx_no_buffer_count increment
3000 * HTHRESH=4 descriptors (to minimize latency on fetch)
3001 * WTHRESH=8 burst writeback up to two cache lines
3002 */
3003 rxdctl &= ~0x3FFFFF;
3004 rxdctl |= 0x080420;
3005 }
3006
3007 /* enable receive descriptor ring */
3008 rxdctl |= IXGBE_RXDCTL_ENABLE;
3009 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3010
3011 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003012 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003013}
3014
Alexander Duyck48654522010-08-19 13:36:27 +00003015static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3016{
3017 struct ixgbe_hw *hw = &adapter->hw;
3018 int p;
3019
3020 /* PSRTYPE must be initialized in non 82598 adapters */
3021 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003022 IXGBE_PSRTYPE_UDPHDR |
3023 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003024 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003025 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003026
3027 if (hw->mac.type == ixgbe_mac_82598EB)
3028 return;
3029
3030 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3031 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3032
3033 for (p = 0; p < adapter->num_rx_pools; p++)
3034 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3035 psrtype);
3036}
3037
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003038static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3039{
3040 struct ixgbe_hw *hw = &adapter->hw;
3041 u32 gcr_ext;
3042 u32 vt_reg_bits;
3043 u32 reg_offset, vf_shift;
3044 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003045 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003046
3047 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3048 return;
3049
3050 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3051 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3052 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3053 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3054
3055 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00003056 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003057
3058 /* Enable only the PF's pool for Tx/Rx */
3059 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3060 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3061 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3062 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3063 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3064
3065 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3066 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3067
3068 /*
3069 * Set up VF register offsets for selected VT Mode,
3070 * i.e. 32 or 64 VFs for SR-IOV
3071 */
3072 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3073 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3074 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3075 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3076
3077 /* enable Tx loopback for VF/PF communication */
3078 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003079 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003080 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003081 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003082 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003083 /* For VFs that have spoof checking turned off */
3084 for (i = 0; i < adapter->num_vfs; i++) {
3085 if (!adapter->vfinfo[i].spoofchk_enabled)
3086 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3087 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003088}
3089
Alexander Duyck477de6e2010-08-19 13:38:11 +00003090static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003091{
Auke Kok9a799d72007-09-15 14:07:45 -07003092 struct ixgbe_hw *hw = &adapter->hw;
3093 struct net_device *netdev = adapter->netdev;
3094 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003095 struct ixgbe_ring *rx_ring;
3096 int i;
3097 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003098
Alexander Duyck477de6e2010-08-19 13:38:11 +00003099#ifdef IXGBE_FCOE
3100 /* adjust max frame to be able to do baby jumbo for FCoE */
3101 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3102 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3103 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3104
3105#endif /* IXGBE_FCOE */
3106 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3107 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3108 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3109 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3110
3111 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003112 }
3113
Alexander Duyck919e78a2011-08-26 09:52:38 +00003114 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3115 max_frame += VLAN_HLEN;
3116
Auke Kok9a799d72007-09-15 14:07:45 -07003117 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003118 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3119 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003120 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3121
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003122 /*
3123 * Setup the HW Rx Head and Tail Descriptor Pointers and
3124 * the Base and Length of the Rx Descriptor Ring
3125 */
Auke Kok9a799d72007-09-15 14:07:45 -07003126 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003127 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003128 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3129 set_ring_rsc_enabled(rx_ring);
3130 else
3131 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003132 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003133}
3134
Alexander Duyck73670962010-08-19 13:38:34 +00003135static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3136{
3137 struct ixgbe_hw *hw = &adapter->hw;
3138 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3139
3140 switch (hw->mac.type) {
3141 case ixgbe_mac_82598EB:
3142 /*
3143 * For VMDq support of different descriptor types or
3144 * buffer sizes through the use of multiple SRRCTL
3145 * registers, RDRXCTL.MVMEN must be set to 1
3146 *
3147 * also, the manual doesn't mention it clearly but DCA hints
3148 * will only use queue 0's tags unless this bit is set. Side
3149 * effects of setting this bit are only that SRRCTL must be
3150 * fully programmed [0..15]
3151 */
3152 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3153 break;
3154 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003155 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003156 /* Disable RSC for ACK packets */
3157 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3158 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3159 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3160 /* hardware requires some bits to be set by default */
3161 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3162 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3163 break;
3164 default:
3165 /* We should do nothing since we don't know this hardware */
3166 return;
3167 }
3168
3169 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3170}
3171
Alexander Duyck477de6e2010-08-19 13:38:11 +00003172/**
3173 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3174 * @adapter: board private structure
3175 *
3176 * Configure the Rx unit of the MAC after a reset.
3177 **/
3178static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3179{
3180 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003181 int i;
3182 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003183
3184 /* disable receives while setting up the descriptors */
3185 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3186 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3187
3188 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003189 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003190
Alexander Duyck9e10e042010-08-19 13:40:06 +00003191 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003192 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003193
Alexander Duyck477de6e2010-08-19 13:38:11 +00003194 /* set_rx_buffer_len must be called before ring initialization */
3195 ixgbe_set_rx_buffer_len(adapter);
3196
3197 /*
3198 * Setup the HW Rx Head and Tail Descriptor Pointers and
3199 * the Base and Length of the Rx Descriptor Ring
3200 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003201 for (i = 0; i < adapter->num_rx_queues; i++)
3202 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003203
Alexander Duyck9e10e042010-08-19 13:40:06 +00003204 /* disable drop enable for 82598 parts */
3205 if (hw->mac.type == ixgbe_mac_82598EB)
3206 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3207
3208 /* enable all receives */
3209 rxctrl |= IXGBE_RXCTRL_RXEN;
3210 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003211}
3212
Jiri Pirko8e586132011-12-08 19:52:37 -05003213static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003214{
3215 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003216 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003217 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003218
3219 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003220 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003221 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003222
3223 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003224}
3225
Jiri Pirko8e586132011-12-08 19:52:37 -05003226static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003227{
3228 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003229 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003230 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003231
Auke Kok9a799d72007-09-15 14:07:45 -07003232 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003233 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003234 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003235
3236 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003237}
3238
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003239/**
3240 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3241 * @adapter: driver data
3242 */
3243static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3244{
3245 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003246 u32 vlnctrl;
3247
3248 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3249 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3250 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3251}
3252
3253/**
3254 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3255 * @adapter: driver data
3256 */
3257static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3258{
3259 struct ixgbe_hw *hw = &adapter->hw;
3260 u32 vlnctrl;
3261
3262 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3263 vlnctrl |= IXGBE_VLNCTRL_VFE;
3264 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3265 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3266}
3267
3268/**
3269 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3270 * @adapter: driver data
3271 */
3272static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3273{
3274 struct ixgbe_hw *hw = &adapter->hw;
3275 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003276 int i, j;
3277
3278 switch (hw->mac.type) {
3279 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003280 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3281 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003282 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3283 break;
3284 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003285 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003286 for (i = 0; i < adapter->num_rx_queues; i++) {
3287 j = adapter->rx_ring[i]->reg_idx;
3288 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3289 vlnctrl &= ~IXGBE_RXDCTL_VME;
3290 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3291 }
3292 break;
3293 default:
3294 break;
3295 }
3296}
3297
3298/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003299 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003300 * @adapter: driver data
3301 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003302static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003303{
3304 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003305 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003306 int i, j;
3307
3308 switch (hw->mac.type) {
3309 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003310 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3311 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003312 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3313 break;
3314 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003315 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003316 for (i = 0; i < adapter->num_rx_queues; i++) {
3317 j = adapter->rx_ring[i]->reg_idx;
3318 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3319 vlnctrl |= IXGBE_RXDCTL_VME;
3320 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3321 }
3322 break;
3323 default:
3324 break;
3325 }
3326}
3327
Auke Kok9a799d72007-09-15 14:07:45 -07003328static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3329{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003330 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003331
Jesse Grossf62bbb52010-10-20 13:56:10 +00003332 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3333
3334 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3335 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003336}
3337
3338/**
Alexander Duyck28500622010-06-15 09:25:48 +00003339 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3340 * @netdev: network interface device structure
3341 *
3342 * Writes unicast address list to the RAR table.
3343 * Returns: -ENOMEM on failure/insufficient address space
3344 * 0 on no addresses written
3345 * X on writing X addresses to the RAR table
3346 **/
3347static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3348{
3349 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3350 struct ixgbe_hw *hw = &adapter->hw;
3351 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003352 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003353 int count = 0;
3354
3355 /* return ENOMEM indicating insufficient memory for addresses */
3356 if (netdev_uc_count(netdev) > rar_entries)
3357 return -ENOMEM;
3358
3359 if (!netdev_uc_empty(netdev) && rar_entries) {
3360 struct netdev_hw_addr *ha;
3361 /* return error if we do not support writing to RAR table */
3362 if (!hw->mac.ops.set_rar)
3363 return -ENOMEM;
3364
3365 netdev_for_each_uc_addr(ha, netdev) {
3366 if (!rar_entries)
3367 break;
3368 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3369 vfn, IXGBE_RAH_AV);
3370 count++;
3371 }
3372 }
3373 /* write the addresses in reverse order to avoid write combining */
3374 for (; rar_entries > 0 ; rar_entries--)
3375 hw->mac.ops.clear_rar(hw, rar_entries);
3376
3377 return count;
3378}
3379
3380/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003381 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003382 * @netdev: network interface device structure
3383 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003384 * The set_rx_method entry point is called whenever the unicast/multicast
3385 * address list or the network interface flags are updated. This routine is
3386 * responsible for configuring the hardware for proper unicast, multicast and
3387 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003388 **/
Greg Rose7f870472010-01-09 02:25:29 +00003389void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003390{
3391 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3392 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003393 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3394 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003395
3396 /* Check for Promiscuous and All Multicast modes */
3397
3398 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3399
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003400 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003401 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003402 fctrl |= IXGBE_FCTRL_BAM;
3403 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3404 fctrl |= IXGBE_FCTRL_PMCF;
3405
Alexander Duyck28500622010-06-15 09:25:48 +00003406 /* clear the bits we are changing the status of */
3407 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3408
Auke Kok9a799d72007-09-15 14:07:45 -07003409 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003410 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003411 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003412 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003413 /* don't hardware filter vlans in promisc mode */
3414 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003415 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003416 if (netdev->flags & IFF_ALLMULTI) {
3417 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003418 vmolr |= IXGBE_VMOLR_MPE;
3419 } else {
3420 /*
3421 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003422 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003423 * that we can at least receive multicast traffic
3424 */
3425 hw->mac.ops.update_mc_addr_list(hw, netdev);
3426 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003427 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003428 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003429 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003430 }
3431
3432 /*
3433 * Write addresses to available RAR registers, if there is not
3434 * sufficient space to store all the addresses then enable
3435 * unicast promiscuous mode
3436 */
3437 count = ixgbe_write_uc_addr_list(netdev);
3438 if (count < 0) {
3439 fctrl |= IXGBE_FCTRL_UPE;
3440 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003441 }
3442
3443 if (adapter->num_vfs) {
3444 ixgbe_restore_vf_multicasts(adapter);
3445 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3446 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3447 IXGBE_VMOLR_ROPE);
3448 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003449 }
3450
Ben Greear3f2d1c02012-03-08 08:28:41 +00003451 /* This is useful for sniffing bad packets. */
3452 if (adapter->netdev->features & NETIF_F_RXALL) {
3453 /* UPE and MPE will be handled by normal PROMISC logic
3454 * in e1000e_set_rx_mode */
3455 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3456 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3457 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3458
3459 fctrl &= ~(IXGBE_FCTRL_DPF);
3460 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3461 }
3462
Auke Kok9a799d72007-09-15 14:07:45 -07003463 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003464
3465 if (netdev->features & NETIF_F_HW_VLAN_RX)
3466 ixgbe_vlan_strip_enable(adapter);
3467 else
3468 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003469}
3470
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003471static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3472{
3473 int q_idx;
3474 struct ixgbe_q_vector *q_vector;
3475 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3476
3477 /* legacy and MSI only use one vector */
3478 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3479 q_vectors = 1;
3480
3481 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003482 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003483 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003484 }
3485}
3486
3487static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3488{
3489 int q_idx;
3490 struct ixgbe_q_vector *q_vector;
3491 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3492
3493 /* legacy and MSI only use one vector */
3494 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3495 q_vectors = 1;
3496
3497 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003498 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003499 napi_disable(&q_vector->napi);
3500 }
3501}
3502
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003503#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003504/*
3505 * ixgbe_configure_dcb - Configure DCB hardware
3506 * @adapter: ixgbe adapter struct
3507 *
3508 * This is called by the driver on open to configure the DCB hardware.
3509 * This is also called by the gennetlink interface when reconfiguring
3510 * the DCB state.
3511 */
3512static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3513{
3514 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003515 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003516
Alexander Duyck67ebd792010-08-19 13:34:04 +00003517 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3518 if (hw->mac.type == ixgbe_mac_82598EB)
3519 netif_set_gso_max_size(adapter->netdev, 65536);
3520 return;
3521 }
3522
3523 if (hw->mac.type == ixgbe_mac_82598EB)
3524 netif_set_gso_max_size(adapter->netdev, 32768);
3525
Alexander Duyck2f90b862008-11-20 20:52:10 -08003526
Alexander Duyck2f90b862008-11-20 20:52:10 -08003527 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003528 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003529
Alexander Duyck2f90b862008-11-20 20:52:10 -08003530 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003531
John Fastabendb1208182011-10-15 05:00:10 +00003532#ifdef IXGBE_FCOE
3533 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3534 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3535#endif
3536
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003537 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003538 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003539 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3540 DCB_TX_CONFIG);
3541 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3542 DCB_RX_CONFIG);
3543 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003544 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3545 ixgbe_dcb_hw_ets(&adapter->hw,
3546 adapter->ixgbe_ieee_ets,
3547 max_frame);
3548 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3549 adapter->ixgbe_ieee_pfc->pfc_en,
3550 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003551 }
John Fastabend8187cd42011-02-23 05:58:08 +00003552
3553 /* Enable RSS Hash per TC */
3554 if (hw->mac.type != ixgbe_mac_82598EB) {
3555 int i;
3556 u32 reg = 0;
3557
3558 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3559 u8 msb = 0;
3560 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3561
3562 while (cnt >>= 1)
3563 msb++;
3564
3565 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3566 }
3567 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3568 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003569}
John Fastabend9da712d2011-08-23 03:14:22 +00003570#endif
3571
3572/* Additional bittime to account for IXGBE framing */
3573#define IXGBE_ETH_FRAMING 20
3574
3575/*
3576 * ixgbe_hpbthresh - calculate high water mark for flow control
3577 *
3578 * @adapter: board private structure to calculate for
3579 * @pb - packet buffer to calculate
3580 */
3581static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3582{
3583 struct ixgbe_hw *hw = &adapter->hw;
3584 struct net_device *dev = adapter->netdev;
3585 int link, tc, kb, marker;
3586 u32 dv_id, rx_pba;
3587
3588 /* Calculate max LAN frame size */
3589 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3590
3591#ifdef IXGBE_FCOE
3592 /* FCoE traffic class uses FCOE jumbo frames */
3593 if (dev->features & NETIF_F_FCOE_MTU) {
3594 int fcoe_pb = 0;
3595
3596#ifdef CONFIG_IXGBE_DCB
3597 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003598
3599#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003600 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3601 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3602 }
3603#endif
3604
3605 /* Calculate delay value for device */
3606 switch (hw->mac.type) {
3607 case ixgbe_mac_X540:
3608 dv_id = IXGBE_DV_X540(link, tc);
3609 break;
3610 default:
3611 dv_id = IXGBE_DV(link, tc);
3612 break;
3613 }
3614
3615 /* Loopback switch introduces additional latency */
3616 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3617 dv_id += IXGBE_B2BT(tc);
3618
3619 /* Delay value is calculated in bit times convert to KB */
3620 kb = IXGBE_BT2KB(dv_id);
3621 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3622
3623 marker = rx_pba - kb;
3624
3625 /* It is possible that the packet buffer is not large enough
3626 * to provide required headroom. In this case throw an error
3627 * to user and a do the best we can.
3628 */
3629 if (marker < 0) {
3630 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3631 "headroom to support flow control."
3632 "Decrease MTU or number of traffic classes\n", pb);
3633 marker = tc + 1;
3634 }
3635
3636 return marker;
3637}
3638
3639/*
3640 * ixgbe_lpbthresh - calculate low water mark for for flow control
3641 *
3642 * @adapter: board private structure to calculate for
3643 * @pb - packet buffer to calculate
3644 */
3645static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3646{
3647 struct ixgbe_hw *hw = &adapter->hw;
3648 struct net_device *dev = adapter->netdev;
3649 int tc;
3650 u32 dv_id;
3651
3652 /* Calculate max LAN frame size */
3653 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3654
3655 /* Calculate delay value for device */
3656 switch (hw->mac.type) {
3657 case ixgbe_mac_X540:
3658 dv_id = IXGBE_LOW_DV_X540(tc);
3659 break;
3660 default:
3661 dv_id = IXGBE_LOW_DV(tc);
3662 break;
3663 }
3664
3665 /* Delay value is calculated in bit times convert to KB */
3666 return IXGBE_BT2KB(dv_id);
3667}
3668
3669/*
3670 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3671 */
3672static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3673{
3674 struct ixgbe_hw *hw = &adapter->hw;
3675 int num_tc = netdev_get_num_tc(adapter->netdev);
3676 int i;
3677
3678 if (!num_tc)
3679 num_tc = 1;
3680
3681 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3682
3683 for (i = 0; i < num_tc; i++) {
3684 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3685
3686 /* Low water marks must not be larger than high water marks */
3687 if (hw->fc.low_water > hw->fc.high_water[i])
3688 hw->fc.low_water = 0;
3689 }
3690}
John Fastabend80605c652011-05-02 12:34:10 +00003691
3692static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3693{
John Fastabend80605c652011-05-02 12:34:10 +00003694 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003695 int hdrm;
3696 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003697
3698 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3699 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003700 hdrm = 32 << adapter->fdir_pballoc;
3701 else
3702 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003703
Alexander Duyckf7e10272011-07-21 00:40:35 +00003704 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003705 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003706}
3707
Alexander Duycke4911d52011-05-11 07:18:52 +00003708static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3709{
3710 struct ixgbe_hw *hw = &adapter->hw;
3711 struct hlist_node *node, *node2;
3712 struct ixgbe_fdir_filter *filter;
3713
3714 spin_lock(&adapter->fdir_perfect_lock);
3715
3716 if (!hlist_empty(&adapter->fdir_filter_list))
3717 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3718
3719 hlist_for_each_entry_safe(filter, node, node2,
3720 &adapter->fdir_filter_list, fdir_node) {
3721 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003722 &filter->filter,
3723 filter->sw_idx,
3724 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3725 IXGBE_FDIR_DROP_QUEUE :
3726 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003727 }
3728
3729 spin_unlock(&adapter->fdir_perfect_lock);
3730}
3731
Auke Kok9a799d72007-09-15 14:07:45 -07003732static void ixgbe_configure(struct ixgbe_adapter *adapter)
3733{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003734 struct ixgbe_hw *hw = &adapter->hw;
3735
John Fastabend80605c652011-05-02 12:34:10 +00003736 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003737#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003738 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003739#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003740
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003741 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003742 ixgbe_restore_vlan(adapter);
3743
Yi Zoueacd73f2009-05-13 13:11:06 +00003744#ifdef IXGBE_FCOE
3745 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3746 ixgbe_configure_fcoe(adapter);
3747
3748#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003749
3750 switch (hw->mac.type) {
3751 case ixgbe_mac_82599EB:
3752 case ixgbe_mac_X540:
3753 hw->mac.ops.disable_rx_buff(hw);
3754 break;
3755 default:
3756 break;
3757 }
3758
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003759 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003760 ixgbe_init_fdir_signature_82599(&adapter->hw,
3761 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003762 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3763 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3764 adapter->fdir_pballoc);
3765 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003766 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003767
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003768 switch (hw->mac.type) {
3769 case ixgbe_mac_82599EB:
3770 case ixgbe_mac_X540:
3771 hw->mac.ops.enable_rx_buff(hw);
3772 break;
3773 default:
3774 break;
3775 }
3776
Alexander Duyck933d41f2010-09-07 21:34:29 +00003777 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003778
Auke Kok9a799d72007-09-15 14:07:45 -07003779 ixgbe_configure_tx(adapter);
3780 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003781}
3782
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003783static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3784{
3785 switch (hw->phy.type) {
3786 case ixgbe_phy_sfp_avago:
3787 case ixgbe_phy_sfp_ftl:
3788 case ixgbe_phy_sfp_intel:
3789 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003790 case ixgbe_phy_sfp_passive_tyco:
3791 case ixgbe_phy_sfp_passive_unknown:
3792 case ixgbe_phy_sfp_active_unknown:
3793 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003794 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003795 case ixgbe_phy_nl:
3796 if (hw->mac.type == ixgbe_mac_82598EB)
3797 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003798 default:
3799 return false;
3800 }
3801}
3802
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003803/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003804 * ixgbe_sfp_link_config - set up SFP+ link
3805 * @adapter: pointer to private adapter struct
3806 **/
3807static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3808{
Alexander Duyck70864002011-04-27 09:13:56 +00003809 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003810 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003811 * is that an SFP was inserted/removed after the reset
3812 * but before SFP detection was enabled. As such the best
3813 * solution is to just start searching as soon as we start
3814 */
3815 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3816 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003817
Alexander Duyck70864002011-04-27 09:13:56 +00003818 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003819}
3820
3821/**
3822 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003823 * @hw: pointer to private hardware struct
3824 *
3825 * Returns 0 on success, negative on failure
3826 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003827static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003828{
3829 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003830 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003831 u32 ret = IXGBE_ERR_LINK_SETUP;
3832
3833 if (hw->mac.ops.check_link)
3834 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3835
3836 if (ret)
3837 goto link_cfg_out;
3838
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003839 autoneg = hw->phy.autoneg_advertised;
3840 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003841 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3842 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003843 if (ret)
3844 goto link_cfg_out;
3845
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003846 if (hw->mac.ops.setup_link)
3847 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003848link_cfg_out:
3849 return ret;
3850}
3851
Alexander Duycka34bcff2010-08-19 13:39:20 +00003852static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003853{
Auke Kok9a799d72007-09-15 14:07:45 -07003854 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003855 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003856
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003857 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003858 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3859 IXGBE_GPIE_OCD;
3860 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003861 /*
3862 * use EIAM to auto-mask when MSI-X interrupt is asserted
3863 * this saves a register write for every interrupt
3864 */
3865 switch (hw->mac.type) {
3866 case ixgbe_mac_82598EB:
3867 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3868 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003869 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003870 case ixgbe_mac_X540:
3871 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003872 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3873 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3874 break;
3875 }
3876 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003877 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3878 * specifically only auto mask tx and rx interrupts */
3879 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003880 }
3881
Alexander Duycka34bcff2010-08-19 13:39:20 +00003882 /* XXX: to interrupt immediately for EICS writes, enable this */
3883 /* gpie |= IXGBE_GPIE_EIMEN; */
3884
3885 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3886 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3887 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003888 }
3889
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003890 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003891 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3892 switch (adapter->hw.mac.type) {
3893 case ixgbe_mac_82599EB:
3894 gpie |= IXGBE_SDP0_GPIEN;
3895 break;
3896 case ixgbe_mac_X540:
3897 gpie |= IXGBE_EIMS_TS;
3898 break;
3899 default:
3900 break;
3901 }
3902 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003903
Alexander Duycka34bcff2010-08-19 13:39:20 +00003904 /* Enable fan failure interrupt */
3905 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003906 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003907
Don Skidmore2698b202011-04-13 07:01:52 +00003908 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003909 gpie |= IXGBE_SDP1_GPIEN;
3910 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003911 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003912
3913 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3914}
3915
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003916static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003917{
3918 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003919 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003920 u32 ctrl_ext;
3921
3922 ixgbe_get_hw_control(adapter);
3923 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003924
Auke Kok9a799d72007-09-15 14:07:45 -07003925 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3926 ixgbe_configure_msix(adapter);
3927 else
3928 ixgbe_configure_msi_and_legacy(adapter);
3929
Don Skidmorec6ecf392010-12-03 03:31:51 +00003930 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3931 if (hw->mac.ops.enable_tx_laser &&
3932 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003933 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003934 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003935 hw->mac.ops.enable_tx_laser(hw);
3936
Auke Kok9a799d72007-09-15 14:07:45 -07003937 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003938 ixgbe_napi_enable_all(adapter);
3939
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003940 if (ixgbe_is_sfp(hw)) {
3941 ixgbe_sfp_link_config(adapter);
3942 } else {
3943 err = ixgbe_non_sfp_link_config(hw);
3944 if (err)
3945 e_err(probe, "link_config FAILED %d\n", err);
3946 }
3947
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003948 /* clear any pending interrupts, may auto mask */
3949 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003950 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003951
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003952 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003953 * If this adapter has a fan, check to see if we had a failure
3954 * before we enabled the interrupt.
3955 */
3956 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3957 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3958 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003959 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003960 }
3961
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003962 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003963 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003964
Auke Kok9a799d72007-09-15 14:07:45 -07003965 /* bring the link up in the watchdog, this could race with our first
3966 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003967 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3968 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003969 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003970
3971 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3972 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3973 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3974 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003975}
3976
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003977void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3978{
3979 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003980 /* put off any impending NetWatchDogTimeout */
3981 adapter->netdev->trans_start = jiffies;
3982
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003983 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003984 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003985 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003986 /*
3987 * If SR-IOV enabled then wait a bit before bringing the adapter
3988 * back up to give the VFs time to respond to the reset. The
3989 * two second wait is based upon the watchdog timer cycle in
3990 * the VF driver.
3991 */
3992 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3993 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003994 ixgbe_up(adapter);
3995 clear_bit(__IXGBE_RESETTING, &adapter->state);
3996}
3997
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003998void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003999{
4000 /* hardware has been reset, we need to reload some things */
4001 ixgbe_configure(adapter);
4002
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004003 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004004}
4005
4006void ixgbe_reset(struct ixgbe_adapter *adapter)
4007{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004008 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004009 int err;
4010
Alexander Duyck70864002011-04-27 09:13:56 +00004011 /* lock SFP init bit to prevent race conditions with the watchdog */
4012 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4013 usleep_range(1000, 2000);
4014
4015 /* clear all SFP and link config related flags while holding SFP_INIT */
4016 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4017 IXGBE_FLAG2_SFP_NEEDS_RESET);
4018 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4019
Don Skidmore8ca783a2009-05-26 20:40:47 -07004020 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004021 switch (err) {
4022 case 0:
4023 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004024 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004025 break;
4026 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004027 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004028 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004029 case IXGBE_ERR_EEPROM_VERSION:
4030 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004031 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004032 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004033 "your hardware. If you are experiencing problems "
4034 "please contact your Intel or hardware "
4035 "representative who provided you with this "
4036 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004037 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004038 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004039 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004040 }
Auke Kok9a799d72007-09-15 14:07:45 -07004041
Alexander Duyck70864002011-04-27 09:13:56 +00004042 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4043
Auke Kok9a799d72007-09-15 14:07:45 -07004044 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004045 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4046 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004047}
4048
Auke Kok9a799d72007-09-15 14:07:45 -07004049/**
Alexander Duyckf8003262012-03-03 02:35:52 +00004050 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
4051 * @rx_ring: ring to setup
4052 *
4053 * On many IA platforms the L1 cache has a critical stride of 4K, this
4054 * results in each receive buffer starting in the same cache set. To help
4055 * reduce the pressure on this cache set we can interleave the offsets so
4056 * that only every other buffer will be in the same cache set.
4057 **/
4058static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4059{
4060 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4061 u16 i;
4062
4063 for (i = 0; i < rx_ring->count; i += 2) {
4064 rx_buffer[0].page_offset = 0;
4065 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4066 rx_buffer = &rx_buffer[2];
4067 }
4068}
4069
4070/**
Auke Kok9a799d72007-09-15 14:07:45 -07004071 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004072 * @rx_ring: ring to free buffers from
4073 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004074static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004075{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004076 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004077 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004078 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004079
Alexander Duyck84418e32010-08-19 13:40:54 +00004080 /* ring already cleared, nothing to do */
4081 if (!rx_ring->rx_buffer_info)
4082 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004083
Alexander Duyck84418e32010-08-19 13:40:54 +00004084 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004085 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004086 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004087
Alexander Duyckf8003262012-03-03 02:35:52 +00004088 rx_buffer = &rx_ring->rx_buffer_info[i];
4089 if (rx_buffer->skb) {
4090 struct sk_buff *skb = rx_buffer->skb;
4091 if (IXGBE_CB(skb)->page_released) {
4092 dma_unmap_page(dev,
4093 IXGBE_CB(skb)->dma,
4094 ixgbe_rx_bufsz(rx_ring),
4095 DMA_FROM_DEVICE);
4096 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004097 }
4098 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004099 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004100 rx_buffer->skb = NULL;
4101 if (rx_buffer->dma)
4102 dma_unmap_page(dev, rx_buffer->dma,
4103 ixgbe_rx_pg_size(rx_ring),
4104 DMA_FROM_DEVICE);
4105 rx_buffer->dma = 0;
4106 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004107 __free_pages(rx_buffer->page,
4108 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004109 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004110 }
4111
4112 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4113 memset(rx_ring->rx_buffer_info, 0, size);
4114
Alexander Duyckf8003262012-03-03 02:35:52 +00004115 ixgbe_init_rx_page_offset(rx_ring);
4116
Auke Kok9a799d72007-09-15 14:07:45 -07004117 /* Zero out the descriptor ring */
4118 memset(rx_ring->desc, 0, rx_ring->size);
4119
Alexander Duyckf8003262012-03-03 02:35:52 +00004120 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004121 rx_ring->next_to_clean = 0;
4122 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004123}
4124
4125/**
4126 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004127 * @tx_ring: ring to be cleaned
4128 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004129static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004130{
4131 struct ixgbe_tx_buffer *tx_buffer_info;
4132 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004133 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004134
Alexander Duyck84418e32010-08-19 13:40:54 +00004135 /* ring already cleared, nothing to do */
4136 if (!tx_ring->tx_buffer_info)
4137 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004138
Alexander Duyck84418e32010-08-19 13:40:54 +00004139 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004140 for (i = 0; i < tx_ring->count; i++) {
4141 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004142 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004143 }
4144
John Fastabenddad8a3b2012-04-23 12:22:39 +00004145 netdev_tx_reset_queue(txring_txq(tx_ring));
4146
Auke Kok9a799d72007-09-15 14:07:45 -07004147 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4148 memset(tx_ring->tx_buffer_info, 0, size);
4149
4150 /* Zero out the descriptor ring */
4151 memset(tx_ring->desc, 0, tx_ring->size);
4152
4153 tx_ring->next_to_use = 0;
4154 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004155}
4156
4157/**
Auke Kok9a799d72007-09-15 14:07:45 -07004158 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4159 * @adapter: board private structure
4160 **/
4161static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4162{
4163 int i;
4164
4165 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004166 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004167}
4168
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004169/**
4170 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4171 * @adapter: board private structure
4172 **/
4173static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4174{
4175 int i;
4176
4177 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004178 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004179}
4180
Alexander Duycke4911d52011-05-11 07:18:52 +00004181static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4182{
4183 struct hlist_node *node, *node2;
4184 struct ixgbe_fdir_filter *filter;
4185
4186 spin_lock(&adapter->fdir_perfect_lock);
4187
4188 hlist_for_each_entry_safe(filter, node, node2,
4189 &adapter->fdir_filter_list, fdir_node) {
4190 hlist_del(&filter->fdir_node);
4191 kfree(filter);
4192 }
4193 adapter->fdir_filter_count = 0;
4194
4195 spin_unlock(&adapter->fdir_perfect_lock);
4196}
4197
Auke Kok9a799d72007-09-15 14:07:45 -07004198void ixgbe_down(struct ixgbe_adapter *adapter)
4199{
4200 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004201 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004202 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004203 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004204
4205 /* signal that we are down to the interrupt handler */
4206 set_bit(__IXGBE_DOWN, &adapter->state);
4207
4208 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004209 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4210 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004211
Yi Zou2d39d572011-01-06 14:29:56 +00004212 /* disable all enabled rx queues */
4213 for (i = 0; i < adapter->num_rx_queues; i++)
4214 /* this call also flushes the previous write */
4215 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4216
Don Skidmore032b4322011-03-18 09:32:53 +00004217 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004218
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004219 netif_tx_stop_all_queues(netdev);
4220
Alexander Duyck70864002011-04-27 09:13:56 +00004221 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004222 netif_carrier_off(netdev);
4223 netif_tx_disable(netdev);
4224
4225 ixgbe_irq_disable(adapter);
4226
4227 ixgbe_napi_disable_all(adapter);
4228
Alexander Duyckd034acf2011-04-27 09:25:34 +00004229 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4230 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004231 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4232
4233 del_timer_sync(&adapter->service_timer);
4234
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004235 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004236 /* Clear EITR Select mapping */
4237 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4238
4239 /* Mark all the VFs as inactive */
4240 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004241 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004242
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004243 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004244 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004245
Auke Kok9a799d72007-09-15 14:07:45 -07004246 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004247 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004248 }
4249
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004250 /* disable transmits in the hardware now that interrupts are off */
4251 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004252 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004253 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004254 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004255
4256 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004257 switch (hw->mac.type) {
4258 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004259 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004260 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004261 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4262 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004263 break;
4264 default:
4265 break;
4266 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004267
Paul Larson6f4a0e42008-06-24 17:00:56 -07004268 if (!pci_channel_offline(adapter->pdev))
4269 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004270
4271 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4272 if (hw->mac.ops.disable_tx_laser &&
4273 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004274 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004275 (hw->mac.type == ixgbe_mac_82599EB))))
4276 hw->mac.ops.disable_tx_laser(hw);
4277
Auke Kok9a799d72007-09-15 14:07:45 -07004278 ixgbe_clean_all_tx_rings(adapter);
4279 ixgbe_clean_all_rx_rings(adapter);
4280
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004281#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004282 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004283 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004284#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004285}
4286
Auke Kok9a799d72007-09-15 14:07:45 -07004287/**
Auke Kok9a799d72007-09-15 14:07:45 -07004288 * ixgbe_tx_timeout - Respond to a Tx Hang
4289 * @netdev: network interface device structure
4290 **/
4291static void ixgbe_tx_timeout(struct net_device *netdev)
4292{
4293 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4294
4295 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004296 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004297}
4298
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004299/**
Auke Kok9a799d72007-09-15 14:07:45 -07004300 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4301 * @adapter: board private structure to initialize
4302 *
4303 * ixgbe_sw_init initializes the Adapter private data structure.
4304 * Fields are initialized based on PCI device information and
4305 * OS network device settings (MTU size).
4306 **/
4307static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4308{
4309 struct ixgbe_hw *hw = &adapter->hw;
4310 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004311 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004312#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004313 int j;
4314 struct tc_configuration *tc;
4315#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004316
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004317 /* PCI config space info */
4318
4319 hw->vendor_id = pdev->vendor;
4320 hw->device_id = pdev->device;
4321 hw->revision_id = pdev->revision;
4322 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4323 hw->subsystem_device_id = pdev->subsystem_device;
4324
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004325 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004326 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004327 adapter->ring_feature[RING_F_RSS].indices = rss;
4328 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08004329 switch (hw->mac.type) {
4330 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004331 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4332 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004333 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004334 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004335 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004336 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4337 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004338 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004339 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4340 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004341 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4342 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004343 /* Flow Director hash filters enabled */
4344 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4345 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004346 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00004347 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004348 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004349#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004350 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4351 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4352 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00004353#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004354 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004355 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004356#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004357#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004358 break;
4359 default:
4360 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004361 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004362
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004363 /* n-tuple support exists, always init our spinlock */
4364 spin_lock_init(&adapter->fdir_perfect_lock);
4365
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004366#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004367 switch (hw->mac.type) {
4368 case ixgbe_mac_X540:
4369 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4370 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4371 break;
4372 default:
4373 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4374 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4375 break;
4376 }
4377
Alexander Duyck2f90b862008-11-20 20:52:10 -08004378 /* Configure DCB traffic classes */
4379 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4380 tc = &adapter->dcb_cfg.tc_config[j];
4381 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4382 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4383 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4384 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4385 tc->dcb_pfc = pfc_disabled;
4386 }
John Fastabend4de2a022011-09-27 03:52:01 +00004387
4388 /* Initialize default user to priority mapping, UPx->TC0 */
4389 tc = &adapter->dcb_cfg.tc_config[0];
4390 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4391 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4392
Alexander Duyck2f90b862008-11-20 20:52:10 -08004393 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4394 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004395 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004396 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004397 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004398 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4399 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004400
4401#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004402
4403 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004404 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004405 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004406#ifdef CONFIG_DCB
4407 adapter->last_lfc_mode = hw->fc.current_mode;
4408#endif
John Fastabend9da712d2011-08-23 03:14:22 +00004409 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004410 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4411 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004412 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004413
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004414 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004415 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004416 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004417
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004418 /* set default ring sizes */
4419 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4420 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4421
Alexander Duyckbd198052011-06-11 01:45:08 +00004422 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004423 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004424
Auke Kok9a799d72007-09-15 14:07:45 -07004425 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004426 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004427 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004428 return -EIO;
4429 }
4430
Auke Kok9a799d72007-09-15 14:07:45 -07004431 set_bit(__IXGBE_DOWN, &adapter->state);
4432
4433 return 0;
4434}
4435
4436/**
4437 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004438 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004439 *
4440 * Return 0 on success, negative on failure
4441 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004442int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004443{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004444 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004445 int orig_node = dev_to_node(dev);
4446 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004447 int size;
4448
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004449 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004450
4451 if (tx_ring->q_vector)
4452 numa_node = tx_ring->q_vector->numa_node;
4453
4454 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004455 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004456 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004457 if (!tx_ring->tx_buffer_info)
4458 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004459
4460 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004461 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004462 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004463
Alexander Duyckde88eee2012-02-08 07:49:59 +00004464 set_dev_node(dev, numa_node);
4465 tx_ring->desc = dma_alloc_coherent(dev,
4466 tx_ring->size,
4467 &tx_ring->dma,
4468 GFP_KERNEL);
4469 set_dev_node(dev, orig_node);
4470 if (!tx_ring->desc)
4471 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4472 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004473 if (!tx_ring->desc)
4474 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004475
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004476 tx_ring->next_to_use = 0;
4477 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004478 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004479
4480err:
4481 vfree(tx_ring->tx_buffer_info);
4482 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004483 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004484 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004485}
4486
4487/**
Alexander Duyck69888672008-09-11 20:05:39 -07004488 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4489 * @adapter: board private structure
4490 *
4491 * If this function returns with an error, then it's possible one or
4492 * more of the rings is populated (while the rest are not). It is the
4493 * callers duty to clean those orphaned rings.
4494 *
4495 * Return 0 on success, negative on failure
4496 **/
4497static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4498{
4499 int i, err = 0;
4500
4501 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004502 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004503 if (!err)
4504 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00004505 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07004506 break;
4507 }
4508
4509 return err;
4510}
4511
4512/**
Auke Kok9a799d72007-09-15 14:07:45 -07004513 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004514 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004515 *
4516 * Returns 0 on success, negative on failure
4517 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004518int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004519{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004520 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004521 int orig_node = dev_to_node(dev);
4522 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004523 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004524
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004525 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004526
4527 if (rx_ring->q_vector)
4528 numa_node = rx_ring->q_vector->numa_node;
4529
4530 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004531 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004532 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004533 if (!rx_ring->rx_buffer_info)
4534 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004535
Auke Kok9a799d72007-09-15 14:07:45 -07004536 /* Round up to nearest 4K */
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004537 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4538 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004539
Alexander Duyckde88eee2012-02-08 07:49:59 +00004540 set_dev_node(dev, numa_node);
4541 rx_ring->desc = dma_alloc_coherent(dev,
4542 rx_ring->size,
4543 &rx_ring->dma,
4544 GFP_KERNEL);
4545 set_dev_node(dev, orig_node);
4546 if (!rx_ring->desc)
4547 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4548 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004549 if (!rx_ring->desc)
4550 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004551
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07004552 rx_ring->next_to_clean = 0;
4553 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004554
Alexander Duyckf8003262012-03-03 02:35:52 +00004555 ixgbe_init_rx_page_offset(rx_ring);
4556
Auke Kok9a799d72007-09-15 14:07:45 -07004557 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004558err:
4559 vfree(rx_ring->rx_buffer_info);
4560 rx_ring->rx_buffer_info = NULL;
4561 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004562 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004563}
4564
4565/**
Alexander Duyck69888672008-09-11 20:05:39 -07004566 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4567 * @adapter: board private structure
4568 *
4569 * If this function returns with an error, then it's possible one or
4570 * more of the rings is populated (while the rest are not). It is the
4571 * callers duty to clean those orphaned rings.
4572 *
4573 * Return 0 on success, negative on failure
4574 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004575static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4576{
4577 int i, err = 0;
4578
4579 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004580 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004581 if (!err)
4582 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00004583 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07004584 break;
4585 }
4586
4587 return err;
4588}
4589
4590/**
Auke Kok9a799d72007-09-15 14:07:45 -07004591 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004592 * @tx_ring: Tx descriptor ring for a specific queue
4593 *
4594 * Free all transmit software resources
4595 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004596void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004597{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004598 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004599
4600 vfree(tx_ring->tx_buffer_info);
4601 tx_ring->tx_buffer_info = NULL;
4602
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004603 /* if not set, then don't free */
4604 if (!tx_ring->desc)
4605 return;
4606
4607 dma_free_coherent(tx_ring->dev, tx_ring->size,
4608 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004609
4610 tx_ring->desc = NULL;
4611}
4612
4613/**
4614 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4615 * @adapter: board private structure
4616 *
4617 * Free all transmit software resources
4618 **/
4619static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4620{
4621 int i;
4622
4623 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004624 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004625 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004626}
4627
4628/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004629 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004630 * @rx_ring: ring to clean the resources from
4631 *
4632 * Free all receive software resources
4633 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004634void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004635{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004636 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004637
4638 vfree(rx_ring->rx_buffer_info);
4639 rx_ring->rx_buffer_info = NULL;
4640
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004641 /* if not set, then don't free */
4642 if (!rx_ring->desc)
4643 return;
4644
4645 dma_free_coherent(rx_ring->dev, rx_ring->size,
4646 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004647
4648 rx_ring->desc = NULL;
4649}
4650
4651/**
4652 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4653 * @adapter: board private structure
4654 *
4655 * Free all receive software resources
4656 **/
4657static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4658{
4659 int i;
4660
4661 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004662 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004663 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004664}
4665
4666/**
Auke Kok9a799d72007-09-15 14:07:45 -07004667 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4668 * @netdev: network interface device structure
4669 * @new_mtu: new value for maximum frame size
4670 *
4671 * Returns 0 on success, negative on failure
4672 **/
4673static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4674{
4675 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4676 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4677
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004678 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004679 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4680 return -EINVAL;
4681
4682 /*
4683 * For 82599EB we cannot allow PF to change MTU greater than 1500
4684 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
4685 * don't allocate and chain buffers correctly.
4686 */
4687 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4688 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4689 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00004690 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07004691
Emil Tantilov396e7992010-07-01 20:05:12 +00004692 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004693
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004694 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004695 netdev->mtu = new_mtu;
4696
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004697 if (netif_running(netdev))
4698 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004699
4700 return 0;
4701}
4702
4703/**
4704 * ixgbe_open - Called when a network interface is made active
4705 * @netdev: network interface device structure
4706 *
4707 * Returns 0 on success, negative value on failure
4708 *
4709 * The open entry point is called when a network interface is made
4710 * active by the system (IFF_UP). At this point all resources needed
4711 * for transmit and receive operations are allocated, the interrupt
4712 * handler is registered with the OS, the watchdog timer is started,
4713 * and the stack is notified that the interface is ready.
4714 **/
4715static int ixgbe_open(struct net_device *netdev)
4716{
4717 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4718 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004719
Auke Kok4bebfaa2008-02-11 09:26:01 -08004720 /* disallow open during test */
4721 if (test_bit(__IXGBE_TESTING, &adapter->state))
4722 return -EBUSY;
4723
Jesse Brandeburg54386462009-04-17 20:44:27 +00004724 netif_carrier_off(netdev);
4725
Auke Kok9a799d72007-09-15 14:07:45 -07004726 /* allocate transmit descriptors */
4727 err = ixgbe_setup_all_tx_resources(adapter);
4728 if (err)
4729 goto err_setup_tx;
4730
Auke Kok9a799d72007-09-15 14:07:45 -07004731 /* allocate receive descriptors */
4732 err = ixgbe_setup_all_rx_resources(adapter);
4733 if (err)
4734 goto err_setup_rx;
4735
4736 ixgbe_configure(adapter);
4737
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004738 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004739 if (err)
4740 goto err_req_irq;
4741
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004742 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004743
4744 return 0;
4745
Auke Kok9a799d72007-09-15 14:07:45 -07004746err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004747err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004748 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004749err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004750 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004751 ixgbe_reset(adapter);
4752
4753 return err;
4754}
4755
4756/**
4757 * ixgbe_close - Disables a network interface
4758 * @netdev: network interface device structure
4759 *
4760 * Returns 0, this is not allowed to fail
4761 *
4762 * The close entry point is called when an interface is de-activated
4763 * by the OS. The hardware is still under the drivers control, but
4764 * needs to be disabled. A global MAC reset is issued to stop the
4765 * hardware, and all transmit and receive resources are freed.
4766 **/
4767static int ixgbe_close(struct net_device *netdev)
4768{
4769 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004770
4771 ixgbe_down(adapter);
4772 ixgbe_free_irq(adapter);
4773
Alexander Duycke4911d52011-05-11 07:18:52 +00004774 ixgbe_fdir_filter_exit(adapter);
4775
Auke Kok9a799d72007-09-15 14:07:45 -07004776 ixgbe_free_all_tx_resources(adapter);
4777 ixgbe_free_all_rx_resources(adapter);
4778
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004779 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004780
4781 return 0;
4782}
4783
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004784#ifdef CONFIG_PM
4785static int ixgbe_resume(struct pci_dev *pdev)
4786{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004787 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4788 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004789 u32 err;
4790
4791 pci_set_power_state(pdev, PCI_D0);
4792 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004793 /*
4794 * pci_restore_state clears dev->state_saved so call
4795 * pci_save_state to restore it.
4796 */
4797 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004798
4799 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004800 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004801 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004802 return err;
4803 }
4804 pci_set_master(pdev);
4805
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004806 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004807
Benjamin Poirier34948a92012-04-06 07:20:21 +00004808 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004809 err = ixgbe_init_interrupt_scheme(adapter);
Benjamin Poirier34948a92012-04-06 07:20:21 +00004810 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004811 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004812 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004813 return err;
4814 }
4815
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004816 ixgbe_reset(adapter);
4817
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004818 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4819
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004820 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004821 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004822 if (err)
4823 return err;
4824 }
4825
4826 netif_device_attach(netdev);
4827
4828 return 0;
4829}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004830#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004831
4832static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004833{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004834 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4835 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004836 struct ixgbe_hw *hw = &adapter->hw;
4837 u32 ctrl, fctrl;
4838 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004839#ifdef CONFIG_PM
4840 int retval = 0;
4841#endif
4842
4843 netif_device_detach(netdev);
4844
4845 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00004846 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004847 ixgbe_down(adapter);
4848 ixgbe_free_irq(adapter);
4849 ixgbe_free_all_tx_resources(adapter);
4850 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00004851 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004852 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004853
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08004854 ixgbe_clear_interrupt_scheme(adapter);
4855
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004856#ifdef CONFIG_PM
4857 retval = pci_save_state(pdev);
4858 if (retval)
4859 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004860
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004861#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004862 if (wufc) {
4863 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004864
Don Skidmorec509e752012-04-05 08:12:05 +00004865 /*
4866 * enable the optics for both mult-speed fiber and
4867 * 82599 SFP+ fiber as we can WoL.
4868 */
4869 if (hw->mac.ops.enable_tx_laser &&
4870 (hw->phy.multispeed_fiber ||
4871 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
4872 hw->mac.type == ixgbe_mac_82599EB)))
4873 hw->mac.ops.enable_tx_laser(hw);
4874
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004875 /* turn on all-multi mode if wake on multicast is enabled */
4876 if (wufc & IXGBE_WUFC_MC) {
4877 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4878 fctrl |= IXGBE_FCTRL_MPE;
4879 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4880 }
4881
4882 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4883 ctrl |= IXGBE_CTRL_GIO_DIS;
4884 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4885
4886 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4887 } else {
4888 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4889 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4890 }
4891
Alexander Duyckbd508172010-11-16 19:27:03 -08004892 switch (hw->mac.type) {
4893 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004894 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08004895 break;
4896 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004897 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08004898 pci_wake_from_d3(pdev, !!wufc);
4899 break;
4900 default:
4901 break;
4902 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004903
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004904 *enable_wake = !!wufc;
4905
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004906 ixgbe_release_hw_control(adapter);
4907
4908 pci_disable_device(pdev);
4909
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004910 return 0;
4911}
4912
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004913#ifdef CONFIG_PM
4914static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4915{
4916 int retval;
4917 bool wake;
4918
4919 retval = __ixgbe_shutdown(pdev, &wake);
4920 if (retval)
4921 return retval;
4922
4923 if (wake) {
4924 pci_prepare_to_sleep(pdev);
4925 } else {
4926 pci_wake_from_d3(pdev, false);
4927 pci_set_power_state(pdev, PCI_D3hot);
4928 }
4929
4930 return 0;
4931}
4932#endif /* CONFIG_PM */
4933
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004934static void ixgbe_shutdown(struct pci_dev *pdev)
4935{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004936 bool wake;
4937
4938 __ixgbe_shutdown(pdev, &wake);
4939
4940 if (system_state == SYSTEM_POWER_OFF) {
4941 pci_wake_from_d3(pdev, wake);
4942 pci_set_power_state(pdev, PCI_D3hot);
4943 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004944}
4945
4946/**
Auke Kok9a799d72007-09-15 14:07:45 -07004947 * ixgbe_update_stats - Update the board statistics counters.
4948 * @adapter: board private structure
4949 **/
4950void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4951{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004952 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07004953 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004954 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004955 u64 total_mpc = 0;
4956 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004957 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
4958 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00004959 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00004960#ifdef IXGBE_FCOE
4961 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
4962 unsigned int cpu;
4963 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
4964#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07004965
Don Skidmored08935c2010-06-11 13:20:29 +00004966 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
4967 test_bit(__IXGBE_RESETTING, &adapter->state))
4968 return;
4969
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004970 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004971 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004972 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004973 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08004974 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
4975 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004976 }
4977 adapter->rsc_total_count = rsc_count;
4978 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004979 }
4980
Alexander Duyck5b7da512010-11-16 19:26:50 -08004981 for (i = 0; i < adapter->num_rx_queues; i++) {
4982 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
4983 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
4984 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
4985 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00004986 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004987 bytes += rx_ring->stats.bytes;
4988 packets += rx_ring->stats.packets;
4989 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00004990 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004991 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
4992 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00004993 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08004994 netdev->stats.rx_bytes = bytes;
4995 netdev->stats.rx_packets = packets;
4996
4997 bytes = 0;
4998 packets = 0;
4999 /* gather some stats to the adapter struct that are per queue */
5000 for (i = 0; i < adapter->num_tx_queues; i++) {
5001 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5002 restart_queue += tx_ring->tx_stats.restart_queue;
5003 tx_busy += tx_ring->tx_stats.tx_busy;
5004 bytes += tx_ring->stats.bytes;
5005 packets += tx_ring->stats.packets;
5006 }
5007 adapter->restart_queue = restart_queue;
5008 adapter->tx_busy = tx_busy;
5009 netdev->stats.tx_bytes = bytes;
5010 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005011
Joe Perches7ca647b2010-09-07 21:35:40 +00005012 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005013
5014 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005015 for (i = 0; i < 8; i++) {
5016 /* for packet buffers not used, the register should read 0 */
5017 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5018 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005019 hwstats->mpc[i] += mpc;
5020 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005021 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5022 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005023 switch (hw->mac.type) {
5024 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005025 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5026 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5027 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005028 hwstats->pxonrxc[i] +=
5029 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005030 break;
5031 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005032 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005033 hwstats->pxonrxc[i] +=
5034 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005035 break;
5036 default:
5037 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005038 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005039 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005040
5041 /*16 register reads */
5042 for (i = 0; i < 16; i++) {
5043 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5044 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5045 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5046 (hw->mac.type == ixgbe_mac_X540)) {
5047 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5048 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5049 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5050 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5051 }
5052 }
5053
Joe Perches7ca647b2010-09-07 21:35:40 +00005054 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005055 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005056 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005057
John Fastabendc84d3242010-11-16 19:27:12 -08005058 ixgbe_update_xoff_received(adapter);
5059
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005060 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005061 switch (hw->mac.type) {
5062 case ixgbe_mac_82598EB:
5063 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005064 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5065 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5066 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5067 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005068 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005069 /* OS2BMC stats are X540 only*/
5070 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5071 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5072 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5073 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5074 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005075 for (i = 0; i < 16; i++)
5076 adapter->hw_rx_no_dma_resources +=
5077 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005078 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005079 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005080 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005081 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005082 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005083 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005084 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005085 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5086 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005087#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005088 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5089 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5090 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5091 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5092 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5093 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005094 /* Add up per cpu counters for total ddp aloc fail */
5095 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5096 for_each_possible_cpu(cpu) {
5097 fcoe_noddp_counts_sum +=
5098 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5099 fcoe_noddp_ext_buff_counts_sum +=
5100 *per_cpu_ptr(fcoe->
5101 pcpu_noddp_ext_buff, cpu);
5102 }
5103 }
5104 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5105 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005106#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005107 break;
5108 default:
5109 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005110 }
Auke Kok9a799d72007-09-15 14:07:45 -07005111 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005112 hwstats->bprc += bprc;
5113 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005114 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005115 hwstats->mprc -= bprc;
5116 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5117 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5118 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5119 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5120 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5121 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5122 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5123 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005124 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005125 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005126 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005127 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005128 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5129 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005130 /*
5131 * 82598 errata - tx of flow control packets is included in tx counters
5132 */
5133 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005134 hwstats->gptc -= xon_off_tot;
5135 hwstats->mptc -= xon_off_tot;
5136 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5137 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5138 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5139 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5140 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5141 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5142 hwstats->ptc64 -= xon_off_tot;
5143 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5144 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5145 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5146 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5147 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5148 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005149
5150 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005151 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005152
5153 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005154 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005155 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005156 netdev->stats.rx_length_errors = hwstats->rlec;
5157 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005158 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005159}
5160
5161/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005162 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5163 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005164 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005165static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005166{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005167 struct ixgbe_hw *hw = &adapter->hw;
5168 int i;
5169
Alexander Duyckd034acf2011-04-27 09:25:34 +00005170 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5171 return;
5172
5173 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5174
5175 /* if interface is down do nothing */
5176 if (test_bit(__IXGBE_DOWN, &adapter->state))
5177 return;
5178
5179 /* do nothing if we are not using signature filters */
5180 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5181 return;
5182
5183 adapter->fdir_overflow++;
5184
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005185 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5186 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005187 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005188 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005189 /* re-enable flow director interrupts */
5190 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005191 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005192 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005193 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005194 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005195}
5196
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005197/**
5198 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5199 * @adapter - pointer to the device adapter structure
5200 *
5201 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005202 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005203 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005204 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005205 */
5206static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5207{
Auke Kok9a799d72007-09-15 14:07:45 -07005208 struct ixgbe_hw *hw = &adapter->hw;
5209 u64 eics = 0;
5210 int i;
5211
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005212 /* If we're down or resetting, just bail */
5213 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5214 test_bit(__IXGBE_RESETTING, &adapter->state))
5215 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005216
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005217 /* Force detection of hung controller */
5218 if (netif_carrier_ok(adapter->netdev)) {
5219 for (i = 0; i < adapter->num_tx_queues; i++)
5220 set_check_for_tx_hang(adapter->tx_ring[i]);
5221 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005222
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005223 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005224 /*
5225 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005226 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005227 * would set *both* EIMS and EICS for any bit in EIAM
5228 */
5229 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5230 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005231 } else {
5232 /* get one bit for every active tx/rx interrupt vector */
5233 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5234 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005235 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005236 eics |= ((u64)1 << i);
5237 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005238 }
5239
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005240 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005241 ixgbe_irq_rearm_queues(adapter, eics);
5242
Alexander Duyckfe49f042009-06-04 16:00:09 +00005243}
5244
5245/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005246 * ixgbe_watchdog_update_link - update the link status
5247 * @adapter - pointer to the device adapter structure
5248 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005249 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005250static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005251{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005252 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005253 u32 link_speed = adapter->link_speed;
5254 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005255 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005256
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005257 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5258 return;
5259
5260 if (hw->mac.ops.check_link) {
5261 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005262 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005263 /* always assume link is up, if no check link function */
5264 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5265 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005266 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005267
5268 if (adapter->ixgbe_ieee_pfc)
5269 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5270
5271 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en))
5272 hw->mac.ops.fc_enable(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005273
5274 if (link_up ||
5275 time_after(jiffies, (adapter->link_check_timeout +
5276 IXGBE_TRY_LINK_TIMEOUT))) {
5277 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5278 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5279 IXGBE_WRITE_FLUSH(hw);
5280 }
5281
5282 adapter->link_up = link_up;
5283 adapter->link_speed = link_speed;
5284}
5285
5286/**
5287 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5288 * print link up message
5289 * @adapter - pointer to the device adapter structure
5290 **/
5291static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5292{
5293 struct net_device *netdev = adapter->netdev;
5294 struct ixgbe_hw *hw = &adapter->hw;
5295 u32 link_speed = adapter->link_speed;
5296 bool flow_rx, flow_tx;
5297
5298 /* only continue if link was previously down */
5299 if (netif_carrier_ok(netdev))
5300 return;
5301
5302 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5303
5304 switch (hw->mac.type) {
5305 case ixgbe_mac_82598EB: {
5306 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5307 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5308 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5309 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5310 }
5311 break;
5312 case ixgbe_mac_X540:
5313 case ixgbe_mac_82599EB: {
5314 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5315 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5316 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5317 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5318 }
5319 break;
5320 default:
5321 flow_tx = false;
5322 flow_rx = false;
5323 break;
5324 }
5325 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5326 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5327 "10 Gbps" :
5328 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5329 "1 Gbps" :
5330 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5331 "100 Mbps" :
5332 "unknown speed"))),
5333 ((flow_rx && flow_tx) ? "RX/TX" :
5334 (flow_rx ? "RX" :
5335 (flow_tx ? "TX" : "None"))));
5336
5337 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005338 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005339}
5340
5341/**
5342 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5343 * print link down message
5344 * @adapter - pointer to the adapter structure
5345 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005346static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005347{
5348 struct net_device *netdev = adapter->netdev;
5349 struct ixgbe_hw *hw = &adapter->hw;
5350
5351 adapter->link_up = false;
5352 adapter->link_speed = 0;
5353
5354 /* only continue if link was up previously */
5355 if (!netif_carrier_ok(netdev))
5356 return;
5357
5358 /* poll for SFP+ cable when link is down */
5359 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5360 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5361
5362 e_info(drv, "NIC Link is Down\n");
5363 netif_carrier_off(netdev);
5364}
5365
5366/**
5367 * ixgbe_watchdog_flush_tx - flush queues on link down
5368 * @adapter - pointer to the device adapter structure
5369 **/
5370static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5371{
5372 int i;
5373 int some_tx_pending = 0;
5374
5375 if (!netif_carrier_ok(adapter->netdev)) {
5376 for (i = 0; i < adapter->num_tx_queues; i++) {
5377 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5378 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5379 some_tx_pending = 1;
5380 break;
5381 }
5382 }
5383
5384 if (some_tx_pending) {
5385 /* We've lost link, so the controller stops DMA,
5386 * but we've got queued Tx work that's never going
5387 * to get done, so reset controller to flush Tx.
5388 * (Do the reset outside of interrupt context).
5389 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005390 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005391 }
5392 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005393}
5394
Greg Rosea985b6c32010-11-18 03:02:52 +00005395static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5396{
5397 u32 ssvpc;
5398
5399 /* Do not perform spoof check for 82598 */
5400 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5401 return;
5402
5403 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5404
5405 /*
5406 * ssvpc register is cleared on read, if zero then no
5407 * spoofed packets in the last interval.
5408 */
5409 if (!ssvpc)
5410 return;
5411
5412 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
5413}
5414
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005415/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005416 * ixgbe_watchdog_subtask - check and bring link up
5417 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005418 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005419static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005420{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005421 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005422 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5423 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005424 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005425
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005426 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005427
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005428 if (adapter->link_up)
5429 ixgbe_watchdog_link_is_up(adapter);
5430 else
5431 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005432
Greg Rosea985b6c32010-11-18 03:02:52 +00005433 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005434 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005435
5436 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005437}
5438
Alexander Duyck70864002011-04-27 09:13:56 +00005439/**
5440 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5441 * @adapter - the ixgbe adapter structure
5442 **/
5443static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5444{
5445 struct ixgbe_hw *hw = &adapter->hw;
5446 s32 err;
5447
5448 /* not searching for SFP so there is nothing to do here */
5449 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5450 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5451 return;
5452
5453 /* someone else is in init, wait until next service event */
5454 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5455 return;
5456
5457 err = hw->phy.ops.identify_sfp(hw);
5458 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5459 goto sfp_out;
5460
5461 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5462 /* If no cable is present, then we need to reset
5463 * the next time we find a good cable. */
5464 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5465 }
5466
5467 /* exit on error */
5468 if (err)
5469 goto sfp_out;
5470
5471 /* exit if reset not needed */
5472 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5473 goto sfp_out;
5474
5475 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5476
5477 /*
5478 * A module may be identified correctly, but the EEPROM may not have
5479 * support for that module. setup_sfp() will fail in that case, so
5480 * we should not allow that module to load.
5481 */
5482 if (hw->mac.type == ixgbe_mac_82598EB)
5483 err = hw->phy.ops.reset(hw);
5484 else
5485 err = hw->mac.ops.setup_sfp(hw);
5486
5487 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5488 goto sfp_out;
5489
5490 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5491 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5492
5493sfp_out:
5494 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5495
5496 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5497 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5498 e_dev_err("failed to initialize because an unsupported "
5499 "SFP+ module type was detected.\n");
5500 e_dev_err("Reload the driver after installing a "
5501 "supported module.\n");
5502 unregister_netdev(adapter->netdev);
5503 }
5504}
5505
5506/**
5507 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
5508 * @adapter - the ixgbe adapter structure
5509 **/
5510static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5511{
5512 struct ixgbe_hw *hw = &adapter->hw;
5513 u32 autoneg;
5514 bool negotiation;
5515
5516 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5517 return;
5518
5519 /* someone else is in init, wait until next service event */
5520 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5521 return;
5522
5523 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5524
5525 autoneg = hw->phy.autoneg_advertised;
5526 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5527 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005528 if (hw->mac.ops.setup_link)
5529 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5530
5531 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5532 adapter->link_check_timeout = jiffies;
5533 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5534}
5535
Greg Rose83c61fa2011-09-07 05:59:35 +00005536#ifdef CONFIG_PCI_IOV
5537static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5538{
5539 int vf;
5540 struct ixgbe_hw *hw = &adapter->hw;
5541 struct net_device *netdev = adapter->netdev;
5542 u32 gpc;
5543 u32 ciaa, ciad;
5544
5545 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5546 if (gpc) /* If incrementing then no need for the check below */
5547 return;
5548 /*
5549 * Check to see if a bad DMA write target from an errant or
5550 * malicious VF has caused a PCIe error. If so then we can
5551 * issue a VFLR to the offending VF(s) and then resume without
5552 * requesting a full slot reset.
5553 */
5554
5555 for (vf = 0; vf < adapter->num_vfs; vf++) {
5556 ciaa = (vf << 16) | 0x80000000;
5557 /* 32 bit read so align, we really want status at offset 6 */
5558 ciaa |= PCI_COMMAND;
5559 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5560 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5561 ciaa &= 0x7FFFFFFF;
5562 /* disable debug mode asap after reading data */
5563 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5564 /* Get the upper 16 bits which will be the PCI status reg */
5565 ciad >>= 16;
5566 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5567 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5568 /* Issue VFLR */
5569 ciaa = (vf << 16) | 0x80000000;
5570 ciaa |= 0xA8;
5571 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5572 ciad = 0x00008000; /* VFLR */
5573 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5574 ciaa &= 0x7FFFFFFF;
5575 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5576 }
5577 }
5578}
5579
5580#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005581/**
5582 * ixgbe_service_timer - Timer Call-back
5583 * @data: pointer to adapter cast into an unsigned long
5584 **/
5585static void ixgbe_service_timer(unsigned long data)
5586{
5587 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5588 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005589 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005590
5591 /* poll faster when waiting for link */
5592 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5593 next_event_offset = HZ / 10;
5594 else
5595 next_event_offset = HZ * 2;
5596
Greg Rose83c61fa2011-09-07 05:59:35 +00005597#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005598 /*
5599 * don't bother with SR-IOV VF DMA hang check if there are
5600 * no VFs or the link is down
5601 */
5602 if (!adapter->num_vfs ||
5603 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5604 goto normal_timer_service;
5605
5606 /* If we have VFs allocated then we must check for DMA hangs */
5607 ixgbe_check_for_bad_vf(adapter);
5608 next_event_offset = HZ / 50;
5609 adapter->timer_event_accumulator++;
5610
5611 if (adapter->timer_event_accumulator >= 100)
5612 adapter->timer_event_accumulator = 0;
5613 else
5614 ready = false;
5615
5616normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005617#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005618 /* Reset the timer */
5619 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5620
Greg Rose83c61fa2011-09-07 05:59:35 +00005621 if (ready)
5622 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005623}
5624
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005625static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5626{
5627 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5628 return;
5629
5630 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5631
5632 /* If we're already down or resetting, just bail */
5633 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5634 test_bit(__IXGBE_RESETTING, &adapter->state))
5635 return;
5636
5637 ixgbe_dump(adapter);
5638 netdev_err(adapter->netdev, "Reset adapter\n");
5639 adapter->tx_timeout_count++;
5640
5641 ixgbe_reinit_locked(adapter);
5642}
5643
Alexander Duyck70864002011-04-27 09:13:56 +00005644/**
5645 * ixgbe_service_task - manages and runs subtasks
5646 * @work: pointer to work_struct containing our data
5647 **/
5648static void ixgbe_service_task(struct work_struct *work)
5649{
5650 struct ixgbe_adapter *adapter = container_of(work,
5651 struct ixgbe_adapter,
5652 service_task);
5653
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005654 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005655 ixgbe_sfp_detection_subtask(adapter);
5656 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005657 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005658 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005659 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005660 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005661
5662 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005663}
5664
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005665static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5666 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005667 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005668{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005669 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005670 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005671 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005672
Alexander Duyck897ab152011-05-27 05:31:47 +00005673 if (!skb_is_gso(skb))
5674 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005675
Alexander Duyck897ab152011-05-27 05:31:47 +00005676 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005677 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005678 if (err)
5679 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005680 }
5681
Alexander Duyck897ab152011-05-27 05:31:47 +00005682 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5683 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5684
Alexander Duyck244e27a2012-02-08 07:51:11 +00005685 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005686 struct iphdr *iph = ip_hdr(skb);
5687 iph->tot_len = 0;
5688 iph->check = 0;
5689 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5690 iph->daddr, 0,
5691 IPPROTO_TCP,
5692 0);
5693 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005694 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5695 IXGBE_TX_FLAGS_CSUM |
5696 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005697 } else if (skb_is_gso_v6(skb)) {
5698 ipv6_hdr(skb)->payload_len = 0;
5699 tcp_hdr(skb)->check =
5700 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5701 &ipv6_hdr(skb)->daddr,
5702 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005703 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5704 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005705 }
5706
Alexander Duyck091a6242012-02-08 07:51:01 +00005707 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005708 l4len = tcp_hdrlen(skb);
5709 *hdr_len = skb_transport_offset(skb) + l4len;
5710
Alexander Duyck091a6242012-02-08 07:51:01 +00005711 /* update gso size and bytecount with header size */
5712 first->gso_segs = skb_shinfo(skb)->gso_segs;
5713 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5714
Alexander Duyck897ab152011-05-27 05:31:47 +00005715 /* mss_l4len_id: use 1 as index for TSO */
5716 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5717 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5718 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5719
5720 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5721 vlan_macip_lens = skb_network_header_len(skb);
5722 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005723 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005724
5725 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005726 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005727
5728 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005729}
5730
Alexander Duyck244e27a2012-02-08 07:51:11 +00005731static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5732 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005733{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005734 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005735 u32 vlan_macip_lens = 0;
5736 u32 mss_l4len_idx = 0;
5737 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005738
Alexander Duyck897ab152011-05-27 05:31:47 +00005739 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005740 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
5741 !(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5742 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00005743 } else {
5744 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005745 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005746 case __constant_htons(ETH_P_IP):
5747 vlan_macip_lens |= skb_network_header_len(skb);
5748 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5749 l4_hdr = ip_hdr(skb)->protocol;
5750 break;
5751 case __constant_htons(ETH_P_IPV6):
5752 vlan_macip_lens |= skb_network_header_len(skb);
5753 l4_hdr = ipv6_hdr(skb)->nexthdr;
5754 break;
5755 default:
5756 if (unlikely(net_ratelimit())) {
5757 dev_warn(tx_ring->dev,
5758 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005759 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005760 }
5761 break;
5762 }
Auke Kok9a799d72007-09-15 14:07:45 -07005763
Alexander Duyck897ab152011-05-27 05:31:47 +00005764 switch (l4_hdr) {
5765 case IPPROTO_TCP:
5766 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5767 mss_l4len_idx = tcp_hdrlen(skb) <<
5768 IXGBE_ADVTXD_L4LEN_SHIFT;
5769 break;
5770 case IPPROTO_SCTP:
5771 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
5772 mss_l4len_idx = sizeof(struct sctphdr) <<
5773 IXGBE_ADVTXD_L4LEN_SHIFT;
5774 break;
5775 case IPPROTO_UDP:
5776 mss_l4len_idx = sizeof(struct udphdr) <<
5777 IXGBE_ADVTXD_L4LEN_SHIFT;
5778 break;
5779 default:
5780 if (unlikely(net_ratelimit())) {
5781 dev_warn(tx_ring->dev,
5782 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005783 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00005784 }
5785 break;
5786 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00005787
5788 /* update TX checksum flag */
5789 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005790 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005791
Alexander Duyck244e27a2012-02-08 07:51:11 +00005792 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00005793 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005794 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005795
5796 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
5797 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07005798}
5799
Alexander Duyckd3d00232011-07-15 02:31:25 +00005800static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
5801{
5802 /* set type for advanced descriptor with frame checksum insertion */
5803 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
5804 IXGBE_ADVTXD_DCMD_IFCS |
5805 IXGBE_ADVTXD_DCMD_DEXT);
5806
5807 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00005808 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005809 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
5810
5811 /* set segmentation enable bits for TSO/FSO */
5812#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005813 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005814#else
5815 if (tx_flags & IXGBE_TX_FLAGS_TSO)
5816#endif
5817 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
5818
5819 return cmd_type;
5820}
5821
Alexander Duyck729739b2012-02-08 07:51:06 +00005822static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
5823 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005824{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005825 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005826
5827 /* enable L4 checksum for TSO and TX checksum offload */
5828 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5829 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
5830
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005831 /* enble IPv4 checksum for TSO */
5832 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5833 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005834
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005835 /* use index 1 context for TSO/FSO/FCOE */
5836#ifdef IXGBE_FCOE
5837 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
5838#else
5839 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005840#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005841 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
5842
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005843 /*
5844 * Check Context must be set if Tx switch is enabled, which it
5845 * always is for case where virtual functions are running
5846 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005847#ifdef IXGBE_FCOE
5848 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
5849#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005850 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005851#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005852 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
5853
Alexander Duyck729739b2012-02-08 07:51:06 +00005854 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005855}
5856
5857#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
5858 IXGBE_TXD_CMD_RS)
5859
5860static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00005861 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00005862 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07005863{
Alexander Duyckd3d00232011-07-15 02:31:25 +00005864 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00005865 struct sk_buff *skb = first->skb;
5866 struct ixgbe_tx_buffer *tx_buffer;
5867 union ixgbe_adv_tx_desc *tx_desc;
5868 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00005869 unsigned int data_len = skb->data_len;
5870 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00005871 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005872 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00005873 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005874 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07005875
Alexander Duyck729739b2012-02-08 07:51:06 +00005876 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5877
5878 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
5879 cmd_type = ixgbe_tx_cmd_type(tx_flags);
5880
Alexander Duyckd3d00232011-07-15 02:31:25 +00005881#ifdef IXGBE_FCOE
5882 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005883 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00005884 size -= sizeof(struct fcoe_crc_eof) - data_len;
5885 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00005886 } else {
5887 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005888 }
Auke Kok9a799d72007-09-15 14:07:45 -07005889 }
5890
Alexander Duyckd3d00232011-07-15 02:31:25 +00005891#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00005892 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5893 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005894 goto dma_error;
5895
Alexander Duyck729739b2012-02-08 07:51:06 +00005896 /* record length, and DMA address */
5897 dma_unmap_len_set(first, len, size);
5898 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005899
Alexander Duyck729739b2012-02-08 07:51:06 +00005900 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005901
5902 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005903 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00005904 tx_desc->read.cmd_type_len =
5905 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005906
Alexander Duyckd3d00232011-07-15 02:31:25 +00005907 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00005908 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005909 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00005910 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005911 i = 0;
5912 }
Alexander Duyck729739b2012-02-08 07:51:06 +00005913
5914 dma += IXGBE_MAX_DATA_PER_TXD;
5915 size -= IXGBE_MAX_DATA_PER_TXD;
5916
5917 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5918 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005919 }
5920
Alexander Duyck729739b2012-02-08 07:51:06 +00005921 if (likely(!data_len))
5922 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005923
Ben Greearf43f3132012-03-06 09:42:04 +00005924 if (unlikely(skb->no_fcs))
5925 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00005926 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005927
Alexander Duyck729739b2012-02-08 07:51:06 +00005928 i++;
5929 tx_desc++;
5930 if (i == tx_ring->count) {
5931 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5932 i = 0;
5933 }
Auke Kok9a799d72007-09-15 14:07:45 -07005934
Alexander Duyckd3d00232011-07-15 02:31:25 +00005935#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00005936 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00005937#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00005938 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005939#endif
5940 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005941
Alexander Duyck729739b2012-02-08 07:51:06 +00005942 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
5943 DMA_TO_DEVICE);
5944 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005945 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005946
Alexander Duyck729739b2012-02-08 07:51:06 +00005947 tx_buffer = &tx_ring->tx_buffer_info[i];
5948 dma_unmap_len_set(tx_buffer, len, size);
5949 dma_unmap_addr_set(tx_buffer, dma, dma);
5950
5951 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5952 tx_desc->read.olinfo_status = 0;
5953
5954 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07005955 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005956
Alexander Duyck729739b2012-02-08 07:51:06 +00005957 /* write last descriptor with RS and EOP bits */
5958 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
5959 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005960
Alexander Duyck091a6242012-02-08 07:51:01 +00005961 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00005962
Alexander Duyckd3d00232011-07-15 02:31:25 +00005963 /* set the timestamp */
5964 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07005965
5966 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00005967 * Force memory writes to complete before letting h/w know there
5968 * are new descriptors to fetch. (Only applicable for weak-ordered
5969 * memory model archs, such as IA-64).
5970 *
5971 * We also need this memory barrier to make certain all of the
5972 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07005973 */
5974 wmb();
5975
Alexander Duyckd3d00232011-07-15 02:31:25 +00005976 /* set next_to_watch value indicating a packet is present */
5977 first->next_to_watch = tx_desc;
5978
Alexander Duyck729739b2012-02-08 07:51:06 +00005979 i++;
5980 if (i == tx_ring->count)
5981 i = 0;
5982
5983 tx_ring->next_to_use = i;
5984
Alexander Duyckd3d00232011-07-15 02:31:25 +00005985 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08005986 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005987
5988 return;
5989dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00005990 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00005991
5992 /* clear dma mappings for failed tx_buffer_info map */
5993 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005994 tx_buffer = &tx_ring->tx_buffer_info[i];
5995 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
5996 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005997 break;
5998 if (i == 0)
5999 i = tx_ring->count;
6000 i--;
6001 }
6002
Alexander Duyckd3d00232011-07-15 02:31:25 +00006003 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006004}
6005
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006006static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006007 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006008{
Alexander Duyck69830522011-01-06 14:29:58 +00006009 struct ixgbe_q_vector *q_vector = ring->q_vector;
6010 union ixgbe_atr_hash_dword input = { .dword = 0 };
6011 union ixgbe_atr_hash_dword common = { .dword = 0 };
6012 union {
6013 unsigned char *network;
6014 struct iphdr *ipv4;
6015 struct ipv6hdr *ipv6;
6016 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006017 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006018 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006019
Alexander Duyck69830522011-01-06 14:29:58 +00006020 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6021 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006022 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006023
Alexander Duyck69830522011-01-06 14:29:58 +00006024 /* do nothing if sampling is disabled */
6025 if (!ring->atr_sample_rate)
6026 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006027
Alexander Duyck69830522011-01-06 14:29:58 +00006028 ring->atr_count++;
6029
6030 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006031 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006032
6033 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006034 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006035 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006036 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006037 hdr.ipv4->protocol != IPPROTO_TCP))
6038 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006039
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006040 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006041
Alexander Duyck66f32a82011-06-29 05:43:22 +00006042 /* skip this packet since it is invalid or the socket is closing */
6043 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006044 return;
6045
6046 /* sample on all syn packets or once every atr sample count */
6047 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6048 return;
6049
6050 /* reset sample count */
6051 ring->atr_count = 0;
6052
Alexander Duyck244e27a2012-02-08 07:51:11 +00006053 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006054
6055 /*
6056 * src and dst are inverted, think how the receiver sees them
6057 *
6058 * The input is broken into two sections, a non-compressed section
6059 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6060 * is XORed together and stored in the compressed dword.
6061 */
6062 input.formatted.vlan_id = vlan_id;
6063
6064 /*
6065 * since src port and flex bytes occupy the same word XOR them together
6066 * and write the value to source port portion of compressed dword
6067 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006068 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006069 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6070 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006071 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006072 common.port.dst ^= th->source;
6073
Alexander Duyck244e27a2012-02-08 07:51:11 +00006074 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006075 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6076 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6077 } else {
6078 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6079 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6080 hdr.ipv6->saddr.s6_addr32[1] ^
6081 hdr.ipv6->saddr.s6_addr32[2] ^
6082 hdr.ipv6->saddr.s6_addr32[3] ^
6083 hdr.ipv6->daddr.s6_addr32[0] ^
6084 hdr.ipv6->daddr.s6_addr32[1] ^
6085 hdr.ipv6->daddr.s6_addr32[2] ^
6086 hdr.ipv6->daddr.s6_addr32[3];
6087 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006088
6089 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006090 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6091 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006092}
6093
Alexander Duyck63544e92011-05-27 05:31:42 +00006094static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006095{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006096 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006097 /* Herbert's original patch had:
6098 * smp_mb__after_netif_stop_queue();
6099 * but since that doesn't exist yet, just open code it. */
6100 smp_mb();
6101
6102 /* We need to check again in a case another CPU has just
6103 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006104 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006105 return -EBUSY;
6106
6107 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006108 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006109 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006110 return 0;
6111}
6112
Alexander Duyck82d4e462011-06-11 01:44:58 +00006113static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006114{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006115 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006116 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006117 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006118}
6119
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006120static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6121{
6122 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006123 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6124 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006125#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006126 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006127
John Fastabende5b64632011-03-08 03:44:52 +00006128 if (((protocol == htons(ETH_P_FCOE)) ||
6129 (protocol == htons(ETH_P_FIP))) &&
6130 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6131 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6132 txq += adapter->ring_feature[RING_F_FCOE].mask;
6133 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006134 }
6135#endif
6136
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006137 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6138 while (unlikely(txq >= dev->real_num_tx_queues))
6139 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006140 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006141 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006142
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006143 return skb_tx_hash(dev, skb);
6144}
6145
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006146netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006147 struct ixgbe_adapter *adapter,
6148 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006149{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006150 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006151 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006152 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006153#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6154 unsigned short f;
6155#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006156 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006157 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006158 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006159
Alexander Duycka535c302011-05-27 05:31:52 +00006160 /*
6161 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006162 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006163 * + 2 desc gap to keep tail from touching head,
6164 * + 1 desc for context descriptor,
6165 * otherwise try next time
6166 */
6167#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6168 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6169 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6170#else
6171 count += skb_shinfo(skb)->nr_frags;
6172#endif
6173 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6174 tx_ring->tx_stats.tx_busy++;
6175 return NETDEV_TX_BUSY;
6176 }
6177
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006178 /* record the location of the first descriptor for this packet */
6179 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6180 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006181 first->bytecount = skb->len;
6182 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006183
Alexander Duyck66f32a82011-06-29 05:43:22 +00006184 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006185 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006186 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6187 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6188 /* else if it is a SW VLAN check the next protocol and store the tag */
6189 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6190 struct vlan_hdr *vhdr, _vhdr;
6191 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6192 if (!vhdr)
6193 goto out_drop;
6194
6195 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006196 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6197 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006198 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006199 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006200
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006201#ifdef CONFIG_PCI_IOV
6202 /*
6203 * Use the l2switch_enable flag - would be false if the DMA
6204 * Tx switch had been disabled.
6205 */
6206 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6207 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6208
6209#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006210 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006211 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006212 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6213 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006214 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006215 tx_flags |= (skb->priority & 0x7) <<
6216 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006217 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6218 struct vlan_ethhdr *vhdr;
6219 if (skb_header_cloned(skb) &&
6220 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6221 goto out_drop;
6222 vhdr = (struct vlan_ethhdr *)skb->data;
6223 vhdr->h_vlan_TCI = htons(tx_flags >>
6224 IXGBE_TX_FLAGS_VLAN_SHIFT);
6225 } else {
6226 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6227 }
6228 }
Alexander Duycka535c302011-05-27 05:31:52 +00006229
Alexander Duyck244e27a2012-02-08 07:51:11 +00006230 /* record initial flags and protocol */
6231 first->tx_flags = tx_flags;
6232 first->protocol = protocol;
6233
Yi Zoueacd73f2009-05-13 13:11:06 +00006234#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006235 /* setup tx offload for FCoE */
6236 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6237 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006238 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006239 if (tso < 0)
6240 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006241
Alexander Duyck66f32a82011-06-29 05:43:22 +00006242 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006243 }
Auke Kok9a799d72007-09-15 14:07:45 -07006244
Auke Kok9a799d72007-09-15 14:07:45 -07006245#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006246 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006247 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006248 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006249 else if (!tso)
6250 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006251
6252 /* add the ATR filter if ATR is on */
6253 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006254 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006255
6256#ifdef IXGBE_FCOE
6257xmit_fcoe:
6258#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006259 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006260
6261 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006262
6263 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006264
6265out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006266 dev_kfree_skb_any(first->skb);
6267 first->skb = NULL;
6268
Alexander Duyck897ab152011-05-27 05:31:47 +00006269 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006270}
6271
Alexander Duycka50c29d2012-02-08 07:50:40 +00006272static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6273 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006274{
6275 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006276 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006277
Alexander Duycka50c29d2012-02-08 07:50:40 +00006278 if (skb->len <= 0) {
6279 dev_kfree_skb_any(skb);
6280 return NETDEV_TX_OK;
6281 }
6282
6283 /*
6284 * The minimum packet size for olinfo paylen is 17 so pad the skb
6285 * in order to meet this minimum size requirement.
6286 */
6287 if (skb->len < 17) {
6288 if (skb_padto(skb, 17))
6289 return NETDEV_TX_OK;
6290 skb->len = 17;
6291 }
6292
Auke Kok9a799d72007-09-15 14:07:45 -07006293 tx_ring = adapter->tx_ring[skb->queue_mapping];
6294 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6295}
6296
6297/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006298 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006299 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006300 * @p: pointer to an address structure
6301 *
Auke Kok9a799d72007-09-15 14:07:45 -07006302 * Returns 0 on success, negative on failure
6303 **/
6304static int ixgbe_set_mac(struct net_device *netdev, void *p)
6305{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006306 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6307 struct ixgbe_hw *hw = &adapter->hw;
6308 struct sockaddr *addr = p;
6309
6310 if (!is_valid_ether_addr(addr->sa_data))
6311 return -EADDRNOTAVAIL;
6312
6313 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6314 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6315
6316 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6317 IXGBE_RAH_AV);
6318
6319 return 0;
6320}
6321
6322static int
6323ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6324{
6325 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6326 struct ixgbe_hw *hw = &adapter->hw;
6327 u16 value;
6328 int rc;
6329
6330 if (prtad != hw->phy.mdio.prtad)
6331 return -EINVAL;
6332 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6333 if (!rc)
6334 rc = value;
6335 return rc;
6336}
6337
6338static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6339 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006340{
6341 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00006342 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006343
6344 if (prtad != hw->phy.mdio.prtad)
6345 return -EINVAL;
6346 return hw->phy.ops.write_reg(hw, addr, devad, value);
6347}
6348
6349static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6350{
6351 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6352
6353 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6354}
6355
6356/**
6357 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6358 * netdev->dev_addrs
6359 * @netdev: network interface device structure
6360 *
6361 * Returns non-zero on failure
6362 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00006363static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006364{
6365 int err = 0;
6366 struct ixgbe_adapter *adapter = netdev_priv(dev);
6367 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6368
6369 if (is_valid_ether_addr(mac->san_addr)) {
6370 rtnl_lock();
6371 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6372 rtnl_unlock();
6373 }
6374 return err;
6375}
6376
6377/**
6378 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6379 * netdev->dev_addrs
6380 * @netdev: network interface device structure
6381 *
Auke Kok9a799d72007-09-15 14:07:45 -07006382 * Returns non-zero on failure
6383 **/
6384static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6385{
6386 int err = 0;
6387 struct ixgbe_adapter *adapter = netdev_priv(dev);
6388 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6389
6390 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006391 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07006392 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006393 rtnl_unlock();
6394 }
6395 return err;
6396}
Auke Kok9a799d72007-09-15 14:07:45 -07006397
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006398#ifdef CONFIG_NET_POLL_CONTROLLER
6399/*
6400 * Polling 'interrupt' - used by things like netconsole to send skbs
6401 * without having to re-enable interrupts. It's not called while
6402 * the interrupt routine is executing.
6403 */
6404static void ixgbe_netpoll(struct net_device *netdev)
6405{
6406 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006407 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006408
6409 /* if interface is down do nothing */
6410 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006411 return;
6412
6413 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08006414 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006415 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00006416 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006417 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00006418 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006419 }
6420 } else {
6421 ixgbe_intr(adapter->pdev->irq, netdev);
6422 }
6423 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6424}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006425
Alexander Duyck581330b2012-02-08 07:51:47 +00006426#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006427static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6428 struct rtnl_link_stats64 *stats)
6429{
6430 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6431 int i;
6432
Eric Dumazet1a515022010-11-16 19:26:42 -08006433 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006434 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006435 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006436 u64 bytes, packets;
6437 unsigned int start;
6438
Eric Dumazet1a515022010-11-16 19:26:42 -08006439 if (ring) {
6440 do {
6441 start = u64_stats_fetch_begin_bh(&ring->syncp);
6442 packets = ring->stats.packets;
6443 bytes = ring->stats.bytes;
6444 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6445 stats->rx_packets += packets;
6446 stats->rx_bytes += bytes;
6447 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006448 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006449
6450 for (i = 0; i < adapter->num_tx_queues; i++) {
6451 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6452 u64 bytes, packets;
6453 unsigned int start;
6454
6455 if (ring) {
6456 do {
6457 start = u64_stats_fetch_begin_bh(&ring->syncp);
6458 packets = ring->stats.packets;
6459 bytes = ring->stats.bytes;
6460 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6461 stats->tx_packets += packets;
6462 stats->tx_bytes += bytes;
6463 }
6464 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006465 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006466 /* following stats updated by ixgbe_watchdog_task() */
6467 stats->multicast = netdev->stats.multicast;
6468 stats->rx_errors = netdev->stats.rx_errors;
6469 stats->rx_length_errors = netdev->stats.rx_length_errors;
6470 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6471 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6472 return stats;
6473}
6474
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006475#ifdef CONFIG_IXGBE_DCB
John Fastabend8b1c0b22011-05-03 02:26:48 +00006476/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6477 * #adapter: pointer to ixgbe_adapter
6478 * @tc: number of traffic classes currently enabled
6479 *
6480 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6481 * 802.1Q priority maps to a packet buffer that exists.
6482 */
6483static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6484{
6485 struct ixgbe_hw *hw = &adapter->hw;
6486 u32 reg, rsave;
6487 int i;
6488
6489 /* 82598 have a static priority to TC mapping that can not
6490 * be changed so no validation is needed.
6491 */
6492 if (hw->mac.type == ixgbe_mac_82598EB)
6493 return;
6494
6495 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6496 rsave = reg;
6497
6498 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6499 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6500
6501 /* If up2tc is out of bounds default to zero */
6502 if (up2tc > tc)
6503 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6504 }
6505
6506 if (reg != rsave)
6507 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6508
6509 return;
6510}
6511
John Fastabend8b1c0b22011-05-03 02:26:48 +00006512/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
6513 * classes.
6514 *
6515 * @netdev: net device to configure
6516 * @tc: number of traffic classes to enable
6517 */
6518int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6519{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006520 struct ixgbe_adapter *adapter = netdev_priv(dev);
6521 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006522
John Fastabende7589ea2011-07-18 22:38:36 +00006523 /* Multiple traffic classes requires multiple queues */
6524 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6525 e_err(drv, "Enable failed, needs MSI-X\n");
6526 return -EINVAL;
6527 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00006528
6529 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006530 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006531 (hw->mac.type == ixgbe_mac_82598EB &&
6532 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006533 return -EINVAL;
6534
6535 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006536 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006537 * hardware is not flexible enough to do this dynamically.
6538 */
6539 if (netif_running(dev))
6540 ixgbe_close(dev);
6541 ixgbe_clear_interrupt_scheme(adapter);
6542
John Fastabende7589ea2011-07-18 22:38:36 +00006543 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006544 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00006545 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006546 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
6547 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6548
6549 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6550 adapter->hw.fc.requested_mode = ixgbe_fc_none;
6551 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006552 netdev_reset_tc(dev);
John Fastabende7589ea2011-07-18 22:38:36 +00006553 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
6554
6555 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6556 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6557
6558 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6559 adapter->dcb_cfg.pfc_mode_enable = false;
6560 }
6561
John Fastabend8b1c0b22011-05-03 02:26:48 +00006562 ixgbe_init_interrupt_scheme(adapter);
6563 ixgbe_validate_rtr(adapter, tc);
6564 if (netif_running(dev))
6565 ixgbe_open(dev);
6566
6567 return 0;
6568}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006569
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006570#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006571void ixgbe_do_reset(struct net_device *netdev)
6572{
6573 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6574
6575 if (netif_running(netdev))
6576 ixgbe_reinit_locked(adapter);
6577 else
6578 ixgbe_reset(adapter);
6579}
6580
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006581static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006582 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006583{
6584 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6585
6586#ifdef CONFIG_DCB
6587 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Alexander Duyck567d2de2012-02-11 07:18:57 +00006588 features &= ~NETIF_F_HW_VLAN_RX;
Don Skidmore082757a2011-07-21 05:55:00 +00006589#endif
6590
6591 /* return error if RXHASH is being enabled when RSS is not supported */
6592 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
Alexander Duyck567d2de2012-02-11 07:18:57 +00006593 features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00006594
6595 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006596 if (!(features & NETIF_F_RXCSUM))
6597 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006598
Alexander Duyck567d2de2012-02-11 07:18:57 +00006599 /* Turn off LRO if not RSC capable */
6600 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6601 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006602
Don Skidmore082757a2011-07-21 05:55:00 +00006603
Alexander Duyck567d2de2012-02-11 07:18:57 +00006604 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006605}
6606
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006607static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006608 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006609{
6610 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006611 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006612 bool need_reset = false;
6613
Don Skidmore082757a2011-07-21 05:55:00 +00006614 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006615 if (!(features & NETIF_F_LRO)) {
6616 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006617 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006618 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6619 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6620 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6621 if (adapter->rx_itr_setting == 1 ||
6622 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6623 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6624 need_reset = true;
6625 } else if ((changed ^ features) & NETIF_F_LRO) {
6626 e_info(probe, "rx-usecs set too low, "
6627 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006628 }
6629 }
6630
6631 /*
6632 * Check if Flow Director n-tuple support was enabled or disabled. If
6633 * the state changed, we need to reset.
6634 */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006635 if (!(features & NETIF_F_NTUPLE)) {
6636 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
6637 /* turn off Flow Director, set ATR and reset */
6638 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
6639 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
6640 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00006641 need_reset = true;
6642 }
Don Skidmore082757a2011-07-21 05:55:00 +00006643 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006644 } else if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
6645 /* turn off ATR, enable perfect filters and reset */
6646 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6647 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00006648 need_reset = true;
6649 }
6650
Ben Greear3f2d1c02012-03-08 08:28:41 +00006651 if (changed & NETIF_F_RXALL)
6652 need_reset = true;
6653
Alexander Duyck567d2de2012-02-11 07:18:57 +00006654 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006655 if (need_reset)
6656 ixgbe_do_reset(netdev);
6657
6658 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006659}
6660
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006661static int ixgbe_ndo_fdb_add(struct ndmsg *ndm,
6662 struct net_device *dev,
6663 unsigned char *addr,
6664 u16 flags)
6665{
6666 struct ixgbe_adapter *adapter = netdev_priv(dev);
6667 int err = -EOPNOTSUPP;
6668
6669 if (ndm->ndm_state & NUD_PERMANENT) {
6670 pr_info("%s: FDB only supports static addresses\n",
6671 ixgbe_driver_name);
6672 return -EINVAL;
6673 }
6674
6675 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6676 if (is_unicast_ether_addr(addr))
6677 err = dev_uc_add_excl(dev, addr);
6678 else if (is_multicast_ether_addr(addr))
6679 err = dev_mc_add_excl(dev, addr);
6680 else
6681 err = -EINVAL;
6682 }
6683
6684 /* Only return duplicate errors if NLM_F_EXCL is set */
6685 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6686 err = 0;
6687
6688 return err;
6689}
6690
6691static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6692 struct net_device *dev,
6693 unsigned char *addr)
6694{
6695 struct ixgbe_adapter *adapter = netdev_priv(dev);
6696 int err = -EOPNOTSUPP;
6697
6698 if (ndm->ndm_state & NUD_PERMANENT) {
6699 pr_info("%s: FDB only supports static addresses\n",
6700 ixgbe_driver_name);
6701 return -EINVAL;
6702 }
6703
6704 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6705 if (is_unicast_ether_addr(addr))
6706 err = dev_uc_del(dev, addr);
6707 else if (is_multicast_ether_addr(addr))
6708 err = dev_mc_del(dev, addr);
6709 else
6710 err = -EINVAL;
6711 }
6712
6713 return err;
6714}
6715
6716static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
6717 struct netlink_callback *cb,
6718 struct net_device *dev,
6719 int idx)
6720{
6721 struct ixgbe_adapter *adapter = netdev_priv(dev);
6722
6723 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6724 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
6725
6726 return idx;
6727}
6728
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006729static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00006730 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006731 .ndo_stop = ixgbe_close,
6732 .ndo_start_xmit = ixgbe_xmit_frame,
6733 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00006734 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006735 .ndo_validate_addr = eth_validate_addr,
6736 .ndo_set_mac_address = ixgbe_set_mac,
6737 .ndo_change_mtu = ixgbe_change_mtu,
6738 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006739 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
6740 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00006741 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00006742 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
6743 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
6744 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00006745 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00006746 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00006747 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006748#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00006749 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006750#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006751#ifdef CONFIG_NET_POLL_CONTROLLER
6752 .ndo_poll_controller = ixgbe_netpoll,
6753#endif
Yi Zou332d4a72009-05-13 13:11:53 +00006754#ifdef IXGBE_FCOE
6755 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00006756 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00006757 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00006758 .ndo_fcoe_enable = ixgbe_fcoe_enable,
6759 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00006760 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00006761 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00006762#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00006763 .ndo_set_features = ixgbe_set_features,
6764 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006765 .ndo_fdb_add = ixgbe_ndo_fdb_add,
6766 .ndo_fdb_del = ixgbe_ndo_fdb_del,
6767 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006768};
6769
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006770static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006771 const struct ixgbe_info *ii)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006772{
6773#ifdef CONFIG_PCI_IOV
6774 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006775
Greg Rosec6bda302011-08-24 02:37:55 +00006776 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006777 return;
6778
6779 /* The 82599 supports up to 64 VFs per physical function
6780 * but this implementation limits allocation to 63 so that
6781 * basic networking resources are still available to the
Greg Rose6b42a9c2012-04-17 04:29:29 +00006782 * physical function. If the user requests greater thn
6783 * 63 VFs then it is an error - reset to default of zero.
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006784 */
Greg Rose6b42a9c2012-04-17 04:29:29 +00006785 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00006786 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006787#endif /* CONFIG_PCI_IOV */
6788}
6789
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006790/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00006791 * ixgbe_wol_supported - Check whether device supports WoL
6792 * @hw: hw specific details
6793 * @device_id: the device ID
6794 * @subdev_id: the subsystem device ID
6795 *
6796 * This function is used by probe and ethtool to determine
6797 * which devices have WoL support
6798 *
6799 **/
6800int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
6801 u16 subdevice_id)
6802{
6803 struct ixgbe_hw *hw = &adapter->hw;
6804 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
6805 int is_wol_supported = 0;
6806
6807 switch (device_id) {
6808 case IXGBE_DEV_ID_82599_SFP:
6809 /* Only these subdevices could supports WOL */
6810 switch (subdevice_id) {
6811 case IXGBE_SUBDEV_ID_82599_560FLR:
6812 /* only support first port */
6813 if (hw->bus.func != 0)
6814 break;
6815 case IXGBE_SUBDEV_ID_82599_SFP:
6816 is_wol_supported = 1;
6817 break;
6818 }
6819 break;
6820 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
6821 /* All except this subdevice support WOL */
6822 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
6823 is_wol_supported = 1;
6824 break;
6825 case IXGBE_DEV_ID_82599_KX4:
6826 is_wol_supported = 1;
6827 break;
6828 case IXGBE_DEV_ID_X540T:
6829 /* check eeprom to see if enabled wol */
6830 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
6831 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
6832 (hw->bus.func == 0))) {
6833 is_wol_supported = 1;
6834 }
6835 break;
6836 }
6837
6838 return is_wol_supported;
6839}
6840
6841/**
Auke Kok9a799d72007-09-15 14:07:45 -07006842 * ixgbe_probe - Device Initialization Routine
6843 * @pdev: PCI device information struct
6844 * @ent: entry in ixgbe_pci_tbl
6845 *
6846 * Returns 0 on success, negative on failure
6847 *
6848 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
6849 * The OS initialization, configuring of the adapter private structure,
6850 * and a hardware reset occur.
6851 **/
6852static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00006853 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07006854{
6855 struct net_device *netdev;
6856 struct ixgbe_adapter *adapter = NULL;
6857 struct ixgbe_hw *hw;
6858 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07006859 static int cards_found;
6860 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00006861 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00006862 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00006863#ifdef IXGBE_FCOE
6864 u16 device_caps;
6865#endif
Don Skidmore289700db2010-12-03 03:32:58 +00006866 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07006867
Andy Gospodarekbded64a2010-07-21 06:40:31 +00006868 /* Catch broken hardware that put the wrong VF device ID in
6869 * the PCIe SR-IOV capability.
6870 */
6871 if (pdev->is_virtfn) {
6872 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
6873 pci_name(pdev), pdev->vendor, pdev->device);
6874 return -EINVAL;
6875 }
6876
gouji-new9ce77662009-05-06 10:44:45 +00006877 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006878 if (err)
6879 return err;
6880
Nick Nunley1b507732010-04-27 13:10:27 +00006881 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
6882 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07006883 pci_using_dac = 1;
6884 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00006885 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07006886 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00006887 err = dma_set_coherent_mask(&pdev->dev,
6888 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07006889 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00006890 dev_err(&pdev->dev,
6891 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006892 goto err_dma;
6893 }
6894 }
6895 pci_using_dac = 0;
6896 }
6897
gouji-new9ce77662009-05-06 10:44:45 +00006898 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00006899 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07006900 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00006901 dev_err(&pdev->dev,
6902 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07006903 goto err_pci_reg;
6904 }
6905
Frans Pop19d5afd2009-10-02 10:04:12 -07006906 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006907
Auke Kok9a799d72007-09-15 14:07:45 -07006908 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07006909 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006910
John Fastabende901acd2011-04-26 07:26:08 +00006911#ifdef CONFIG_IXGBE_DCB
6912 indices *= MAX_TRAFFIC_CLASS;
6913#endif
6914
John Fastabendc85a2612010-02-25 23:15:21 +00006915 if (ii->mac == ixgbe_mac_82598EB)
6916 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
6917 else
6918 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
6919
John Fastabende901acd2011-04-26 07:26:08 +00006920#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00006921 indices += min_t(unsigned int, num_possible_cpus(),
6922 IXGBE_MAX_FCOE_INDICES);
6923#endif
John Fastabendc85a2612010-02-25 23:15:21 +00006924 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07006925 if (!netdev) {
6926 err = -ENOMEM;
6927 goto err_alloc_etherdev;
6928 }
6929
Auke Kok9a799d72007-09-15 14:07:45 -07006930 SET_NETDEV_DEV(netdev, &pdev->dev);
6931
Auke Kok9a799d72007-09-15 14:07:45 -07006932 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006933 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006934
6935 adapter->netdev = netdev;
6936 adapter->pdev = pdev;
6937 hw = &adapter->hw;
6938 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00006939 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07006940
Jeff Kirsher05857982008-09-11 19:57:00 -07006941 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00006942 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07006943 if (!hw->hw_addr) {
6944 err = -EIO;
6945 goto err_ioremap;
6946 }
6947
6948 for (i = 1; i <= 5; i++) {
6949 if (pci_resource_len(pdev, i) == 0)
6950 continue;
6951 }
6952
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006953 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07006954 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006955 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00006956 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07006957
Auke Kok9a799d72007-09-15 14:07:45 -07006958 adapter->bd_number = cards_found;
6959
Auke Kok9a799d72007-09-15 14:07:45 -07006960 /* Setup hw api */
6961 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006962 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07006963
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006964 /* EEPROM */
6965 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
6966 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
6967 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
6968 if (!(eec & (1 << 8)))
6969 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
6970
6971 /* PHY */
6972 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08006973 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00006974 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
6975 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
6976 hw->phy.mdio.mmds = 0;
6977 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
6978 hw->phy.mdio.dev = netdev;
6979 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
6980 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08006981
Don Skidmore8ca783a2009-05-26 20:40:47 -07006982 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006983
6984 /* setup the private structure */
6985 err = ixgbe_sw_init(adapter);
6986 if (err)
6987 goto err_sw_init;
6988
Don Skidmoree86bff02010-02-11 04:14:08 +00006989 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08006990 switch (adapter->hw.mac.type) {
6991 case ixgbe_mac_82599EB:
6992 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00006993 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08006994 break;
6995 default:
6996 break;
6997 }
Don Skidmoree86bff02010-02-11 04:14:08 +00006998
Don Skidmorebf069c92009-05-07 10:39:54 +00006999 /*
7000 * If there is a fan on this device and it has failed log the
7001 * failure.
7002 */
7003 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7004 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7005 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007006 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007007 }
7008
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007009 if (allow_unsupported_sfp)
7010 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7011
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007012 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007013 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007014 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007015 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007016 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7017 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007018 err = 0;
7019 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007020 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007021 "module type was detected.\n");
7022 e_dev_err("Reload the driver after installing a supported "
7023 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007024 goto err_sw_init;
7025 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007026 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007027 goto err_sw_init;
7028 }
7029
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007030 ixgbe_probe_vf(adapter, ii);
7031
Emil Tantilov396e7992010-07-01 20:05:12 +00007032 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007033 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007034 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007035 NETIF_F_HW_VLAN_TX |
7036 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007037 NETIF_F_HW_VLAN_FILTER |
7038 NETIF_F_TSO |
7039 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007040 NETIF_F_RXHASH |
7041 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007042
Don Skidmore082757a2011-07-21 05:55:00 +00007043 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007044
Don Skidmore58be7662011-04-12 09:42:11 +00007045 switch (adapter->hw.mac.type) {
7046 case ixgbe_mac_82599EB:
7047 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007048 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007049 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7050 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007051 break;
7052 default:
7053 break;
7054 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007055
Ben Greear3f2d1c02012-03-08 08:28:41 +00007056 netdev->hw_features |= NETIF_F_RXALL;
7057
Jeff Kirsherad31c402008-06-05 04:05:30 -07007058 netdev->vlan_features |= NETIF_F_TSO;
7059 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007060 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007061 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007062 netdev->vlan_features |= NETIF_F_SG;
7063
Jiri Pirko01789342011-08-16 06:29:00 +00007064 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007065 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007066
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007067 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7068 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7069 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007070
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007071#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007072 netdev->dcbnl_ops = &dcbnl_ops;
7073#endif
7074
Yi Zoueacd73f2009-05-13 13:11:06 +00007075#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007076 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007077 if (hw->mac.ops.get_device_caps) {
7078 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007079 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7080 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007081 }
7082 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007083 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7084 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7085 netdev->vlan_features |= NETIF_F_FSO;
7086 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7087 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007088#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007089 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007090 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007091 netdev->vlan_features |= NETIF_F_HIGHDMA;
7092 }
Auke Kok9a799d72007-09-15 14:07:45 -07007093
Don Skidmore082757a2011-07-21 05:55:00 +00007094 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7095 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007096 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007097 netdev->features |= NETIF_F_LRO;
7098
Auke Kok9a799d72007-09-15 14:07:45 -07007099 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007100 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007101 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007102 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007103 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007104 }
7105
7106 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7107 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7108
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007109 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007110 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007111 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007112 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007113 }
7114
Alexander Duyck70864002011-04-27 09:13:56 +00007115 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007116 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007117
Alexander Duyck70864002011-04-27 09:13:56 +00007118 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7119 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007120
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007121 err = ixgbe_init_interrupt_scheme(adapter);
7122 if (err)
7123 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007124
Don Skidmore082757a2011-07-21 05:55:00 +00007125 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7126 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007127 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007128 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007129
Jacob Keller8e2813f2012-04-21 06:05:40 +00007130 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007131 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007132 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7133 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007134 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007135
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007136 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7137
Emil Tantilov15e52092011-09-29 05:01:29 +00007138 /* save off EEPROM version number */
7139 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7140 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7141
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007142 /* pick up the PCI bus settings for reporting later */
7143 hw->mac.ops.get_bus_info(hw);
7144
Auke Kok9a799d72007-09-15 14:07:45 -07007145 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007146 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007147 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7148 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007149 "Unknown"),
7150 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7151 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7152 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7153 "Unknown"),
7154 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007155
7156 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7157 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007158 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007159 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007160 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007161 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007162 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007163 else
Don Skidmore289700db2010-12-03 03:32:58 +00007164 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7165 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007166
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007167 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007168 e_dev_warn("PCI-Express bandwidth available for this card is "
7169 "not sufficient for optimal performance.\n");
7170 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7171 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007172 }
7173
Auke Kok9a799d72007-09-15 14:07:45 -07007174 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007175 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007176 if (err == IXGBE_ERR_EEPROM_VERSION) {
7177 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007178 e_dev_warn("This device is a pre-production adapter/LOM. "
7179 "Please be aware there may be issues associated "
7180 "with your hardware. If you are experiencing "
7181 "problems please contact your Intel or hardware "
7182 "representative who provided you with this "
7183 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007184 }
Auke Kok9a799d72007-09-15 14:07:45 -07007185 strcpy(netdev->name, "eth%d");
7186 err = register_netdev(netdev);
7187 if (err)
7188 goto err_register;
7189
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007190 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7191 if (hw->mac.ops.disable_tx_laser &&
7192 ((hw->phy.multispeed_fiber) ||
7193 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7194 (hw->mac.type == ixgbe_mac_82599EB))))
7195 hw->mac.ops.disable_tx_laser(hw);
7196
Jesse Brandeburg54386462009-04-17 20:44:27 +00007197 /* carrier off reporting is important to ethtool even BEFORE open */
7198 netif_carrier_off(netdev);
7199
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007200#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007201 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007202 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007203 ixgbe_setup_dca(adapter);
7204 }
7205#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007206 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007207 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007208 for (i = 0; i < adapter->num_vfs; i++)
7209 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7210 }
7211
Jacob Keller2466dd92011-09-08 03:50:54 +00007212 /* firmware requires driver version to be 0xFFFFFFFF
7213 * since os does not support feature
7214 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007215 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007216 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7217 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007218
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007219 /* add san mac addr to netdev */
7220 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007221
Neerav Parikhea818752012-01-04 20:23:40 +00007222 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007223 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007224
7225 if (ixgbe_sysfs_init(adapter))
7226 e_err(probe, "failed to allocate sysfs resources\n");
7227
Auke Kok9a799d72007-09-15 14:07:45 -07007228 return 0;
7229
7230err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007231 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007232 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007233err_sw_init:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007234 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7235 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007236 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007237 iounmap(hw->hw_addr);
7238err_ioremap:
7239 free_netdev(netdev);
7240err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007241 pci_release_selected_regions(pdev,
7242 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007243err_pci_reg:
7244err_dma:
7245 pci_disable_device(pdev);
7246 return err;
7247}
7248
7249/**
7250 * ixgbe_remove - Device Removal Routine
7251 * @pdev: PCI device information struct
7252 *
7253 * ixgbe_remove is called by the PCI subsystem to alert the driver
7254 * that it should release a PCI device. The could be caused by a
7255 * Hot-Plug event, or because the driver is going to be removed from
7256 * memory.
7257 **/
7258static void __devexit ixgbe_remove(struct pci_dev *pdev)
7259{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007260 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7261 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007262
7263 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007264 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007265
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007266#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007267 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7268 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7269 dca_remove_requester(&pdev->dev);
7270 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7271 }
7272
7273#endif
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007274 ixgbe_sysfs_exit(adapter);
7275
Yi Zou332d4a72009-05-13 13:11:53 +00007276#ifdef IXGBE_FCOE
7277 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7278 ixgbe_cleanup_fcoe(adapter);
7279
7280#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007281
7282 /* remove the added san mac */
7283 ixgbe_del_sanmac_netdev(netdev);
7284
Donald Skidmorec4900be2008-11-20 21:11:42 -08007285 if (netdev->reg_state == NETREG_REGISTERED)
7286 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007287
Greg Rosec6bda302011-08-24 02:37:55 +00007288 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7289 if (!(ixgbe_check_vf_assignment(adapter)))
7290 ixgbe_disable_sriov(adapter);
7291 else
7292 e_dev_warn("Unloading driver while VFs are assigned "
7293 "- VFs will not be deallocated\n");
7294 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007295
Alexander Duyck7a921c92009-05-06 10:43:28 +00007296 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007297
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007298 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007299
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007300#ifdef CONFIG_DCB
7301 kfree(adapter->ixgbe_ieee_pfc);
7302 kfree(adapter->ixgbe_ieee_ets);
7303
7304#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007305 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007306 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007307 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007308
Emil Tantilov849c4542010-06-03 16:53:41 +00007309 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007310
Auke Kok9a799d72007-09-15 14:07:45 -07007311 free_netdev(netdev);
7312
Frans Pop19d5afd2009-10-02 10:04:12 -07007313 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007314
Auke Kok9a799d72007-09-15 14:07:45 -07007315 pci_disable_device(pdev);
7316}
7317
7318/**
7319 * ixgbe_io_error_detected - called when PCI error is detected
7320 * @pdev: Pointer to PCI device
7321 * @state: The current pci connection state
7322 *
7323 * This function is called after a PCI bus error affecting
7324 * this device has been detected.
7325 */
7326static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007327 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007328{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007329 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7330 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007331
Greg Rose83c61fa2011-09-07 05:59:35 +00007332#ifdef CONFIG_PCI_IOV
7333 struct pci_dev *bdev, *vfdev;
7334 u32 dw0, dw1, dw2, dw3;
7335 int vf, pos;
7336 u16 req_id, pf_func;
7337
7338 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7339 adapter->num_vfs == 0)
7340 goto skip_bad_vf_detection;
7341
7342 bdev = pdev->bus->self;
7343 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
7344 bdev = bdev->bus->self;
7345
7346 if (!bdev)
7347 goto skip_bad_vf_detection;
7348
7349 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7350 if (!pos)
7351 goto skip_bad_vf_detection;
7352
7353 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7354 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7355 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7356 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7357
7358 req_id = dw1 >> 16;
7359 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7360 if (!(req_id & 0x0080))
7361 goto skip_bad_vf_detection;
7362
7363 pf_func = req_id & 0x01;
7364 if ((pf_func & 1) == (pdev->devfn & 1)) {
7365 unsigned int device_id;
7366
7367 vf = (req_id & 0x7F) >> 1;
7368 e_dev_err("VF %d has caused a PCIe error\n", vf);
7369 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7370 "%8.8x\tdw3: %8.8x\n",
7371 dw0, dw1, dw2, dw3);
7372 switch (adapter->hw.mac.type) {
7373 case ixgbe_mac_82599EB:
7374 device_id = IXGBE_82599_VF_DEVICE_ID;
7375 break;
7376 case ixgbe_mac_X540:
7377 device_id = IXGBE_X540_VF_DEVICE_ID;
7378 break;
7379 default:
7380 device_id = 0;
7381 break;
7382 }
7383
7384 /* Find the pci device of the offending VF */
7385 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
7386 while (vfdev) {
7387 if (vfdev->devfn == (req_id & 0xFF))
7388 break;
7389 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
7390 device_id, vfdev);
7391 }
7392 /*
7393 * There's a slim chance the VF could have been hot plugged,
7394 * so if it is no longer present we don't need to issue the
7395 * VFLR. Just clean up the AER in that case.
7396 */
7397 if (vfdev) {
7398 e_dev_err("Issuing VFLR to VF %d\n", vf);
7399 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7400 }
7401
7402 pci_cleanup_aer_uncorrect_error_status(pdev);
7403 }
7404
7405 /*
7406 * Even though the error may have occurred on the other port
7407 * we still need to increment the vf error reference count for
7408 * both ports because the I/O resume function will be called
7409 * for both of them.
7410 */
7411 adapter->vferr_refcount++;
7412
7413 return PCI_ERS_RESULT_RECOVERED;
7414
7415skip_bad_vf_detection:
7416#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007417 netif_device_detach(netdev);
7418
Breno Leitao3044b8d2009-05-06 10:44:26 +00007419 if (state == pci_channel_io_perm_failure)
7420 return PCI_ERS_RESULT_DISCONNECT;
7421
Auke Kok9a799d72007-09-15 14:07:45 -07007422 if (netif_running(netdev))
7423 ixgbe_down(adapter);
7424 pci_disable_device(pdev);
7425
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007426 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007427 return PCI_ERS_RESULT_NEED_RESET;
7428}
7429
7430/**
7431 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7432 * @pdev: Pointer to PCI device
7433 *
7434 * Restart the card from scratch, as if from a cold-boot.
7435 */
7436static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7437{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007438 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007439 pci_ers_result_t result;
7440 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007441
gouji-new9ce77662009-05-06 10:44:45 +00007442 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007443 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007444 result = PCI_ERS_RESULT_DISCONNECT;
7445 } else {
7446 pci_set_master(pdev);
7447 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007448 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007449
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007450 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007451
7452 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007453 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007454 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007455 }
Auke Kok9a799d72007-09-15 14:07:45 -07007456
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007457 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7458 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007459 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7460 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007461 /* non-fatal, continue */
7462 }
Auke Kok9a799d72007-09-15 14:07:45 -07007463
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007464 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007465}
7466
7467/**
7468 * ixgbe_io_resume - called when traffic can start flowing again.
7469 * @pdev: Pointer to PCI device
7470 *
7471 * This callback is called when the error recovery driver tells us that
7472 * its OK to resume normal operation.
7473 */
7474static void ixgbe_io_resume(struct pci_dev *pdev)
7475{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007476 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7477 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007478
Greg Rose83c61fa2011-09-07 05:59:35 +00007479#ifdef CONFIG_PCI_IOV
7480 if (adapter->vferr_refcount) {
7481 e_info(drv, "Resuming after VF err\n");
7482 adapter->vferr_refcount--;
7483 return;
7484 }
7485
7486#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007487 if (netif_running(netdev))
7488 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007489
7490 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007491}
7492
7493static struct pci_error_handlers ixgbe_err_handler = {
7494 .error_detected = ixgbe_io_error_detected,
7495 .slot_reset = ixgbe_io_slot_reset,
7496 .resume = ixgbe_io_resume,
7497};
7498
7499static struct pci_driver ixgbe_driver = {
7500 .name = ixgbe_driver_name,
7501 .id_table = ixgbe_pci_tbl,
7502 .probe = ixgbe_probe,
7503 .remove = __devexit_p(ixgbe_remove),
7504#ifdef CONFIG_PM
7505 .suspend = ixgbe_suspend,
7506 .resume = ixgbe_resume,
7507#endif
7508 .shutdown = ixgbe_shutdown,
7509 .err_handler = &ixgbe_err_handler
7510};
7511
7512/**
7513 * ixgbe_init_module - Driver Registration Routine
7514 *
7515 * ixgbe_init_module is the first routine called when the driver is
7516 * loaded. All it does is register with the PCI subsystem.
7517 **/
7518static int __init ixgbe_init_module(void)
7519{
7520 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007521 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007522 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007523
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007524#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007525 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007526#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007527
Auke Kok9a799d72007-09-15 14:07:45 -07007528 ret = pci_register_driver(&ixgbe_driver);
7529 return ret;
7530}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007531
Auke Kok9a799d72007-09-15 14:07:45 -07007532module_init(ixgbe_init_module);
7533
7534/**
7535 * ixgbe_exit_module - Driver Exit Cleanup Routine
7536 *
7537 * ixgbe_exit_module is called just before the driver is removed
7538 * from memory.
7539 **/
7540static void __exit ixgbe_exit_module(void)
7541{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007542#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007543 dca_unregister_notify(&dca_notifier);
7544#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007545 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007546 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007547}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007548
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007549#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007550static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007551 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007552{
7553 int ret_val;
7554
7555 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007556 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007557
7558 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7559}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007560
Alexander Duyckb4533682009-03-31 21:32:42 +00007561#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007562
Auke Kok9a799d72007-09-15 14:07:45 -07007563module_exit(ixgbe_exit_module);
7564
7565/* ixgbe_main.c */