blob: 1693ec3d4046f4a70128d6acdfbda7e324124766 [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
Alexander Duyck943561d2012-05-09 22:14:44 -0700613static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
614{
615 struct ixgbe_hw *hw = &adapter->hw;
616 struct ixgbe_hw_stats *hwstats = &adapter->stats;
617 int i;
618 u32 data;
619
620 if ((hw->fc.current_mode != ixgbe_fc_full) &&
621 (hw->fc.current_mode != ixgbe_fc_rx_pause))
622 return;
623
624 switch (hw->mac.type) {
625 case ixgbe_mac_82598EB:
626 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
627 break;
628 default:
629 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
630 }
631 hwstats->lxoffrxc += data;
632
633 /* refill credits (no tx hang) if we received xoff */
634 if (!data)
635 return;
636
637 for (i = 0; i < adapter->num_tx_queues; i++)
638 clear_bit(__IXGBE_HANG_CHECK_ARMED,
639 &adapter->tx_ring[i]->state);
640}
641
John Fastabendc84d3242010-11-16 19:27:12 -0800642static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700643{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700644 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800645 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800646 u32 xoff[8] = {0};
647 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700648 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700649
Alexander Duyck943561d2012-05-09 22:14:44 -0700650 if (adapter->ixgbe_ieee_pfc)
651 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800652
Alexander Duyck943561d2012-05-09 22:14:44 -0700653 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
654 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800655 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700656 }
John Fastabendc84d3242010-11-16 19:27:12 -0800657
658 /* update stats for each tc, only valid with PFC enabled */
659 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
660 switch (hw->mac.type) {
661 case ixgbe_mac_82598EB:
662 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
663 break;
664 default:
665 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
666 }
667 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700668 }
669
John Fastabendc84d3242010-11-16 19:27:12 -0800670 /* disarm tx queues that have received xoff frames */
671 for (i = 0; i < adapter->num_tx_queues; i++) {
672 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000673 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800674
675 if (xoff[tc])
676 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
677 }
678}
679
680static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
681{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000682 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800683}
684
685static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
686{
687 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
688 struct ixgbe_hw *hw = &adapter->hw;
689
690 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
691 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
692
693 if (head != tail)
694 return (head < tail) ?
695 tail - head : (tail + ring->count - head);
696
697 return 0;
698}
699
700static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
701{
702 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
703 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
704 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
705 bool ret = false;
706
707 clear_check_for_tx_hang(tx_ring);
708
709 /*
710 * Check for a hung queue, but be thorough. This verifies
711 * that a transmit has been completed since the previous
712 * check AND there is at least one packet pending. The
713 * ARMED bit is set to indicate a potential hang. The
714 * bit is cleared if a pause frame is received to remove
715 * false hang detection due to PFC or 802.3x frames. By
716 * requiring this to fail twice we avoid races with
717 * pfc clearing the ARMED bit and conditions where we
718 * run the check_tx_hang logic with a transmit completion
719 * pending but without time to complete it yet.
720 */
721 if ((tx_done_old == tx_done) && tx_pending) {
722 /* make sure it is true for two checks in a row */
723 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
724 &tx_ring->state);
725 } else {
726 /* update completed stats and continue */
727 tx_ring->tx_stats.tx_done_old = tx_done;
728 /* reset the countdown */
729 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
730 }
731
732 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700733}
734
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000735/**
736 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
737 * @adapter: driver private struct
738 **/
739static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
740{
741
742 /* Do the reset outside of interrupt context */
743 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
744 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
745 ixgbe_service_event_schedule(adapter);
746 }
747}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700748
Auke Kok9a799d72007-09-15 14:07:45 -0700749/**
750 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000751 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700752 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700753 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000754static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000755 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700756{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000757 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000758 struct ixgbe_tx_buffer *tx_buffer;
759 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700760 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000761 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000762 unsigned int i = tx_ring->next_to_clean;
763
764 if (test_bit(__IXGBE_DOWN, &adapter->state))
765 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700766
Alexander Duyckd3d00232011-07-15 02:31:25 +0000767 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000768 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000769 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800770
Alexander Duyck729739b2012-02-08 07:51:06 +0000771 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000772 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700773
Alexander Duyckd3d00232011-07-15 02:31:25 +0000774 /* if next_to_watch is not set then there is no work pending */
775 if (!eop_desc)
776 break;
777
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000778 /* prevent any other reads prior to eop_desc */
779 rmb();
780
Alexander Duyckd3d00232011-07-15 02:31:25 +0000781 /* if DD is not set pending work has not been completed */
782 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
783 break;
784
Alexander Duyckd3d00232011-07-15 02:31:25 +0000785 /* clear next_to_watch to prevent false hangs */
786 tx_buffer->next_to_watch = NULL;
787
Alexander Duyck091a6242012-02-08 07:51:01 +0000788 /* update the statistics for this packet */
789 total_bytes += tx_buffer->bytecount;
790 total_packets += tx_buffer->gso_segs;
791
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000792 /* free the skb */
793 dev_kfree_skb_any(tx_buffer->skb);
794
Alexander Duyck729739b2012-02-08 07:51:06 +0000795 /* unmap skb header data */
796 dma_unmap_single(tx_ring->dev,
797 dma_unmap_addr(tx_buffer, dma),
798 dma_unmap_len(tx_buffer, len),
799 DMA_TO_DEVICE);
800
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000801 /* clear tx_buffer data */
802 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000803 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000804
Alexander Duyck729739b2012-02-08 07:51:06 +0000805 /* unmap remaining buffers */
806 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000807 tx_buffer++;
808 tx_desc++;
809 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000810 if (unlikely(!i)) {
811 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000812 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000813 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000814 }
815
Alexander Duyck729739b2012-02-08 07:51:06 +0000816 /* unmap any remaining paged data */
817 if (dma_unmap_len(tx_buffer, len)) {
818 dma_unmap_page(tx_ring->dev,
819 dma_unmap_addr(tx_buffer, dma),
820 dma_unmap_len(tx_buffer, len),
821 DMA_TO_DEVICE);
822 dma_unmap_len_set(tx_buffer, len, 0);
823 }
824 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800825
Alexander Duyck729739b2012-02-08 07:51:06 +0000826 /* move us one more past the eop_desc for start of next pkt */
827 tx_buffer++;
828 tx_desc++;
829 i++;
830 if (unlikely(!i)) {
831 i -= tx_ring->count;
832 tx_buffer = tx_ring->tx_buffer_info;
833 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
834 }
835
836 /* issue prefetch for next Tx descriptor */
837 prefetch(tx_desc);
838
839 /* update budget accounting */
840 budget--;
841 } while (likely(budget));
842
843 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700844 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000845 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800846 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000847 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000848 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000849 q_vector->tx.total_bytes += total_bytes;
850 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800851
John Fastabendc84d3242010-11-16 19:27:12 -0800852 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800853 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800854 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800855 e_err(drv, "Detected Tx Unit Hang\n"
856 " Tx Queue <%d>\n"
857 " TDH, TDT <%x>, <%x>\n"
858 " next_to_use <%x>\n"
859 " next_to_clean <%x>\n"
860 "tx_buffer_info[next_to_clean]\n"
861 " time_stamp <%lx>\n"
862 " jiffies <%lx>\n",
863 tx_ring->queue_index,
864 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
865 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000866 tx_ring->next_to_use, i,
867 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800868
869 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
870
871 e_info(probe,
872 "tx hang %d detected on queue %d, resetting adapter\n",
873 adapter->tx_timeout_count + 1, tx_ring->queue_index);
874
875 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000876 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800877
878 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000879 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800880 }
Auke Kok9a799d72007-09-15 14:07:45 -0700881
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000882 netdev_tx_completed_queue(txring_txq(tx_ring),
883 total_packets, total_bytes);
884
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800885#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000886 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000887 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800888 /* Make sure that anybody stopping the queue after this
889 * sees the new next_to_clean.
890 */
891 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000892 if (__netif_subqueue_stopped(tx_ring->netdev,
893 tx_ring->queue_index)
894 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
895 netif_wake_subqueue(tx_ring->netdev,
896 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800897 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800898 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800899 }
Auke Kok9a799d72007-09-15 14:07:45 -0700900
Alexander Duyck59224552011-08-31 00:01:06 +0000901 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700902}
903
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400904#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800905static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800906 struct ixgbe_ring *tx_ring,
907 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800908{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000909 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000910 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
911 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800912
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800913 switch (hw->mac.type) {
914 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000915 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800916 break;
917 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800918 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000919 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
920 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
921 break;
922 default:
923 /* for unknown hardware do not write register */
924 return;
925 }
926
927 /*
928 * We can enable relaxed ordering for reads, but not writes when
929 * DCA is enabled. This is due to a known issue in some chipsets
930 * which will cause the DCA tag to be cleared.
931 */
932 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
933 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
934 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
935
936 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
937}
938
939static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
940 struct ixgbe_ring *rx_ring,
941 int cpu)
942{
943 struct ixgbe_hw *hw = &adapter->hw;
944 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
945 u8 reg_idx = rx_ring->reg_idx;
946
947
948 switch (hw->mac.type) {
949 case ixgbe_mac_82599EB:
950 case ixgbe_mac_X540:
951 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800952 break;
953 default:
954 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800955 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000956
957 /*
958 * We can enable relaxed ordering for reads, but not writes when
959 * DCA is enabled. This is due to a known issue in some chipsets
960 * which will cause the DCA tag to be cleared.
961 */
962 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
963 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
964 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
965
966 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800967}
968
969static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
970{
971 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000972 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800973 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800974
975 if (q_vector->cpu == cpu)
976 goto out_no_update;
977
Alexander Duycka5579282012-02-08 07:50:04 +0000978 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000979 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800980
Alexander Duycka5579282012-02-08 07:50:04 +0000981 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000982 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800983
984 q_vector->cpu = cpu;
985out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800986 put_cpu();
987}
988
989static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
990{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800991 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800992 int i;
993
994 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
995 return;
996
Alexander Duycke35ec122009-05-21 13:07:12 +0000997 /* always use CB2 mode, difference is masked in the CB driver */
998 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
999
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001000 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1001 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1002 else
1003 num_q_vectors = 1;
1004
1005 for (i = 0; i < num_q_vectors; i++) {
1006 adapter->q_vector[i]->cpu = -1;
1007 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001008 }
1009}
1010
1011static int __ixgbe_notify_dca(struct device *dev, void *data)
1012{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001013 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001014 unsigned long event = *(unsigned long *)data;
1015
Don Skidmore2a72c312011-07-20 02:27:05 +00001016 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001017 return 0;
1018
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001019 switch (event) {
1020 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001021 /* if we're already enabled, don't do it again */
1022 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1023 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001024 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001025 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001026 ixgbe_setup_dca(adapter);
1027 break;
1028 }
1029 /* Fall Through since DCA is disabled. */
1030 case DCA_PROVIDER_REMOVE:
1031 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1032 dca_remove_requester(dev);
1033 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1034 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1035 }
1036 break;
1037 }
1038
Denis V. Lunev652f0932008-03-27 14:39:17 +03001039 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001040}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001041
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001042#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001043static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1044 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001045 struct sk_buff *skb)
1046{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001047 if (ring->netdev->features & NETIF_F_RXHASH)
1048 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001049}
1050
Alexander Duyckf8003262012-03-03 02:35:52 +00001051#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001052/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001053 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1054 * @adapter: address of board private structure
1055 * @rx_desc: advanced rx descriptor
1056 *
1057 * Returns : true if it is FCoE pkt
1058 */
1059static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1060 union ixgbe_adv_rx_desc *rx_desc)
1061{
1062 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1063
1064 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1065 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1066 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1067 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1068}
1069
Alexander Duyckf8003262012-03-03 02:35:52 +00001070#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001071/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001072 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001073 * @ring: structure containing ring specific data
1074 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001075 * @skb: skb currently being received and modified
1076 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001077static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001078 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001079 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001080{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001081 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001082
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001083 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001084 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001085 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001086
1087 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001088 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1089 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001090 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001091 return;
1092 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001093
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001094 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001095 return;
1096
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001097 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001098 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001099
1100 /*
1101 * 82599 errata, UDP frames with a 0 checksum can be marked as
1102 * checksum errors.
1103 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001104 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1105 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001106 return;
1107
Alexander Duyck8a0da212012-01-31 02:59:49 +00001108 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001109 return;
1110 }
1111
Auke Kok9a799d72007-09-15 14:07:45 -07001112 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001113 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001114}
1115
Alexander Duyck84ea2592010-11-16 19:26:49 -08001116static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001117{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001118 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001119
1120 /* update next to alloc since we have filled the ring */
1121 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001122 /*
1123 * Force memory writes to complete before letting h/w
1124 * know there are new descriptors to fetch. (Only
1125 * applicable for weak-ordered memory model archs,
1126 * such as IA-64).
1127 */
1128 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001129 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001130}
1131
Alexander Duyckf990b792012-01-31 02:59:34 +00001132static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1133 struct ixgbe_rx_buffer *bi)
1134{
1135 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001136 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001137
Alexander Duyckf8003262012-03-03 02:35:52 +00001138 /* since we are recycling buffers we should seldom need to alloc */
1139 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001140 return true;
1141
Alexander Duyckf8003262012-03-03 02:35:52 +00001142 /* alloc new page for storage */
1143 if (likely(!page)) {
1144 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1145 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001146 if (unlikely(!page)) {
1147 rx_ring->rx_stats.alloc_rx_page_failed++;
1148 return false;
1149 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001150 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001151 }
1152
Alexander Duyckf8003262012-03-03 02:35:52 +00001153 /* map page for use */
1154 dma = dma_map_page(rx_ring->dev, page, 0,
1155 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001156
Alexander Duyckf8003262012-03-03 02:35:52 +00001157 /*
1158 * if mapping failed free memory back to system since
1159 * there isn't much point in holding memory we can't use
1160 */
1161 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001162 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001163 bi->page = NULL;
1164
Alexander Duyckf990b792012-01-31 02:59:34 +00001165 rx_ring->rx_stats.alloc_rx_page_failed++;
1166 return false;
1167 }
1168
Alexander Duyckf8003262012-03-03 02:35:52 +00001169 bi->dma = dma;
1170 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1171
Alexander Duyckf990b792012-01-31 02:59:34 +00001172 return true;
1173}
1174
Auke Kok9a799d72007-09-15 14:07:45 -07001175/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001176 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001177 * @rx_ring: ring to place buffers on
1178 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001179 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001180void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001181{
Auke Kok9a799d72007-09-15 14:07:45 -07001182 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001183 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001184 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001185
Alexander Duyckf8003262012-03-03 02:35:52 +00001186 /* nothing to do */
1187 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001188 return;
1189
Alexander Duycke4f74022012-01-31 02:59:44 +00001190 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001191 bi = &rx_ring->rx_buffer_info[i];
1192 i -= rx_ring->count;
1193
Alexander Duyckf8003262012-03-03 02:35:52 +00001194 do {
1195 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001196 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001197
Alexander Duyckf8003262012-03-03 02:35:52 +00001198 /*
1199 * Refresh the desc even if buffer_addrs didn't change
1200 * because each write-back erases this info.
1201 */
1202 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001203
Alexander Duyckf990b792012-01-31 02:59:34 +00001204 rx_desc++;
1205 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001206 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001207 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001208 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001209 bi = rx_ring->rx_buffer_info;
1210 i -= rx_ring->count;
1211 }
1212
1213 /* clear the hdr_addr for the next_to_use descriptor */
1214 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001215
1216 cleaned_count--;
1217 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001218
Alexander Duyckf990b792012-01-31 02:59:34 +00001219 i += rx_ring->count;
1220
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001221 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001222 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001223}
1224
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001225/**
1226 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1227 * @data: pointer to the start of the headers
1228 * @max_len: total length of section to find headers in
1229 *
1230 * This function is meant to determine the length of headers that will
1231 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1232 * motivation of doing this is to only perform one pull for IPv4 TCP
1233 * packets so that we can do basic things like calculating the gso_size
1234 * based on the average data per packet.
1235 **/
1236static unsigned int ixgbe_get_headlen(unsigned char *data,
1237 unsigned int max_len)
1238{
1239 union {
1240 unsigned char *network;
1241 /* l2 headers */
1242 struct ethhdr *eth;
1243 struct vlan_hdr *vlan;
1244 /* l3 headers */
1245 struct iphdr *ipv4;
1246 } hdr;
1247 __be16 protocol;
1248 u8 nexthdr = 0; /* default to not TCP */
1249 u8 hlen;
1250
1251 /* this should never happen, but better safe than sorry */
1252 if (max_len < ETH_HLEN)
1253 return max_len;
1254
1255 /* initialize network frame pointer */
1256 hdr.network = data;
1257
1258 /* set first protocol and move network header forward */
1259 protocol = hdr.eth->h_proto;
1260 hdr.network += ETH_HLEN;
1261
1262 /* handle any vlan tag if present */
1263 if (protocol == __constant_htons(ETH_P_8021Q)) {
1264 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1265 return max_len;
1266
1267 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1268 hdr.network += VLAN_HLEN;
1269 }
1270
1271 /* handle L3 protocols */
1272 if (protocol == __constant_htons(ETH_P_IP)) {
1273 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1274 return max_len;
1275
1276 /* access ihl as a u8 to avoid unaligned access on ia64 */
1277 hlen = (hdr.network[0] & 0x0F) << 2;
1278
1279 /* verify hlen meets minimum size requirements */
1280 if (hlen < sizeof(struct iphdr))
1281 return hdr.network - data;
1282
1283 /* record next protocol */
1284 nexthdr = hdr.ipv4->protocol;
1285 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001286#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001287 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1288 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1289 return max_len;
1290 hdr.network += FCOE_HEADER_LEN;
1291#endif
1292 } else {
1293 return hdr.network - data;
1294 }
1295
1296 /* finally sort out TCP */
1297 if (nexthdr == IPPROTO_TCP) {
1298 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1299 return max_len;
1300
1301 /* access doff as a u8 to avoid unaligned access on ia64 */
1302 hlen = (hdr.network[12] & 0xF0) >> 2;
1303
1304 /* verify hlen meets minimum size requirements */
1305 if (hlen < sizeof(struct tcphdr))
1306 return hdr.network - data;
1307
1308 hdr.network += hlen;
1309 }
1310
1311 /*
1312 * If everything has gone correctly hdr.network should be the
1313 * data section of the packet and will be the end of the header.
1314 * If not then it probably represents the end of the last recognized
1315 * header.
1316 */
1317 if ((hdr.network - data) < max_len)
1318 return hdr.network - data;
1319 else
1320 return max_len;
1321}
1322
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001323static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1324 union ixgbe_adv_rx_desc *rx_desc,
1325 struct sk_buff *skb)
1326{
1327 __le32 rsc_enabled;
1328 u32 rsc_cnt;
1329
1330 if (!ring_is_rsc_enabled(rx_ring))
1331 return;
1332
1333 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1334 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1335
1336 /* If this is an RSC frame rsc_cnt should be non-zero */
1337 if (!rsc_enabled)
1338 return;
1339
1340 rsc_cnt = le32_to_cpu(rsc_enabled);
1341 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1342
1343 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001344}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001345
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001346static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1347 struct sk_buff *skb)
1348{
Alexander Duyckf8003262012-03-03 02:35:52 +00001349 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001350
1351 /* set gso_size to avoid messing up TCP MSS */
1352 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1353 IXGBE_CB(skb)->append_cnt);
1354}
1355
1356static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1357 struct sk_buff *skb)
1358{
1359 /* if append_cnt is 0 then frame is not RSC */
1360 if (!IXGBE_CB(skb)->append_cnt)
1361 return;
1362
1363 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1364 rx_ring->rx_stats.rsc_flush++;
1365
1366 ixgbe_set_rsc_gso_size(rx_ring, skb);
1367
1368 /* gso_size is computed using append_cnt so always clear it last */
1369 IXGBE_CB(skb)->append_cnt = 0;
1370}
1371
Alexander Duyck8a0da212012-01-31 02:59:49 +00001372/**
1373 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1374 * @rx_ring: rx descriptor ring packet is being transacted on
1375 * @rx_desc: pointer to the EOP Rx descriptor
1376 * @skb: pointer to current skb being populated
1377 *
1378 * This function checks the ring, descriptor, and packet information in
1379 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1380 * other fields within the skb.
1381 **/
1382static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1383 union ixgbe_adv_rx_desc *rx_desc,
1384 struct sk_buff *skb)
1385{
1386 ixgbe_update_rsc_stats(rx_ring, skb);
1387
1388 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1389
1390 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1391
1392 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1393 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1394 __vlan_hwaccel_put_tag(skb, vid);
1395 }
1396
1397 skb_record_rx_queue(skb, rx_ring->queue_index);
1398
1399 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1400}
1401
1402static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1403 struct sk_buff *skb)
1404{
1405 struct ixgbe_adapter *adapter = q_vector->adapter;
1406
1407 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1408 napi_gro_receive(&q_vector->napi, skb);
1409 else
1410 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001411}
1412
Alexander Duyckf8003262012-03-03 02:35:52 +00001413/**
1414 * ixgbe_is_non_eop - process handling of non-EOP buffers
1415 * @rx_ring: Rx ring being processed
1416 * @rx_desc: Rx descriptor for current buffer
1417 * @skb: Current socket buffer containing buffer in progress
1418 *
1419 * This function updates next to clean. If the buffer is an EOP buffer
1420 * this function exits returning false, otherwise it will place the
1421 * sk_buff in the next buffer to be chained and return true indicating
1422 * that this is in fact a non-EOP buffer.
1423 **/
1424static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1425 union ixgbe_adv_rx_desc *rx_desc,
1426 struct sk_buff *skb)
1427{
1428 u32 ntc = rx_ring->next_to_clean + 1;
1429
1430 /* fetch, update, and store next to clean */
1431 ntc = (ntc < rx_ring->count) ? ntc : 0;
1432 rx_ring->next_to_clean = ntc;
1433
1434 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1435
1436 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1437 return false;
1438
1439 /* append_cnt indicates packet is RSC, if so fetch nextp */
1440 if (IXGBE_CB(skb)->append_cnt) {
1441 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1442 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1443 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1444 }
1445
1446 /* place skb in next buffer to be received */
1447 rx_ring->rx_buffer_info[ntc].skb = skb;
1448 rx_ring->rx_stats.non_eop_descs++;
1449
1450 return true;
1451}
1452
1453/**
1454 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1455 * @rx_ring: rx descriptor ring packet is being transacted on
1456 * @rx_desc: pointer to the EOP Rx descriptor
1457 * @skb: pointer to current skb being fixed
1458 *
1459 * Check for corrupted packet headers caused by senders on the local L2
1460 * embedded NIC switch not setting up their Tx Descriptors right. These
1461 * should be very rare.
1462 *
1463 * Also address the case where we are pulling data in on pages only
1464 * and as such no data is present in the skb header.
1465 *
1466 * In addition if skb is not at least 60 bytes we need to pad it so that
1467 * it is large enough to qualify as a valid Ethernet frame.
1468 *
1469 * Returns true if an error was encountered and skb was freed.
1470 **/
1471static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1472 union ixgbe_adv_rx_desc *rx_desc,
1473 struct sk_buff *skb)
1474{
1475 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1476 struct net_device *netdev = rx_ring->netdev;
1477 unsigned char *va;
1478 unsigned int pull_len;
1479
1480 /* if the page was released unmap it, else just sync our portion */
1481 if (unlikely(IXGBE_CB(skb)->page_released)) {
1482 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1483 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1484 IXGBE_CB(skb)->page_released = false;
1485 } else {
1486 dma_sync_single_range_for_cpu(rx_ring->dev,
1487 IXGBE_CB(skb)->dma,
1488 frag->page_offset,
1489 ixgbe_rx_bufsz(rx_ring),
1490 DMA_FROM_DEVICE);
1491 }
1492 IXGBE_CB(skb)->dma = 0;
1493
1494 /* verify that the packet does not have any known errors */
1495 if (unlikely(ixgbe_test_staterr(rx_desc,
1496 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1497 !(netdev->features & NETIF_F_RXALL))) {
1498 dev_kfree_skb_any(skb);
1499 return true;
1500 }
1501
1502 /*
1503 * it is valid to use page_address instead of kmap since we are
1504 * working with pages allocated out of the lomem pool per
1505 * alloc_page(GFP_ATOMIC)
1506 */
1507 va = skb_frag_address(frag);
1508
1509 /*
1510 * we need the header to contain the greater of either ETH_HLEN or
1511 * 60 bytes if the skb->len is less than 60 for skb_pad.
1512 */
1513 pull_len = skb_frag_size(frag);
1514 if (pull_len > 256)
1515 pull_len = ixgbe_get_headlen(va, pull_len);
1516
1517 /* align pull length to size of long to optimize memcpy performance */
1518 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1519
1520 /* update all of the pointers */
1521 skb_frag_size_sub(frag, pull_len);
1522 frag->page_offset += pull_len;
1523 skb->data_len -= pull_len;
1524 skb->tail += pull_len;
1525
1526 /*
1527 * if we sucked the frag empty then we should free it,
1528 * if there are other frags here something is screwed up in hardware
1529 */
1530 if (skb_frag_size(frag) == 0) {
1531 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1532 skb_shinfo(skb)->nr_frags = 0;
1533 __skb_frag_unref(frag);
1534 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1535 }
1536
1537 /* if skb_pad returns an error the skb was freed */
1538 if (unlikely(skb->len < 60)) {
1539 int pad_len = 60 - skb->len;
1540
1541 if (skb_pad(skb, pad_len))
1542 return true;
1543 __skb_put(skb, pad_len);
1544 }
1545
1546 return false;
1547}
1548
1549/**
1550 * ixgbe_can_reuse_page - determine if we can reuse a page
1551 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1552 *
1553 * Returns true if page can be reused in another Rx buffer
1554 **/
1555static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1556{
1557 struct page *page = rx_buffer->page;
1558
1559 /* if we are only owner of page and it is local we can reuse it */
1560 return likely(page_count(page) == 1) &&
1561 likely(page_to_nid(page) == numa_node_id());
1562}
1563
1564/**
1565 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1566 * @rx_ring: rx descriptor ring to store buffers on
1567 * @old_buff: donor buffer to have page reused
1568 *
1569 * Syncronizes page for reuse by the adapter
1570 **/
1571static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1572 struct ixgbe_rx_buffer *old_buff)
1573{
1574 struct ixgbe_rx_buffer *new_buff;
1575 u16 nta = rx_ring->next_to_alloc;
1576 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1577
1578 new_buff = &rx_ring->rx_buffer_info[nta];
1579
1580 /* update, and store next to alloc */
1581 nta++;
1582 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1583
1584 /* transfer page from old buffer to new buffer */
1585 new_buff->page = old_buff->page;
1586 new_buff->dma = old_buff->dma;
1587
1588 /* flip page offset to other buffer and store to new_buff */
1589 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1590
1591 /* sync the buffer for use by the device */
1592 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1593 new_buff->page_offset, bufsz,
1594 DMA_FROM_DEVICE);
1595
1596 /* bump ref count on page before it is given to the stack */
1597 get_page(new_buff->page);
1598}
1599
1600/**
1601 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1602 * @rx_ring: rx descriptor ring to transact packets on
1603 * @rx_buffer: buffer containing page to add
1604 * @rx_desc: descriptor containing length of buffer written by hardware
1605 * @skb: sk_buff to place the data into
1606 *
1607 * This function is based on skb_add_rx_frag. I would have used that
1608 * function however it doesn't handle the truesize case correctly since we
1609 * are allocating more memory than might be used for a single receive.
1610 **/
1611static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1612 struct ixgbe_rx_buffer *rx_buffer,
1613 struct sk_buff *skb, int size)
1614{
1615 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1616 rx_buffer->page, rx_buffer->page_offset,
1617 size);
1618 skb->len += size;
1619 skb->data_len += size;
1620 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1621}
1622
1623/**
1624 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1625 * @q_vector: structure containing interrupt and ring information
1626 * @rx_ring: rx descriptor ring to transact packets on
1627 * @budget: Total limit on number of packets to process
1628 *
1629 * This function provides a "bounce buffer" approach to Rx interrupt
1630 * processing. The advantage to this is that on systems that have
1631 * expensive overhead for IOMMU access this provides a means of avoiding
1632 * it by maintaining the mapping of the page to the syste.
1633 *
1634 * Returns true if all work is completed without reaching budget
1635 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001636static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001637 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001638 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001639{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001640 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001641#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001642 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001643 int ddp_bytes = 0;
1644#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001645 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001646
Alexander Duyckf8003262012-03-03 02:35:52 +00001647 do {
1648 struct ixgbe_rx_buffer *rx_buffer;
1649 union ixgbe_adv_rx_desc *rx_desc;
1650 struct sk_buff *skb;
1651 struct page *page;
1652 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001653
Alexander Duyckf8003262012-03-03 02:35:52 +00001654 /* return some buffers to hardware, one at a time is too slow */
1655 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1656 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1657 cleaned_count = 0;
1658 }
Auke Kok9a799d72007-09-15 14:07:45 -07001659
Alexander Duyckf8003262012-03-03 02:35:52 +00001660 ntc = rx_ring->next_to_clean;
1661 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1662 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001663
Alexander Duyckf8003262012-03-03 02:35:52 +00001664 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1665 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001666
Alexander Duyckf8003262012-03-03 02:35:52 +00001667 /*
1668 * This memory barrier is needed to keep us from reading
1669 * any other fields out of the rx_desc until we know the
1670 * RXD_STAT_DD bit is set
1671 */
1672 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001673
Alexander Duyckf8003262012-03-03 02:35:52 +00001674 page = rx_buffer->page;
1675 prefetchw(page);
1676
1677 skb = rx_buffer->skb;
1678
1679 if (likely(!skb)) {
1680 void *page_addr = page_address(page) +
1681 rx_buffer->page_offset;
1682
1683 /* prefetch first cache line of first page */
1684 prefetch(page_addr);
1685#if L1_CACHE_BYTES < 128
1686 prefetch(page_addr + L1_CACHE_BYTES);
1687#endif
1688
1689 /* allocate a skb to store the frags */
1690 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1691 IXGBE_RX_HDR_SIZE);
1692 if (unlikely(!skb)) {
1693 rx_ring->rx_stats.alloc_rx_buff_failed++;
1694 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001695 }
1696
Alexander Duyckf8003262012-03-03 02:35:52 +00001697 /*
1698 * we will be copying header into skb->data in
1699 * pskb_may_pull so it is in our interest to prefetch
1700 * it now to avoid a possible cache miss
1701 */
1702 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001703
1704 /*
1705 * Delay unmapping of the first packet. It carries the
1706 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001707 * after the writeback. Only unmap it when EOP is
1708 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001709 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001710 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001711 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001712 /* we are reusing so sync this buffer for CPU use */
1713 dma_sync_single_range_for_cpu(rx_ring->dev,
1714 rx_buffer->dma,
1715 rx_buffer->page_offset,
1716 ixgbe_rx_bufsz(rx_ring),
1717 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001718 }
1719
Alexander Duyckf8003262012-03-03 02:35:52 +00001720 /* pull page into skb */
1721 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1722 le16_to_cpu(rx_desc->wb.upper.length));
1723
1724 if (ixgbe_can_reuse_page(rx_buffer)) {
1725 /* hand second half of page back to the ring */
1726 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1727 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1728 /* the page has been released from the ring */
1729 IXGBE_CB(skb)->page_released = true;
1730 } else {
1731 /* we are not reusing the buffer so unmap it */
1732 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1733 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001734 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001735 }
1736
Alexander Duyckf8003262012-03-03 02:35:52 +00001737 /* clear contents of buffer_info */
1738 rx_buffer->skb = NULL;
1739 rx_buffer->dma = 0;
1740 rx_buffer->page = NULL;
1741
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001742 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1743
Auke Kok9a799d72007-09-15 14:07:45 -07001744 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001745
Alexander Duyckf8003262012-03-03 02:35:52 +00001746 /* place incomplete frames back on ring for completion */
1747 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1748 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001749
Alexander Duyckf8003262012-03-03 02:35:52 +00001750 /* verify the packet layout is correct */
1751 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1752 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001753
1754 /* probably a little skewed due to removing CRC */
1755 total_rx_bytes += skb->len;
1756 total_rx_packets++;
1757
Alexander Duyck8a0da212012-01-31 02:59:49 +00001758 /* populate checksum, timestamp, VLAN, and protocol */
1759 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1760
Yi Zou332d4a72009-05-13 13:11:53 +00001761#ifdef IXGBE_FCOE
1762 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001763 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001764 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001765 if (!ddp_bytes) {
1766 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001767 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001768 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001769 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001770
Yi Zou332d4a72009-05-13 13:11:53 +00001771#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001772 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001773
Alexander Duyckf8003262012-03-03 02:35:52 +00001774 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001775 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001776 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001777
Yi Zou3d8fd382009-06-08 14:38:44 +00001778#ifdef IXGBE_FCOE
1779 /* include DDPed FCoE data */
1780 if (ddp_bytes > 0) {
1781 unsigned int mss;
1782
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001783 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001784 sizeof(struct fc_frame_header) -
1785 sizeof(struct fcoe_crc_eof);
1786 if (mss > 512)
1787 mss &= ~511;
1788 total_rx_bytes += ddp_bytes;
1789 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1790 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001791
Alexander Duyckf8003262012-03-03 02:35:52 +00001792#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001793 u64_stats_update_begin(&rx_ring->syncp);
1794 rx_ring->stats.packets += total_rx_packets;
1795 rx_ring->stats.bytes += total_rx_bytes;
1796 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001797 q_vector->rx.total_packets += total_rx_packets;
1798 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001799
Alexander Duyckf8003262012-03-03 02:35:52 +00001800 if (cleaned_count)
1801 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1802
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001803 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001804}
1805
Auke Kok9a799d72007-09-15 14:07:45 -07001806/**
1807 * ixgbe_configure_msix - Configure MSI-X hardware
1808 * @adapter: board private structure
1809 *
1810 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1811 * interrupts.
1812 **/
1813static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1814{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001815 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001816 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001817 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001818
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001819 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1820
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001821 /* Populate MSIX to EITR Select */
1822 if (adapter->num_vfs > 32) {
1823 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1824 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1825 }
1826
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001827 /*
1828 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001829 * corresponding register.
1830 */
1831 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001832 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001833 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001834
Alexander Duycka5579282012-02-08 07:50:04 +00001835 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001836 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001837
Alexander Duycka5579282012-02-08 07:50:04 +00001838 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001839 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001840
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001841 if (q_vector->tx.ring && !q_vector->rx.ring) {
1842 /* tx only vector */
1843 if (adapter->tx_itr_setting == 1)
1844 q_vector->itr = IXGBE_10K_ITR;
1845 else
1846 q_vector->itr = adapter->tx_itr_setting;
1847 } else {
1848 /* rx or rx/tx vector */
1849 if (adapter->rx_itr_setting == 1)
1850 q_vector->itr = IXGBE_20K_ITR;
1851 else
1852 q_vector->itr = adapter->rx_itr_setting;
1853 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001854
Alexander Duyckfe49f042009-06-04 16:00:09 +00001855 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001856 }
1857
Alexander Duyckbd508172010-11-16 19:27:03 -08001858 switch (adapter->hw.mac.type) {
1859 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001860 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001861 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001862 break;
1863 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001864 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001865 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001866 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001867 default:
1868 break;
1869 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001870 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001871
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001872 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001873 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001874 mask &= ~(IXGBE_EIMS_OTHER |
1875 IXGBE_EIMS_MAILBOX |
1876 IXGBE_EIMS_LSC);
1877
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001878 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001879}
1880
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001881enum latency_range {
1882 lowest_latency = 0,
1883 low_latency = 1,
1884 bulk_latency = 2,
1885 latency_invalid = 255
1886};
1887
1888/**
1889 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001890 * @q_vector: structure containing interrupt and ring information
1891 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001892 *
1893 * Stores a new ITR value based on packets and byte
1894 * counts during the last interrupt. The advantage of per interrupt
1895 * computation is faster updates and more accurate ITR for the current
1896 * traffic pattern. Constants in this function were computed
1897 * based on theoretical maximum wire speed and thresholds were set based
1898 * on testing data as well as attempting to minimize response time
1899 * while increasing bulk throughput.
1900 * this functionality is controlled by the InterruptThrottleRate module
1901 * parameter (see ixgbe_param.c)
1902 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001903static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1904 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001905{
Alexander Duyckbd198052011-06-11 01:45:08 +00001906 int bytes = ring_container->total_bytes;
1907 int packets = ring_container->total_packets;
1908 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001909 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001910 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001911
1912 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001913 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001914
1915 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001916 * 0-10MB/s lowest (100000 ints/s)
1917 * 10-20MB/s low (20000 ints/s)
1918 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001919 */
1920 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001921 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001922 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1923
1924 switch (itr_setting) {
1925 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001926 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001927 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001928 break;
1929 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001930 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001931 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001932 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001933 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001934 break;
1935 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001936 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001937 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001938 break;
1939 }
1940
Alexander Duyckbd198052011-06-11 01:45:08 +00001941 /* clear work counters since we have the values we need */
1942 ring_container->total_bytes = 0;
1943 ring_container->total_packets = 0;
1944
1945 /* write updated itr to ring container */
1946 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001947}
1948
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001949/**
1950 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001951 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001952 *
1953 * This function is made to be called by ethtool and by the driver
1954 * when it needs to update EITR registers at runtime. Hardware
1955 * specific quirks/differences are taken care of here.
1956 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001957void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001958{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001959 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001960 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001961 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001962 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001963
Alexander Duyckbd508172010-11-16 19:27:03 -08001964 switch (adapter->hw.mac.type) {
1965 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001966 /* must write high and low 16 bits to reset counter */
1967 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001968 break;
1969 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001970 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001971 /*
1972 * set the WDIS bit to not clear the timer bits and cause an
1973 * immediate assertion of the interrupt
1974 */
1975 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001976 break;
1977 default:
1978 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001979 }
1980 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1981}
1982
Alexander Duyckbd198052011-06-11 01:45:08 +00001983static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001984{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001985 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001986 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001987
Alexander Duyckbd198052011-06-11 01:45:08 +00001988 ixgbe_update_itr(q_vector, &q_vector->tx);
1989 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001990
Alexander Duyck08c88332011-06-11 01:45:03 +00001991 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001992
1993 switch (current_itr) {
1994 /* counts and packets in update_itr are dependent on these numbers */
1995 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001996 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001997 break;
1998 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001999 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002000 break;
2001 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002002 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002003 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002004 default:
2005 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002006 }
2007
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002008 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002009 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002010 new_itr = (10 * new_itr * q_vector->itr) /
2011 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002012
Alexander Duyckbd198052011-06-11 01:45:08 +00002013 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002014 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002015
2016 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002017 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002018}
2019
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002020/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002021 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002022 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002023 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002024static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002025{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002026 struct ixgbe_hw *hw = &adapter->hw;
2027 u32 eicr = adapter->interrupt_event;
2028
Alexander Duyckf0f97782011-04-22 04:08:09 +00002029 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002030 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002031
Alexander Duyckf0f97782011-04-22 04:08:09 +00002032 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2033 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2034 return;
2035
2036 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2037
Joe Perches7ca647b2010-09-07 21:35:40 +00002038 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002039 case IXGBE_DEV_ID_82599_T3_LOM:
2040 /*
2041 * Since the warning interrupt is for both ports
2042 * we don't have to check if:
2043 * - This interrupt wasn't for our port.
2044 * - We may have missed the interrupt so always have to
2045 * check if we got a LSC
2046 */
2047 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2048 !(eicr & IXGBE_EICR_LSC))
2049 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002050
Alexander Duyckf0f97782011-04-22 04:08:09 +00002051 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2052 u32 autoneg;
2053 bool link_up = false;
2054
Joe Perches7ca647b2010-09-07 21:35:40 +00002055 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2056
Alexander Duyckf0f97782011-04-22 04:08:09 +00002057 if (link_up)
2058 return;
2059 }
2060
2061 /* Check if this is not due to overtemp */
2062 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2063 return;
2064
2065 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002066 default:
2067 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2068 return;
2069 break;
2070 }
2071 e_crit(drv,
2072 "Network adapter has been stopped because it has over heated. "
2073 "Restart the computer. If the problem persists, "
2074 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002075
2076 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002077}
2078
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002079static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2080{
2081 struct ixgbe_hw *hw = &adapter->hw;
2082
2083 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2084 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002085 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002086 /* write to clear the interrupt */
2087 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2088 }
2089}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002090
Jacob Keller4f51bf72011-08-20 04:49:45 +00002091static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2092{
2093 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2094 return;
2095
2096 switch (adapter->hw.mac.type) {
2097 case ixgbe_mac_82599EB:
2098 /*
2099 * Need to check link state so complete overtemp check
2100 * on service task
2101 */
2102 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2103 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2104 adapter->interrupt_event = eicr;
2105 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2106 ixgbe_service_event_schedule(adapter);
2107 return;
2108 }
2109 return;
2110 case ixgbe_mac_X540:
2111 if (!(eicr & IXGBE_EICR_TS))
2112 return;
2113 break;
2114 default:
2115 return;
2116 }
2117
2118 e_crit(drv,
2119 "Network adapter has been stopped because it has over heated. "
2120 "Restart the computer. If the problem persists, "
2121 "power off the system and replace the adapter\n");
2122}
2123
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002124static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2125{
2126 struct ixgbe_hw *hw = &adapter->hw;
2127
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002128 if (eicr & IXGBE_EICR_GPI_SDP2) {
2129 /* Clear the interrupt */
2130 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002131 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2132 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2133 ixgbe_service_event_schedule(adapter);
2134 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002135 }
2136
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002137 if (eicr & IXGBE_EICR_GPI_SDP1) {
2138 /* Clear the interrupt */
2139 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002140 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2141 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2142 ixgbe_service_event_schedule(adapter);
2143 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002144 }
2145}
2146
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002147static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2148{
2149 struct ixgbe_hw *hw = &adapter->hw;
2150
2151 adapter->lsc_int++;
2152 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2153 adapter->link_check_timeout = jiffies;
2154 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2155 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002156 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002157 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002158 }
2159}
2160
Alexander Duyckfe49f042009-06-04 16:00:09 +00002161static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2162 u64 qmask)
2163{
2164 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002165 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002166
Alexander Duyckbd508172010-11-16 19:27:03 -08002167 switch (hw->mac.type) {
2168 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002169 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002170 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2171 break;
2172 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002173 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002174 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002175 if (mask)
2176 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002177 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002178 if (mask)
2179 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2180 break;
2181 default:
2182 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002183 }
2184 /* skip the flush */
2185}
2186
2187static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002188 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002189{
2190 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002191 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002192
Alexander Duyckbd508172010-11-16 19:27:03 -08002193 switch (hw->mac.type) {
2194 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002195 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002196 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2197 break;
2198 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002199 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002200 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002201 if (mask)
2202 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002203 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002204 if (mask)
2205 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2206 break;
2207 default:
2208 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002209 }
2210 /* skip the flush */
2211}
2212
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002213/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002214 * ixgbe_irq_enable - Enable default interrupt generation settings
2215 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002216 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002217static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2218 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002219{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002220 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002221
Alexander Duyck2c4af692011-07-15 07:29:55 +00002222 /* don't reenable LSC while waiting for link */
2223 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2224 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002225
Alexander Duyck2c4af692011-07-15 07:29:55 +00002226 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002227 switch (adapter->hw.mac.type) {
2228 case ixgbe_mac_82599EB:
2229 mask |= IXGBE_EIMS_GPI_SDP0;
2230 break;
2231 case ixgbe_mac_X540:
2232 mask |= IXGBE_EIMS_TS;
2233 break;
2234 default:
2235 break;
2236 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002237 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2238 mask |= IXGBE_EIMS_GPI_SDP1;
2239 switch (adapter->hw.mac.type) {
2240 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002241 mask |= IXGBE_EIMS_GPI_SDP1;
2242 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002243 case ixgbe_mac_X540:
2244 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002245 mask |= IXGBE_EIMS_MAILBOX;
2246 break;
2247 default:
2248 break;
2249 }
2250 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2251 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2252 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002253
Alexander Duyck2c4af692011-07-15 07:29:55 +00002254 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2255 if (queues)
2256 ixgbe_irq_enable_queues(adapter, ~0);
2257 if (flush)
2258 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002259}
2260
Alexander Duyck2c4af692011-07-15 07:29:55 +00002261static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002262{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002263 struct ixgbe_adapter *adapter = data;
2264 struct ixgbe_hw *hw = &adapter->hw;
2265 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002266
Alexander Duyck2c4af692011-07-15 07:29:55 +00002267 /*
2268 * Workaround for Silicon errata. Use clear-by-write instead
2269 * of clear-by-read. Reading with EICS will return the
2270 * interrupt causes without clearing, which later be done
2271 * with the write to EICR.
2272 */
2273 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2274 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002275
Alexander Duyck2c4af692011-07-15 07:29:55 +00002276 if (eicr & IXGBE_EICR_LSC)
2277 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002278
Alexander Duyck2c4af692011-07-15 07:29:55 +00002279 if (eicr & IXGBE_EICR_MAILBOX)
2280 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002281
Alexander Duyck2c4af692011-07-15 07:29:55 +00002282 switch (hw->mac.type) {
2283 case ixgbe_mac_82599EB:
2284 case ixgbe_mac_X540:
2285 if (eicr & IXGBE_EICR_ECC)
2286 e_info(link, "Received unrecoverable ECC Err, please "
2287 "reboot\n");
2288 /* Handle Flow Director Full threshold interrupt */
2289 if (eicr & IXGBE_EICR_FLOW_DIR) {
2290 int reinit_count = 0;
2291 int i;
2292 for (i = 0; i < adapter->num_tx_queues; i++) {
2293 struct ixgbe_ring *ring = adapter->tx_ring[i];
2294 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2295 &ring->state))
2296 reinit_count++;
2297 }
2298 if (reinit_count) {
2299 /* no more flow director interrupts until after init */
2300 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2301 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2302 ixgbe_service_event_schedule(adapter);
2303 }
2304 }
2305 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002306 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002307 break;
2308 default:
2309 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002310 }
2311
Alexander Duyck2c4af692011-07-15 07:29:55 +00002312 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002313
Alexander Duyck2c4af692011-07-15 07:29:55 +00002314 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002315 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002316 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002317
Alexander Duyck2c4af692011-07-15 07:29:55 +00002318 return IRQ_HANDLED;
2319}
2320
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002321static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002322{
2323 struct ixgbe_q_vector *q_vector = data;
2324
Auke Kok9a799d72007-09-15 14:07:45 -07002325 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002326
2327 if (q_vector->rx.ring || q_vector->tx.ring)
2328 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002329
2330 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002331}
2332
Auke Kok9a799d72007-09-15 14:07:45 -07002333/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002334 * ixgbe_poll - NAPI Rx polling callback
2335 * @napi: structure for representing this polling device
2336 * @budget: how many packets driver is allowed to clean
2337 *
2338 * This function is used for legacy and MSI, NAPI mode
2339 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002340int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002341{
2342 struct ixgbe_q_vector *q_vector =
2343 container_of(napi, struct ixgbe_q_vector, napi);
2344 struct ixgbe_adapter *adapter = q_vector->adapter;
2345 struct ixgbe_ring *ring;
2346 int per_ring_budget;
2347 bool clean_complete = true;
2348
2349#ifdef CONFIG_IXGBE_DCA
2350 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2351 ixgbe_update_dca(q_vector);
2352#endif
2353
2354 ixgbe_for_each_ring(ring, q_vector->tx)
2355 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2356
2357 /* attempt to distribute budget to each queue fairly, but don't allow
2358 * the budget to go below 1 because we'll exit polling */
2359 if (q_vector->rx.count > 1)
2360 per_ring_budget = max(budget/q_vector->rx.count, 1);
2361 else
2362 per_ring_budget = budget;
2363
2364 ixgbe_for_each_ring(ring, q_vector->rx)
2365 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2366 per_ring_budget);
2367
2368 /* If all work not completed, return budget and keep polling */
2369 if (!clean_complete)
2370 return budget;
2371
2372 /* all work done, exit the polling mode */
2373 napi_complete(napi);
2374 if (adapter->rx_itr_setting & 1)
2375 ixgbe_set_itr(q_vector);
2376 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2377 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2378
2379 return 0;
2380}
2381
2382/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002383 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2384 * @adapter: board private structure
2385 *
2386 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2387 * interrupts from the kernel.
2388 **/
2389static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2390{
2391 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002392 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2393 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002394 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002395
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002396 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002397 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002398 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002399
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002400 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002401 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002402 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002403 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002404 } else if (q_vector->rx.ring) {
2405 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2406 "%s-%s-%d", netdev->name, "rx", ri++);
2407 } else if (q_vector->tx.ring) {
2408 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2409 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002410 } else {
2411 /* skip this unused q_vector */
2412 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002413 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002414 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2415 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002416 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002417 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002418 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002419 goto free_queue_irqs;
2420 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002421 /* If Flow Director is enabled, set interrupt affinity */
2422 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2423 /* assign the mask for this irq */
2424 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002425 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002426 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002427 }
2428
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002429 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002430 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002431 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002432 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002433 goto free_queue_irqs;
2434 }
2435
2436 return 0;
2437
2438free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002439 while (vector) {
2440 vector--;
2441 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2442 NULL);
2443 free_irq(adapter->msix_entries[vector].vector,
2444 adapter->q_vector[vector]);
2445 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002446 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2447 pci_disable_msix(adapter->pdev);
2448 kfree(adapter->msix_entries);
2449 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450 return err;
2451}
2452
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002453/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002454 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002455 * @irq: interrupt number
2456 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002457 **/
2458static irqreturn_t ixgbe_intr(int irq, void *data)
2459{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002460 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002461 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002462 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002463 u32 eicr;
2464
Don Skidmore54037502009-02-21 15:42:56 -08002465 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002466 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002467 * before the read of EICR.
2468 */
2469 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2470
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002471 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002472 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002473 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002474 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002475 /*
2476 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002477 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002478 * have disabled interrupts due to EIAM
2479 * finish the workaround of silicon errata on 82598. Unmask
2480 * the interrupt that we masked before the EICR read.
2481 */
2482 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2483 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002484 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002485 }
Auke Kok9a799d72007-09-15 14:07:45 -07002486
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002487 if (eicr & IXGBE_EICR_LSC)
2488 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002489
Alexander Duyckbd508172010-11-16 19:27:03 -08002490 switch (hw->mac.type) {
2491 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002492 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002493 /* Fall through */
2494 case ixgbe_mac_X540:
2495 if (eicr & IXGBE_EICR_ECC)
2496 e_info(link, "Received unrecoverable ECC err, please "
2497 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002498 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002499 break;
2500 default:
2501 break;
2502 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002503
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002504 ixgbe_check_fan_failure(adapter, eicr);
2505
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002506 /* would disable interrupts here but EIAM disabled it */
2507 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002508
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002509 /*
2510 * re-enable link(maybe) and non-queue interrupts, no flush.
2511 * ixgbe_poll will re-enable the queue interrupts
2512 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002513 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2514 ixgbe_irq_enable(adapter, false, false);
2515
Auke Kok9a799d72007-09-15 14:07:45 -07002516 return IRQ_HANDLED;
2517}
2518
2519/**
2520 * ixgbe_request_irq - initialize interrupts
2521 * @adapter: board private structure
2522 *
2523 * Attempts to configure interrupts using the best available
2524 * capabilities of the hardware and kernel.
2525 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002526static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002527{
2528 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002530
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002531 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002533 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002534 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002535 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002536 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002537 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002538 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002539
Alexander Duyckde88eee2012-02-08 07:49:59 +00002540 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002541 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002542
Auke Kok9a799d72007-09-15 14:07:45 -07002543 return err;
2544}
2545
2546static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2547{
Auke Kok9a799d72007-09-15 14:07:45 -07002548 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002549 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002550
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002551 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002552 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002553 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002554 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002555
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002556 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002557 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002558 if (!adapter->q_vector[i]->rx.ring &&
2559 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002560 continue;
2561
Alexander Duyck207867f2011-07-15 03:05:37 +00002562 /* clear the affinity_mask in the IRQ descriptor */
2563 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2564 NULL);
2565
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002566 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002567 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002568 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002569 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002570 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002571 }
2572}
2573
2574/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002575 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2576 * @adapter: board private structure
2577 **/
2578static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2579{
Alexander Duyckbd508172010-11-16 19:27:03 -08002580 switch (adapter->hw.mac.type) {
2581 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002582 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002583 break;
2584 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002585 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002586 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2587 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002588 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002589 break;
2590 default:
2591 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002592 }
2593 IXGBE_WRITE_FLUSH(&adapter->hw);
2594 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2595 int i;
2596 for (i = 0; i < adapter->num_msix_vectors; i++)
2597 synchronize_irq(adapter->msix_entries[i].vector);
2598 } else {
2599 synchronize_irq(adapter->pdev->irq);
2600 }
2601}
2602
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002603/**
Auke Kok9a799d72007-09-15 14:07:45 -07002604 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2605 *
2606 **/
2607static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2608{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002609 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002610
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002611 /* rx/tx vector */
2612 if (adapter->rx_itr_setting == 1)
2613 q_vector->itr = IXGBE_20K_ITR;
2614 else
2615 q_vector->itr = adapter->rx_itr_setting;
2616
2617 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002618
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002619 ixgbe_set_ivar(adapter, 0, 0, 0);
2620 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002621
Emil Tantilov396e7992010-07-01 20:05:12 +00002622 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002623}
2624
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002625/**
2626 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2627 * @adapter: board private structure
2628 * @ring: structure containing ring specific data
2629 *
2630 * Configure the Tx descriptor ring after a reset.
2631 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002632void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2633 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002634{
2635 struct ixgbe_hw *hw = &adapter->hw;
2636 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002637 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002638 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002639 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002640
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002641 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002642 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002643 IXGBE_WRITE_FLUSH(hw);
2644
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002645 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002646 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002647 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2648 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2649 ring->count * sizeof(union ixgbe_adv_tx_desc));
2650 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2651 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002652 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002653
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002654 /*
2655 * set WTHRESH to encourage burst writeback, it should not be set
2656 * higher than 1 when ITR is 0 as it could cause false TX hangs
2657 *
2658 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2659 * to or less than the number of on chip descriptors, which is
2660 * currently 40.
2661 */
Alexander Duycke954b372012-02-08 07:49:38 +00002662 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002663 txdctl |= (1 << 16); /* WTHRESH = 1 */
2664 else
2665 txdctl |= (8 << 16); /* WTHRESH = 8 */
2666
Alexander Duycke954b372012-02-08 07:49:38 +00002667 /*
2668 * Setting PTHRESH to 32 both improves performance
2669 * and avoids a TX hang with DFP enabled
2670 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002671 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2672 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002673
2674 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002675 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2676 adapter->atr_sample_rate) {
2677 ring->atr_sample_rate = adapter->atr_sample_rate;
2678 ring->atr_count = 0;
2679 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2680 } else {
2681 ring->atr_sample_rate = 0;
2682 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002683
John Fastabendc84d3242010-11-16 19:27:12 -08002684 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2685
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002686 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002687 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2688
2689 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2690 if (hw->mac.type == ixgbe_mac_82598EB &&
2691 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2692 return;
2693
2694 /* poll to verify queue is enabled */
2695 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002696 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002697 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2698 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2699 if (!wait_loop)
2700 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002701}
2702
Alexander Duyck120ff942010-08-19 13:34:50 +00002703static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2704{
2705 struct ixgbe_hw *hw = &adapter->hw;
2706 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002707 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002708 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002709
2710 if (hw->mac.type == ixgbe_mac_82598EB)
2711 return;
2712
2713 /* disable the arbiter while setting MTQC */
2714 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2715 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2716 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2717
2718 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002719 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002720 case (IXGBE_FLAG_SRIOV_ENABLED):
2721 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2722 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2723 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002724 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002725 if (!tcs)
2726 reg = IXGBE_MTQC_64Q_1PB;
2727 else if (tcs <= 4)
2728 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2729 else
2730 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2731
2732 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2733
2734 /* Enable Security TX Buffer IFG for multiple pb */
2735 if (tcs) {
2736 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2737 reg |= IXGBE_SECTX_DCB;
2738 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2739 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002740 break;
2741 }
2742
2743 /* re-enable the arbiter */
2744 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2745 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2746}
2747
Auke Kok9a799d72007-09-15 14:07:45 -07002748/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002749 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002750 * @adapter: board private structure
2751 *
2752 * Configure the Tx unit of the MAC after a reset.
2753 **/
2754static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2755{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002756 struct ixgbe_hw *hw = &adapter->hw;
2757 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002758 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002759
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002760 ixgbe_setup_mtqc(adapter);
2761
2762 if (hw->mac.type != ixgbe_mac_82598EB) {
2763 /* DMATXCTL.EN must be before Tx queues are enabled */
2764 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2765 dmatxctl |= IXGBE_DMATXCTL_TE;
2766 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2767 }
2768
Auke Kok9a799d72007-09-15 14:07:45 -07002769 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002770 for (i = 0; i < adapter->num_tx_queues; i++)
2771 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002772}
2773
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002774static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2775 struct ixgbe_ring *ring)
2776{
2777 struct ixgbe_hw *hw = &adapter->hw;
2778 u8 reg_idx = ring->reg_idx;
2779 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2780
2781 srrctl |= IXGBE_SRRCTL_DROP_EN;
2782
2783 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2784}
2785
2786static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2787 struct ixgbe_ring *ring)
2788{
2789 struct ixgbe_hw *hw = &adapter->hw;
2790 u8 reg_idx = ring->reg_idx;
2791 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2792
2793 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2794
2795 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2796}
2797
2798#ifdef CONFIG_IXGBE_DCB
2799void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2800#else
2801static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2802#endif
2803{
2804 int i;
2805 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2806
2807 if (adapter->ixgbe_ieee_pfc)
2808 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2809
2810 /*
2811 * We should set the drop enable bit if:
2812 * SR-IOV is enabled
2813 * or
2814 * Number of Rx queues > 1 and flow control is disabled
2815 *
2816 * This allows us to avoid head of line blocking for security
2817 * and performance reasons.
2818 */
2819 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2820 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2821 for (i = 0; i < adapter->num_rx_queues; i++)
2822 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2823 } else {
2824 for (i = 0; i < adapter->num_rx_queues; i++)
2825 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2826 }
2827}
2828
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002829#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002830
Yi Zoua6616b42009-08-06 13:05:23 +00002831static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002832 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002833{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002834 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002835 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002836
Alexander Duyckbd508172010-11-16 19:27:03 -08002837 switch (adapter->hw.mac.type) {
2838 case ixgbe_mac_82598EB: {
2839 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2840 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002841 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002842 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002843 break;
2844 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002845 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002846 default:
2847 break;
2848 }
2849
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002850 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002851
2852 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2853 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002854 if (adapter->num_vfs)
2855 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002856
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002857 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2858 IXGBE_SRRCTL_BSIZEHDR_MASK;
2859
Alexander Duyckf8003262012-03-03 02:35:52 +00002860#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2861 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002862#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002863 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002864#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002865 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002866
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002867 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002868}
2869
Alexander Duyck05abb122010-08-19 13:35:41 +00002870static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002871{
Alexander Duyck05abb122010-08-19 13:35:41 +00002872 struct ixgbe_hw *hw = &adapter->hw;
2873 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002874 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2875 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002876 u32 mrqc = 0, reta = 0;
2877 u32 rxcsum;
2878 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002879 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002880 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2881
2882 if (tcs)
2883 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002884
Alexander Duyck05abb122010-08-19 13:35:41 +00002885 /* Fill out hash function seeds */
2886 for (i = 0; i < 10; i++)
2887 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002888
Alexander Duyck05abb122010-08-19 13:35:41 +00002889 /* Fill out redirection table */
2890 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002891 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002892 j = 0;
2893 /* reta = 4-byte sliding window of
2894 * 0x00..(indices-1)(indices-1)00..etc. */
2895 reta = (reta << 8) | (j * 0x11);
2896 if ((i & 3) == 3)
2897 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2898 }
2899
2900 /* Disable indicating checksum in descriptor, enables RSS hash */
2901 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2902 rxcsum |= IXGBE_RXCSUM_PCSD;
2903 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2904
John Fastabend8b1c0b22011-05-03 02:26:48 +00002905 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2906 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002907 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002908 } else {
2909 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2910 | IXGBE_FLAG_SRIOV_ENABLED);
2911
2912 switch (mask) {
2913 case (IXGBE_FLAG_RSS_ENABLED):
2914 if (!tcs)
2915 mrqc = IXGBE_MRQC_RSSEN;
2916 else if (tcs <= 4)
2917 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2918 else
2919 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2920 break;
2921 case (IXGBE_FLAG_SRIOV_ENABLED):
2922 mrqc = IXGBE_MRQC_VMDQEN;
2923 break;
2924 default:
2925 break;
2926 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002927 }
2928
Alexander Duyck05abb122010-08-19 13:35:41 +00002929 /* Perform hash on these packet types */
2930 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2931 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2932 | IXGBE_MRQC_RSS_FIELD_IPV6
2933 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2934
Alexander Duyckef6afc02012-02-08 07:51:53 +00002935 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2936 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
2937 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2938 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2939
Alexander Duyck05abb122010-08-19 13:35:41 +00002940 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002941}
2942
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002943/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002944 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2945 * @adapter: address of board private structure
2946 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002947 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002948static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002949 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002950{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002951 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002952 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002953 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002954
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002955 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002956 return;
2957
Alexander Duyck73670962010-08-19 13:38:34 +00002958 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002959 rscctrl |= IXGBE_RSCCTL_RSCEN;
2960 /*
2961 * we must limit the number of descriptors so that the
2962 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002963 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002964 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002965#if (PAGE_SIZE <= 8192)
2966 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2967#elif (PAGE_SIZE <= 16384)
2968 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002969#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002970 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002971#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002972 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002973}
2974
Alexander Duyck9e10e042010-08-19 13:40:06 +00002975#define IXGBE_MAX_RX_DESC_POLL 10
2976static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2977 struct ixgbe_ring *ring)
2978{
2979 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002980 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2981 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002982 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002983
2984 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2985 if (hw->mac.type == ixgbe_mac_82598EB &&
2986 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2987 return;
2988
2989 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002990 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002991 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2992 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2993
2994 if (!wait_loop) {
2995 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2996 "the polling period\n", reg_idx);
2997 }
2998}
2999
Yi Zou2d39d572011-01-06 14:29:56 +00003000void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3001 struct ixgbe_ring *ring)
3002{
3003 struct ixgbe_hw *hw = &adapter->hw;
3004 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3005 u32 rxdctl;
3006 u8 reg_idx = ring->reg_idx;
3007
3008 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3009 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3010
3011 /* write value back with RXDCTL.ENABLE bit cleared */
3012 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3013
3014 if (hw->mac.type == ixgbe_mac_82598EB &&
3015 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3016 return;
3017
3018 /* the hardware may take up to 100us to really disable the rx queue */
3019 do {
3020 udelay(10);
3021 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3022 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3023
3024 if (!wait_loop) {
3025 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3026 "the polling period\n", reg_idx);
3027 }
3028}
3029
Alexander Duyck84418e32010-08-19 13:40:54 +00003030void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3031 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003032{
3033 struct ixgbe_hw *hw = &adapter->hw;
3034 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003035 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003036 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003037
Alexander Duyck9e10e042010-08-19 13:40:06 +00003038 /* disable queue to avoid issues while updating state */
3039 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003040 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003041
Alexander Duyckacd37172010-08-19 13:36:05 +00003042 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3043 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3044 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3045 ring->count * sizeof(union ixgbe_adv_rx_desc));
3046 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3047 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003048 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003049
3050 ixgbe_configure_srrctl(adapter, ring);
3051 ixgbe_configure_rscctl(adapter, ring);
3052
Greg Rosee9f98072011-01-26 01:06:07 +00003053 /* If operating in IOV mode set RLPML for X540 */
3054 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3055 hw->mac.type == ixgbe_mac_X540) {
3056 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3057 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3058 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3059 }
3060
Alexander Duyck9e10e042010-08-19 13:40:06 +00003061 if (hw->mac.type == ixgbe_mac_82598EB) {
3062 /*
3063 * enable cache line friendly hardware writes:
3064 * PTHRESH=32 descriptors (half the internal cache),
3065 * this also removes ugly rx_no_buffer_count increment
3066 * HTHRESH=4 descriptors (to minimize latency on fetch)
3067 * WTHRESH=8 burst writeback up to two cache lines
3068 */
3069 rxdctl &= ~0x3FFFFF;
3070 rxdctl |= 0x080420;
3071 }
3072
3073 /* enable receive descriptor ring */
3074 rxdctl |= IXGBE_RXDCTL_ENABLE;
3075 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3076
3077 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003078 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003079}
3080
Alexander Duyck48654522010-08-19 13:36:27 +00003081static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3082{
3083 struct ixgbe_hw *hw = &adapter->hw;
3084 int p;
3085
3086 /* PSRTYPE must be initialized in non 82598 adapters */
3087 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003088 IXGBE_PSRTYPE_UDPHDR |
3089 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003090 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003091 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003092
3093 if (hw->mac.type == ixgbe_mac_82598EB)
3094 return;
3095
3096 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3097 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3098
3099 for (p = 0; p < adapter->num_rx_pools; p++)
3100 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3101 psrtype);
3102}
3103
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003104static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3105{
3106 struct ixgbe_hw *hw = &adapter->hw;
3107 u32 gcr_ext;
3108 u32 vt_reg_bits;
3109 u32 reg_offset, vf_shift;
3110 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003111 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003112
3113 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3114 return;
3115
3116 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3117 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3118 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3119 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3120
3121 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00003122 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003123
3124 /* Enable only the PF's pool for Tx/Rx */
3125 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3126 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3127 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3128 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3129 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3130
3131 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3132 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3133
3134 /*
3135 * Set up VF register offsets for selected VT Mode,
3136 * i.e. 32 or 64 VFs for SR-IOV
3137 */
3138 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3139 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3140 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3141 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3142
3143 /* enable Tx loopback for VF/PF communication */
3144 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003145 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003146 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003147 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003148 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003149 /* For VFs that have spoof checking turned off */
3150 for (i = 0; i < adapter->num_vfs; i++) {
3151 if (!adapter->vfinfo[i].spoofchk_enabled)
3152 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3153 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003154}
3155
Alexander Duyck477de6e2010-08-19 13:38:11 +00003156static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003157{
Auke Kok9a799d72007-09-15 14:07:45 -07003158 struct ixgbe_hw *hw = &adapter->hw;
3159 struct net_device *netdev = adapter->netdev;
3160 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003161 struct ixgbe_ring *rx_ring;
3162 int i;
3163 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003164
Alexander Duyck477de6e2010-08-19 13:38:11 +00003165#ifdef IXGBE_FCOE
3166 /* adjust max frame to be able to do baby jumbo for FCoE */
3167 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3168 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3169 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3170
3171#endif /* IXGBE_FCOE */
3172 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3173 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3174 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3175 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3176
3177 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003178 }
3179
Alexander Duyck919e78a2011-08-26 09:52:38 +00003180 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3181 max_frame += VLAN_HLEN;
3182
Auke Kok9a799d72007-09-15 14:07:45 -07003183 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003184 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3185 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003186 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3187
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003188 /*
3189 * Setup the HW Rx Head and Tail Descriptor Pointers and
3190 * the Base and Length of the Rx Descriptor Ring
3191 */
Auke Kok9a799d72007-09-15 14:07:45 -07003192 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003193 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003194 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3195 set_ring_rsc_enabled(rx_ring);
3196 else
3197 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003198 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003199}
3200
Alexander Duyck73670962010-08-19 13:38:34 +00003201static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3202{
3203 struct ixgbe_hw *hw = &adapter->hw;
3204 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3205
3206 switch (hw->mac.type) {
3207 case ixgbe_mac_82598EB:
3208 /*
3209 * For VMDq support of different descriptor types or
3210 * buffer sizes through the use of multiple SRRCTL
3211 * registers, RDRXCTL.MVMEN must be set to 1
3212 *
3213 * also, the manual doesn't mention it clearly but DCA hints
3214 * will only use queue 0's tags unless this bit is set. Side
3215 * effects of setting this bit are only that SRRCTL must be
3216 * fully programmed [0..15]
3217 */
3218 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3219 break;
3220 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003221 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003222 /* Disable RSC for ACK packets */
3223 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3224 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3225 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3226 /* hardware requires some bits to be set by default */
3227 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3228 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3229 break;
3230 default:
3231 /* We should do nothing since we don't know this hardware */
3232 return;
3233 }
3234
3235 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3236}
3237
Alexander Duyck477de6e2010-08-19 13:38:11 +00003238/**
3239 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3240 * @adapter: board private structure
3241 *
3242 * Configure the Rx unit of the MAC after a reset.
3243 **/
3244static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3245{
3246 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003247 int i;
3248 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003249
3250 /* disable receives while setting up the descriptors */
3251 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3252 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3253
3254 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003255 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003256
Alexander Duyck9e10e042010-08-19 13:40:06 +00003257 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003258 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003259
Alexander Duyck477de6e2010-08-19 13:38:11 +00003260 /* set_rx_buffer_len must be called before ring initialization */
3261 ixgbe_set_rx_buffer_len(adapter);
3262
3263 /*
3264 * Setup the HW Rx Head and Tail Descriptor Pointers and
3265 * the Base and Length of the Rx Descriptor Ring
3266 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003267 for (i = 0; i < adapter->num_rx_queues; i++)
3268 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003269
Alexander Duyck9e10e042010-08-19 13:40:06 +00003270 /* disable drop enable for 82598 parts */
3271 if (hw->mac.type == ixgbe_mac_82598EB)
3272 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3273
3274 /* enable all receives */
3275 rxctrl |= IXGBE_RXCTRL_RXEN;
3276 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003277}
3278
Jiri Pirko8e586132011-12-08 19:52:37 -05003279static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003280{
3281 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003282 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003283 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003284
3285 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003286 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003287 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003288
3289 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003290}
3291
Jiri Pirko8e586132011-12-08 19:52:37 -05003292static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003293{
3294 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003295 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003296 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003297
Auke Kok9a799d72007-09-15 14:07:45 -07003298 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003299 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003300 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003301
3302 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003303}
3304
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003305/**
3306 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3307 * @adapter: driver data
3308 */
3309static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3310{
3311 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003312 u32 vlnctrl;
3313
3314 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3315 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3316 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3317}
3318
3319/**
3320 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3321 * @adapter: driver data
3322 */
3323static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3324{
3325 struct ixgbe_hw *hw = &adapter->hw;
3326 u32 vlnctrl;
3327
3328 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3329 vlnctrl |= IXGBE_VLNCTRL_VFE;
3330 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3331 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3332}
3333
3334/**
3335 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3336 * @adapter: driver data
3337 */
3338static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3339{
3340 struct ixgbe_hw *hw = &adapter->hw;
3341 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003342 int i, j;
3343
3344 switch (hw->mac.type) {
3345 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003346 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3347 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003348 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3349 break;
3350 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003351 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003352 for (i = 0; i < adapter->num_rx_queues; i++) {
3353 j = adapter->rx_ring[i]->reg_idx;
3354 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3355 vlnctrl &= ~IXGBE_RXDCTL_VME;
3356 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3357 }
3358 break;
3359 default:
3360 break;
3361 }
3362}
3363
3364/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003365 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003366 * @adapter: driver data
3367 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003368static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003369{
3370 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003371 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003372 int i, j;
3373
3374 switch (hw->mac.type) {
3375 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003376 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3377 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003378 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3379 break;
3380 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003381 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003382 for (i = 0; i < adapter->num_rx_queues; i++) {
3383 j = adapter->rx_ring[i]->reg_idx;
3384 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3385 vlnctrl |= IXGBE_RXDCTL_VME;
3386 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3387 }
3388 break;
3389 default:
3390 break;
3391 }
3392}
3393
Auke Kok9a799d72007-09-15 14:07:45 -07003394static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3395{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003396 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003397
Jesse Grossf62bbb52010-10-20 13:56:10 +00003398 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3399
3400 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3401 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003402}
3403
3404/**
Alexander Duyck28500622010-06-15 09:25:48 +00003405 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3406 * @netdev: network interface device structure
3407 *
3408 * Writes unicast address list to the RAR table.
3409 * Returns: -ENOMEM on failure/insufficient address space
3410 * 0 on no addresses written
3411 * X on writing X addresses to the RAR table
3412 **/
3413static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3414{
3415 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3416 struct ixgbe_hw *hw = &adapter->hw;
3417 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003418 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003419 int count = 0;
3420
3421 /* return ENOMEM indicating insufficient memory for addresses */
3422 if (netdev_uc_count(netdev) > rar_entries)
3423 return -ENOMEM;
3424
3425 if (!netdev_uc_empty(netdev) && rar_entries) {
3426 struct netdev_hw_addr *ha;
3427 /* return error if we do not support writing to RAR table */
3428 if (!hw->mac.ops.set_rar)
3429 return -ENOMEM;
3430
3431 netdev_for_each_uc_addr(ha, netdev) {
3432 if (!rar_entries)
3433 break;
3434 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3435 vfn, IXGBE_RAH_AV);
3436 count++;
3437 }
3438 }
3439 /* write the addresses in reverse order to avoid write combining */
3440 for (; rar_entries > 0 ; rar_entries--)
3441 hw->mac.ops.clear_rar(hw, rar_entries);
3442
3443 return count;
3444}
3445
3446/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003447 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003448 * @netdev: network interface device structure
3449 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003450 * The set_rx_method entry point is called whenever the unicast/multicast
3451 * address list or the network interface flags are updated. This routine is
3452 * responsible for configuring the hardware for proper unicast, multicast and
3453 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003454 **/
Greg Rose7f870472010-01-09 02:25:29 +00003455void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003456{
3457 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3458 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003459 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3460 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003461
3462 /* Check for Promiscuous and All Multicast modes */
3463
3464 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3465
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003466 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003467 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003468 fctrl |= IXGBE_FCTRL_BAM;
3469 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3470 fctrl |= IXGBE_FCTRL_PMCF;
3471
Alexander Duyck28500622010-06-15 09:25:48 +00003472 /* clear the bits we are changing the status of */
3473 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3474
Auke Kok9a799d72007-09-15 14:07:45 -07003475 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003476 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003477 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003478 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003479 /* don't hardware filter vlans in promisc mode */
3480 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003481 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003482 if (netdev->flags & IFF_ALLMULTI) {
3483 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003484 vmolr |= IXGBE_VMOLR_MPE;
3485 } else {
3486 /*
3487 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003488 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003489 * that we can at least receive multicast traffic
3490 */
3491 hw->mac.ops.update_mc_addr_list(hw, netdev);
3492 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003493 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003494 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003495 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003496 }
3497
3498 /*
3499 * Write addresses to available RAR registers, if there is not
3500 * sufficient space to store all the addresses then enable
3501 * unicast promiscuous mode
3502 */
3503 count = ixgbe_write_uc_addr_list(netdev);
3504 if (count < 0) {
3505 fctrl |= IXGBE_FCTRL_UPE;
3506 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003507 }
3508
3509 if (adapter->num_vfs) {
3510 ixgbe_restore_vf_multicasts(adapter);
3511 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3512 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3513 IXGBE_VMOLR_ROPE);
3514 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003515 }
3516
Ben Greear3f2d1c02012-03-08 08:28:41 +00003517 /* This is useful for sniffing bad packets. */
3518 if (adapter->netdev->features & NETIF_F_RXALL) {
3519 /* UPE and MPE will be handled by normal PROMISC logic
3520 * in e1000e_set_rx_mode */
3521 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3522 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3523 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3524
3525 fctrl &= ~(IXGBE_FCTRL_DPF);
3526 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3527 }
3528
Auke Kok9a799d72007-09-15 14:07:45 -07003529 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003530
3531 if (netdev->features & NETIF_F_HW_VLAN_RX)
3532 ixgbe_vlan_strip_enable(adapter);
3533 else
3534 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003535}
3536
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003537static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3538{
3539 int q_idx;
3540 struct ixgbe_q_vector *q_vector;
3541 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3542
3543 /* legacy and MSI only use one vector */
3544 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3545 q_vectors = 1;
3546
3547 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003548 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003549 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003550 }
3551}
3552
3553static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3554{
3555 int q_idx;
3556 struct ixgbe_q_vector *q_vector;
3557 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3558
3559 /* legacy and MSI only use one vector */
3560 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3561 q_vectors = 1;
3562
3563 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003564 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003565 napi_disable(&q_vector->napi);
3566 }
3567}
3568
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003569#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003570/*
3571 * ixgbe_configure_dcb - Configure DCB hardware
3572 * @adapter: ixgbe adapter struct
3573 *
3574 * This is called by the driver on open to configure the DCB hardware.
3575 * This is also called by the gennetlink interface when reconfiguring
3576 * the DCB state.
3577 */
3578static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3579{
3580 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003581 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003582
Alexander Duyck67ebd792010-08-19 13:34:04 +00003583 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3584 if (hw->mac.type == ixgbe_mac_82598EB)
3585 netif_set_gso_max_size(adapter->netdev, 65536);
3586 return;
3587 }
3588
3589 if (hw->mac.type == ixgbe_mac_82598EB)
3590 netif_set_gso_max_size(adapter->netdev, 32768);
3591
Alexander Duyck2f90b862008-11-20 20:52:10 -08003592
Alexander Duyck2f90b862008-11-20 20:52:10 -08003593 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003594 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003595
Alexander Duyck2f90b862008-11-20 20:52:10 -08003596 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003597
John Fastabendb1208182011-10-15 05:00:10 +00003598#ifdef IXGBE_FCOE
3599 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3600 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3601#endif
3602
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003603 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003604 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003605 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3606 DCB_TX_CONFIG);
3607 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3608 DCB_RX_CONFIG);
3609 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003610 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3611 ixgbe_dcb_hw_ets(&adapter->hw,
3612 adapter->ixgbe_ieee_ets,
3613 max_frame);
3614 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3615 adapter->ixgbe_ieee_pfc->pfc_en,
3616 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003617 }
John Fastabend8187cd42011-02-23 05:58:08 +00003618
3619 /* Enable RSS Hash per TC */
3620 if (hw->mac.type != ixgbe_mac_82598EB) {
3621 int i;
3622 u32 reg = 0;
3623
3624 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3625 u8 msb = 0;
3626 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3627
3628 while (cnt >>= 1)
3629 msb++;
3630
3631 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3632 }
3633 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3634 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003635}
John Fastabend9da712d2011-08-23 03:14:22 +00003636#endif
3637
3638/* Additional bittime to account for IXGBE framing */
3639#define IXGBE_ETH_FRAMING 20
3640
3641/*
3642 * ixgbe_hpbthresh - calculate high water mark for flow control
3643 *
3644 * @adapter: board private structure to calculate for
3645 * @pb - packet buffer to calculate
3646 */
3647static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3648{
3649 struct ixgbe_hw *hw = &adapter->hw;
3650 struct net_device *dev = adapter->netdev;
3651 int link, tc, kb, marker;
3652 u32 dv_id, rx_pba;
3653
3654 /* Calculate max LAN frame size */
3655 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3656
3657#ifdef IXGBE_FCOE
3658 /* FCoE traffic class uses FCOE jumbo frames */
3659 if (dev->features & NETIF_F_FCOE_MTU) {
3660 int fcoe_pb = 0;
3661
3662#ifdef CONFIG_IXGBE_DCB
3663 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003664
3665#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003666 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3667 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3668 }
3669#endif
3670
3671 /* Calculate delay value for device */
3672 switch (hw->mac.type) {
3673 case ixgbe_mac_X540:
3674 dv_id = IXGBE_DV_X540(link, tc);
3675 break;
3676 default:
3677 dv_id = IXGBE_DV(link, tc);
3678 break;
3679 }
3680
3681 /* Loopback switch introduces additional latency */
3682 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3683 dv_id += IXGBE_B2BT(tc);
3684
3685 /* Delay value is calculated in bit times convert to KB */
3686 kb = IXGBE_BT2KB(dv_id);
3687 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3688
3689 marker = rx_pba - kb;
3690
3691 /* It is possible that the packet buffer is not large enough
3692 * to provide required headroom. In this case throw an error
3693 * to user and a do the best we can.
3694 */
3695 if (marker < 0) {
3696 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3697 "headroom to support flow control."
3698 "Decrease MTU or number of traffic classes\n", pb);
3699 marker = tc + 1;
3700 }
3701
3702 return marker;
3703}
3704
3705/*
3706 * ixgbe_lpbthresh - calculate low water mark for for flow control
3707 *
3708 * @adapter: board private structure to calculate for
3709 * @pb - packet buffer to calculate
3710 */
3711static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3712{
3713 struct ixgbe_hw *hw = &adapter->hw;
3714 struct net_device *dev = adapter->netdev;
3715 int tc;
3716 u32 dv_id;
3717
3718 /* Calculate max LAN frame size */
3719 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3720
3721 /* Calculate delay value for device */
3722 switch (hw->mac.type) {
3723 case ixgbe_mac_X540:
3724 dv_id = IXGBE_LOW_DV_X540(tc);
3725 break;
3726 default:
3727 dv_id = IXGBE_LOW_DV(tc);
3728 break;
3729 }
3730
3731 /* Delay value is calculated in bit times convert to KB */
3732 return IXGBE_BT2KB(dv_id);
3733}
3734
3735/*
3736 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3737 */
3738static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3739{
3740 struct ixgbe_hw *hw = &adapter->hw;
3741 int num_tc = netdev_get_num_tc(adapter->netdev);
3742 int i;
3743
3744 if (!num_tc)
3745 num_tc = 1;
3746
3747 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3748
3749 for (i = 0; i < num_tc; i++) {
3750 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3751
3752 /* Low water marks must not be larger than high water marks */
3753 if (hw->fc.low_water > hw->fc.high_water[i])
3754 hw->fc.low_water = 0;
3755 }
3756}
John Fastabend80605c652011-05-02 12:34:10 +00003757
3758static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3759{
John Fastabend80605c652011-05-02 12:34:10 +00003760 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003761 int hdrm;
3762 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003763
3764 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3765 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003766 hdrm = 32 << adapter->fdir_pballoc;
3767 else
3768 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003769
Alexander Duyckf7e10272011-07-21 00:40:35 +00003770 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003771 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003772}
3773
Alexander Duycke4911d52011-05-11 07:18:52 +00003774static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3775{
3776 struct ixgbe_hw *hw = &adapter->hw;
3777 struct hlist_node *node, *node2;
3778 struct ixgbe_fdir_filter *filter;
3779
3780 spin_lock(&adapter->fdir_perfect_lock);
3781
3782 if (!hlist_empty(&adapter->fdir_filter_list))
3783 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3784
3785 hlist_for_each_entry_safe(filter, node, node2,
3786 &adapter->fdir_filter_list, fdir_node) {
3787 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003788 &filter->filter,
3789 filter->sw_idx,
3790 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3791 IXGBE_FDIR_DROP_QUEUE :
3792 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003793 }
3794
3795 spin_unlock(&adapter->fdir_perfect_lock);
3796}
3797
Auke Kok9a799d72007-09-15 14:07:45 -07003798static void ixgbe_configure(struct ixgbe_adapter *adapter)
3799{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003800 struct ixgbe_hw *hw = &adapter->hw;
3801
John Fastabend80605c652011-05-02 12:34:10 +00003802 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003803#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003804 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003805#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003806
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003807 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003808 ixgbe_restore_vlan(adapter);
3809
Yi Zoueacd73f2009-05-13 13:11:06 +00003810#ifdef IXGBE_FCOE
3811 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3812 ixgbe_configure_fcoe(adapter);
3813
3814#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003815
3816 switch (hw->mac.type) {
3817 case ixgbe_mac_82599EB:
3818 case ixgbe_mac_X540:
3819 hw->mac.ops.disable_rx_buff(hw);
3820 break;
3821 default:
3822 break;
3823 }
3824
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003825 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003826 ixgbe_init_fdir_signature_82599(&adapter->hw,
3827 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003828 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3829 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3830 adapter->fdir_pballoc);
3831 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003832 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003833
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003834 switch (hw->mac.type) {
3835 case ixgbe_mac_82599EB:
3836 case ixgbe_mac_X540:
3837 hw->mac.ops.enable_rx_buff(hw);
3838 break;
3839 default:
3840 break;
3841 }
3842
Alexander Duyck933d41f2010-09-07 21:34:29 +00003843 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003844
Auke Kok9a799d72007-09-15 14:07:45 -07003845 ixgbe_configure_tx(adapter);
3846 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003847}
3848
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003849static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3850{
3851 switch (hw->phy.type) {
3852 case ixgbe_phy_sfp_avago:
3853 case ixgbe_phy_sfp_ftl:
3854 case ixgbe_phy_sfp_intel:
3855 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003856 case ixgbe_phy_sfp_passive_tyco:
3857 case ixgbe_phy_sfp_passive_unknown:
3858 case ixgbe_phy_sfp_active_unknown:
3859 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003860 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003861 case ixgbe_phy_nl:
3862 if (hw->mac.type == ixgbe_mac_82598EB)
3863 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003864 default:
3865 return false;
3866 }
3867}
3868
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003869/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003870 * ixgbe_sfp_link_config - set up SFP+ link
3871 * @adapter: pointer to private adapter struct
3872 **/
3873static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3874{
Alexander Duyck70864002011-04-27 09:13:56 +00003875 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003876 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003877 * is that an SFP was inserted/removed after the reset
3878 * but before SFP detection was enabled. As such the best
3879 * solution is to just start searching as soon as we start
3880 */
3881 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3882 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003883
Alexander Duyck70864002011-04-27 09:13:56 +00003884 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003885}
3886
3887/**
3888 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003889 * @hw: pointer to private hardware struct
3890 *
3891 * Returns 0 on success, negative on failure
3892 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003893static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003894{
3895 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003896 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003897 u32 ret = IXGBE_ERR_LINK_SETUP;
3898
3899 if (hw->mac.ops.check_link)
3900 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3901
3902 if (ret)
3903 goto link_cfg_out;
3904
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003905 autoneg = hw->phy.autoneg_advertised;
3906 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003907 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3908 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003909 if (ret)
3910 goto link_cfg_out;
3911
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003912 if (hw->mac.ops.setup_link)
3913 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003914link_cfg_out:
3915 return ret;
3916}
3917
Alexander Duycka34bcff2010-08-19 13:39:20 +00003918static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003919{
Auke Kok9a799d72007-09-15 14:07:45 -07003920 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003921 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003922
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003923 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003924 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3925 IXGBE_GPIE_OCD;
3926 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003927 /*
3928 * use EIAM to auto-mask when MSI-X interrupt is asserted
3929 * this saves a register write for every interrupt
3930 */
3931 switch (hw->mac.type) {
3932 case ixgbe_mac_82598EB:
3933 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3934 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003935 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003936 case ixgbe_mac_X540:
3937 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003938 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3939 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3940 break;
3941 }
3942 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003943 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3944 * specifically only auto mask tx and rx interrupts */
3945 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003946 }
3947
Alexander Duycka34bcff2010-08-19 13:39:20 +00003948 /* XXX: to interrupt immediately for EICS writes, enable this */
3949 /* gpie |= IXGBE_GPIE_EIMEN; */
3950
3951 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3952 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3953 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003954 }
3955
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003956 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003957 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3958 switch (adapter->hw.mac.type) {
3959 case ixgbe_mac_82599EB:
3960 gpie |= IXGBE_SDP0_GPIEN;
3961 break;
3962 case ixgbe_mac_X540:
3963 gpie |= IXGBE_EIMS_TS;
3964 break;
3965 default:
3966 break;
3967 }
3968 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003969
Alexander Duycka34bcff2010-08-19 13:39:20 +00003970 /* Enable fan failure interrupt */
3971 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003972 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003973
Don Skidmore2698b202011-04-13 07:01:52 +00003974 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003975 gpie |= IXGBE_SDP1_GPIEN;
3976 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003977 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003978
3979 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3980}
3981
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003982static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003983{
3984 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003985 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003986 u32 ctrl_ext;
3987
3988 ixgbe_get_hw_control(adapter);
3989 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003990
Auke Kok9a799d72007-09-15 14:07:45 -07003991 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3992 ixgbe_configure_msix(adapter);
3993 else
3994 ixgbe_configure_msi_and_legacy(adapter);
3995
Don Skidmorec6ecf392010-12-03 03:31:51 +00003996 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3997 if (hw->mac.ops.enable_tx_laser &&
3998 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003999 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004000 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004001 hw->mac.ops.enable_tx_laser(hw);
4002
Auke Kok9a799d72007-09-15 14:07:45 -07004003 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004004 ixgbe_napi_enable_all(adapter);
4005
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004006 if (ixgbe_is_sfp(hw)) {
4007 ixgbe_sfp_link_config(adapter);
4008 } else {
4009 err = ixgbe_non_sfp_link_config(hw);
4010 if (err)
4011 e_err(probe, "link_config FAILED %d\n", err);
4012 }
4013
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004014 /* clear any pending interrupts, may auto mask */
4015 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004016 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004017
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004018 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004019 * If this adapter has a fan, check to see if we had a failure
4020 * before we enabled the interrupt.
4021 */
4022 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4023 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4024 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004025 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004026 }
4027
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004028 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004029 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004030
Auke Kok9a799d72007-09-15 14:07:45 -07004031 /* bring the link up in the watchdog, this could race with our first
4032 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004033 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4034 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004035 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004036
4037 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4038 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4039 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4040 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004041}
4042
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004043void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4044{
4045 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004046 /* put off any impending NetWatchDogTimeout */
4047 adapter->netdev->trans_start = jiffies;
4048
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004049 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004050 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004051 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004052 /*
4053 * If SR-IOV enabled then wait a bit before bringing the adapter
4054 * back up to give the VFs time to respond to the reset. The
4055 * two second wait is based upon the watchdog timer cycle in
4056 * the VF driver.
4057 */
4058 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4059 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004060 ixgbe_up(adapter);
4061 clear_bit(__IXGBE_RESETTING, &adapter->state);
4062}
4063
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004064void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004065{
4066 /* hardware has been reset, we need to reload some things */
4067 ixgbe_configure(adapter);
4068
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004069 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004070}
4071
4072void ixgbe_reset(struct ixgbe_adapter *adapter)
4073{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004074 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004075 int err;
4076
Alexander Duyck70864002011-04-27 09:13:56 +00004077 /* lock SFP init bit to prevent race conditions with the watchdog */
4078 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4079 usleep_range(1000, 2000);
4080
4081 /* clear all SFP and link config related flags while holding SFP_INIT */
4082 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4083 IXGBE_FLAG2_SFP_NEEDS_RESET);
4084 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4085
Don Skidmore8ca783a2009-05-26 20:40:47 -07004086 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004087 switch (err) {
4088 case 0:
4089 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004090 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004091 break;
4092 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004093 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004094 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004095 case IXGBE_ERR_EEPROM_VERSION:
4096 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004097 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004098 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004099 "your hardware. If you are experiencing problems "
4100 "please contact your Intel or hardware "
4101 "representative who provided you with this "
4102 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004103 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004104 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004105 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004106 }
Auke Kok9a799d72007-09-15 14:07:45 -07004107
Alexander Duyck70864002011-04-27 09:13:56 +00004108 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4109
Auke Kok9a799d72007-09-15 14:07:45 -07004110 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004111 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4112 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004113}
4114
Auke Kok9a799d72007-09-15 14:07:45 -07004115/**
Alexander Duyckf8003262012-03-03 02:35:52 +00004116 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
4117 * @rx_ring: ring to setup
4118 *
4119 * On many IA platforms the L1 cache has a critical stride of 4K, this
4120 * results in each receive buffer starting in the same cache set. To help
4121 * reduce the pressure on this cache set we can interleave the offsets so
4122 * that only every other buffer will be in the same cache set.
4123 **/
4124static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4125{
4126 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4127 u16 i;
4128
4129 for (i = 0; i < rx_ring->count; i += 2) {
4130 rx_buffer[0].page_offset = 0;
4131 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4132 rx_buffer = &rx_buffer[2];
4133 }
4134}
4135
4136/**
Auke Kok9a799d72007-09-15 14:07:45 -07004137 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004138 * @rx_ring: ring to free buffers from
4139 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004140static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004141{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004142 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004143 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004144 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004145
Alexander Duyck84418e32010-08-19 13:40:54 +00004146 /* ring already cleared, nothing to do */
4147 if (!rx_ring->rx_buffer_info)
4148 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004149
Alexander Duyck84418e32010-08-19 13:40:54 +00004150 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004151 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004152 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004153
Alexander Duyckf8003262012-03-03 02:35:52 +00004154 rx_buffer = &rx_ring->rx_buffer_info[i];
4155 if (rx_buffer->skb) {
4156 struct sk_buff *skb = rx_buffer->skb;
4157 if (IXGBE_CB(skb)->page_released) {
4158 dma_unmap_page(dev,
4159 IXGBE_CB(skb)->dma,
4160 ixgbe_rx_bufsz(rx_ring),
4161 DMA_FROM_DEVICE);
4162 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004163 }
4164 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004165 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004166 rx_buffer->skb = NULL;
4167 if (rx_buffer->dma)
4168 dma_unmap_page(dev, rx_buffer->dma,
4169 ixgbe_rx_pg_size(rx_ring),
4170 DMA_FROM_DEVICE);
4171 rx_buffer->dma = 0;
4172 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004173 __free_pages(rx_buffer->page,
4174 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004175 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004176 }
4177
4178 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4179 memset(rx_ring->rx_buffer_info, 0, size);
4180
Alexander Duyckf8003262012-03-03 02:35:52 +00004181 ixgbe_init_rx_page_offset(rx_ring);
4182
Auke Kok9a799d72007-09-15 14:07:45 -07004183 /* Zero out the descriptor ring */
4184 memset(rx_ring->desc, 0, rx_ring->size);
4185
Alexander Duyckf8003262012-03-03 02:35:52 +00004186 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004187 rx_ring->next_to_clean = 0;
4188 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004189}
4190
4191/**
4192 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004193 * @tx_ring: ring to be cleaned
4194 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004195static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004196{
4197 struct ixgbe_tx_buffer *tx_buffer_info;
4198 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004199 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004200
Alexander Duyck84418e32010-08-19 13:40:54 +00004201 /* ring already cleared, nothing to do */
4202 if (!tx_ring->tx_buffer_info)
4203 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004204
Alexander Duyck84418e32010-08-19 13:40:54 +00004205 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004206 for (i = 0; i < tx_ring->count; i++) {
4207 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004208 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004209 }
4210
John Fastabenddad8a3b2012-04-23 12:22:39 +00004211 netdev_tx_reset_queue(txring_txq(tx_ring));
4212
Auke Kok9a799d72007-09-15 14:07:45 -07004213 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4214 memset(tx_ring->tx_buffer_info, 0, size);
4215
4216 /* Zero out the descriptor ring */
4217 memset(tx_ring->desc, 0, tx_ring->size);
4218
4219 tx_ring->next_to_use = 0;
4220 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004221}
4222
4223/**
Auke Kok9a799d72007-09-15 14:07:45 -07004224 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4225 * @adapter: board private structure
4226 **/
4227static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4228{
4229 int i;
4230
4231 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004232 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004233}
4234
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004235/**
4236 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4237 * @adapter: board private structure
4238 **/
4239static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4240{
4241 int i;
4242
4243 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004244 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004245}
4246
Alexander Duycke4911d52011-05-11 07:18:52 +00004247static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4248{
4249 struct hlist_node *node, *node2;
4250 struct ixgbe_fdir_filter *filter;
4251
4252 spin_lock(&adapter->fdir_perfect_lock);
4253
4254 hlist_for_each_entry_safe(filter, node, node2,
4255 &adapter->fdir_filter_list, fdir_node) {
4256 hlist_del(&filter->fdir_node);
4257 kfree(filter);
4258 }
4259 adapter->fdir_filter_count = 0;
4260
4261 spin_unlock(&adapter->fdir_perfect_lock);
4262}
4263
Auke Kok9a799d72007-09-15 14:07:45 -07004264void ixgbe_down(struct ixgbe_adapter *adapter)
4265{
4266 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004267 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004268 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004269 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004270
4271 /* signal that we are down to the interrupt handler */
4272 set_bit(__IXGBE_DOWN, &adapter->state);
4273
4274 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004275 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4276 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004277
Yi Zou2d39d572011-01-06 14:29:56 +00004278 /* disable all enabled rx queues */
4279 for (i = 0; i < adapter->num_rx_queues; i++)
4280 /* this call also flushes the previous write */
4281 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4282
Don Skidmore032b4322011-03-18 09:32:53 +00004283 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004284
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004285 netif_tx_stop_all_queues(netdev);
4286
Alexander Duyck70864002011-04-27 09:13:56 +00004287 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004288 netif_carrier_off(netdev);
4289 netif_tx_disable(netdev);
4290
4291 ixgbe_irq_disable(adapter);
4292
4293 ixgbe_napi_disable_all(adapter);
4294
Alexander Duyckd034acf2011-04-27 09:25:34 +00004295 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4296 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004297 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4298
4299 del_timer_sync(&adapter->service_timer);
4300
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004301 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004302 /* Clear EITR Select mapping */
4303 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4304
4305 /* Mark all the VFs as inactive */
4306 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004307 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004308
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004309 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004310 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004311
Auke Kok9a799d72007-09-15 14:07:45 -07004312 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004313 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004314 }
4315
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004316 /* disable transmits in the hardware now that interrupts are off */
4317 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004318 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004319 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004320 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004321
4322 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004323 switch (hw->mac.type) {
4324 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004325 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004326 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004327 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4328 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004329 break;
4330 default:
4331 break;
4332 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004333
Paul Larson6f4a0e42008-06-24 17:00:56 -07004334 if (!pci_channel_offline(adapter->pdev))
4335 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004336
4337 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4338 if (hw->mac.ops.disable_tx_laser &&
4339 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004340 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004341 (hw->mac.type == ixgbe_mac_82599EB))))
4342 hw->mac.ops.disable_tx_laser(hw);
4343
Auke Kok9a799d72007-09-15 14:07:45 -07004344 ixgbe_clean_all_tx_rings(adapter);
4345 ixgbe_clean_all_rx_rings(adapter);
4346
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004347#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004348 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004349 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004350#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004351}
4352
Auke Kok9a799d72007-09-15 14:07:45 -07004353/**
Auke Kok9a799d72007-09-15 14:07:45 -07004354 * ixgbe_tx_timeout - Respond to a Tx Hang
4355 * @netdev: network interface device structure
4356 **/
4357static void ixgbe_tx_timeout(struct net_device *netdev)
4358{
4359 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4360
4361 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004362 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004363}
4364
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004365/**
Auke Kok9a799d72007-09-15 14:07:45 -07004366 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4367 * @adapter: board private structure to initialize
4368 *
4369 * ixgbe_sw_init initializes the Adapter private data structure.
4370 * Fields are initialized based on PCI device information and
4371 * OS network device settings (MTU size).
4372 **/
4373static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4374{
4375 struct ixgbe_hw *hw = &adapter->hw;
4376 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004377 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004378#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004379 int j;
4380 struct tc_configuration *tc;
4381#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004382
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004383 /* PCI config space info */
4384
4385 hw->vendor_id = pdev->vendor;
4386 hw->device_id = pdev->device;
4387 hw->revision_id = pdev->revision;
4388 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4389 hw->subsystem_device_id = pdev->subsystem_device;
4390
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004391 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004392 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004393 adapter->ring_feature[RING_F_RSS].indices = rss;
4394 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08004395 switch (hw->mac.type) {
4396 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004397 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4398 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004399 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004400 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004401 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004402 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4403 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004404 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004405 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4406 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004407 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4408 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004409 /* Flow Director hash filters enabled */
4410 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4411 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004412 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00004413 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004414 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004415#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004416 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4417 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4418 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00004419#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004420 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004421 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004422#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004423#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004424 break;
4425 default:
4426 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004427 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004428
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004429 /* n-tuple support exists, always init our spinlock */
4430 spin_lock_init(&adapter->fdir_perfect_lock);
4431
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004432#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004433 switch (hw->mac.type) {
4434 case ixgbe_mac_X540:
4435 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4436 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4437 break;
4438 default:
4439 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4440 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4441 break;
4442 }
4443
Alexander Duyck2f90b862008-11-20 20:52:10 -08004444 /* Configure DCB traffic classes */
4445 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4446 tc = &adapter->dcb_cfg.tc_config[j];
4447 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4448 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4449 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4450 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4451 tc->dcb_pfc = pfc_disabled;
4452 }
John Fastabend4de2a022011-09-27 03:52:01 +00004453
4454 /* Initialize default user to priority mapping, UPx->TC0 */
4455 tc = &adapter->dcb_cfg.tc_config[0];
4456 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4457 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4458
Alexander Duyck2f90b862008-11-20 20:52:10 -08004459 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4460 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004461 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004462 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004463 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004464 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4465 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004466
4467#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004468
4469 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004470 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004471 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004472 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004473 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4474 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004475 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004476
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004477 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004478 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004479 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004480
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004481 /* set default ring sizes */
4482 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4483 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4484
Alexander Duyckbd198052011-06-11 01:45:08 +00004485 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004486 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004487
Auke Kok9a799d72007-09-15 14:07:45 -07004488 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004489 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004490 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004491 return -EIO;
4492 }
4493
Auke Kok9a799d72007-09-15 14:07:45 -07004494 set_bit(__IXGBE_DOWN, &adapter->state);
4495
4496 return 0;
4497}
4498
4499/**
4500 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004501 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004502 *
4503 * Return 0 on success, negative on failure
4504 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004505int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004506{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004507 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004508 int orig_node = dev_to_node(dev);
4509 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004510 int size;
4511
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004512 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004513
4514 if (tx_ring->q_vector)
4515 numa_node = tx_ring->q_vector->numa_node;
4516
4517 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004518 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004519 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004520 if (!tx_ring->tx_buffer_info)
4521 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004522
4523 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004524 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004525 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004526
Alexander Duyckde88eee2012-02-08 07:49:59 +00004527 set_dev_node(dev, numa_node);
4528 tx_ring->desc = dma_alloc_coherent(dev,
4529 tx_ring->size,
4530 &tx_ring->dma,
4531 GFP_KERNEL);
4532 set_dev_node(dev, orig_node);
4533 if (!tx_ring->desc)
4534 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4535 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004536 if (!tx_ring->desc)
4537 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004538
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004539 tx_ring->next_to_use = 0;
4540 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004541 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004542
4543err:
4544 vfree(tx_ring->tx_buffer_info);
4545 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004546 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004547 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004548}
4549
4550/**
Alexander Duyck69888672008-09-11 20:05:39 -07004551 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4552 * @adapter: board private structure
4553 *
4554 * If this function returns with an error, then it's possible one or
4555 * more of the rings is populated (while the rest are not). It is the
4556 * callers duty to clean those orphaned rings.
4557 *
4558 * Return 0 on success, negative on failure
4559 **/
4560static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4561{
4562 int i, err = 0;
4563
4564 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004565 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004566 if (!err)
4567 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00004568 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07004569 break;
4570 }
4571
4572 return err;
4573}
4574
4575/**
Auke Kok9a799d72007-09-15 14:07:45 -07004576 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004577 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004578 *
4579 * Returns 0 on success, negative on failure
4580 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004581int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004582{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004583 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004584 int orig_node = dev_to_node(dev);
4585 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004586 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004587
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004588 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004589
4590 if (rx_ring->q_vector)
4591 numa_node = rx_ring->q_vector->numa_node;
4592
4593 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004594 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004595 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004596 if (!rx_ring->rx_buffer_info)
4597 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004598
Auke Kok9a799d72007-09-15 14:07:45 -07004599 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004600 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4601 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004602
Alexander Duyckde88eee2012-02-08 07:49:59 +00004603 set_dev_node(dev, numa_node);
4604 rx_ring->desc = dma_alloc_coherent(dev,
4605 rx_ring->size,
4606 &rx_ring->dma,
4607 GFP_KERNEL);
4608 set_dev_node(dev, orig_node);
4609 if (!rx_ring->desc)
4610 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4611 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004612 if (!rx_ring->desc)
4613 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004614
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004615 rx_ring->next_to_clean = 0;
4616 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004617
Alexander Duyckf8003262012-03-03 02:35:52 +00004618 ixgbe_init_rx_page_offset(rx_ring);
4619
Auke Kok9a799d72007-09-15 14:07:45 -07004620 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004621err:
4622 vfree(rx_ring->rx_buffer_info);
4623 rx_ring->rx_buffer_info = NULL;
4624 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004625 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004626}
4627
4628/**
Alexander Duyck69888672008-09-11 20:05:39 -07004629 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4630 * @adapter: board private structure
4631 *
4632 * If this function returns with an error, then it's possible one or
4633 * more of the rings is populated (while the rest are not). It is the
4634 * callers duty to clean those orphaned rings.
4635 *
4636 * Return 0 on success, negative on failure
4637 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004638static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4639{
4640 int i, err = 0;
4641
4642 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004643 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004644 if (!err)
4645 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00004646 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07004647 break;
4648 }
4649
4650 return err;
4651}
4652
4653/**
Auke Kok9a799d72007-09-15 14:07:45 -07004654 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004655 * @tx_ring: Tx descriptor ring for a specific queue
4656 *
4657 * Free all transmit software resources
4658 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004659void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004660{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004661 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004662
4663 vfree(tx_ring->tx_buffer_info);
4664 tx_ring->tx_buffer_info = NULL;
4665
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004666 /* if not set, then don't free */
4667 if (!tx_ring->desc)
4668 return;
4669
4670 dma_free_coherent(tx_ring->dev, tx_ring->size,
4671 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004672
4673 tx_ring->desc = NULL;
4674}
4675
4676/**
4677 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4678 * @adapter: board private structure
4679 *
4680 * Free all transmit software resources
4681 **/
4682static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4683{
4684 int i;
4685
4686 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004687 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004688 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004689}
4690
4691/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004692 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004693 * @rx_ring: ring to clean the resources from
4694 *
4695 * Free all receive software resources
4696 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004697void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004698{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004699 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004700
4701 vfree(rx_ring->rx_buffer_info);
4702 rx_ring->rx_buffer_info = NULL;
4703
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004704 /* if not set, then don't free */
4705 if (!rx_ring->desc)
4706 return;
4707
4708 dma_free_coherent(rx_ring->dev, rx_ring->size,
4709 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004710
4711 rx_ring->desc = NULL;
4712}
4713
4714/**
4715 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4716 * @adapter: board private structure
4717 *
4718 * Free all receive software resources
4719 **/
4720static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4721{
4722 int i;
4723
4724 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004725 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004726 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004727}
4728
4729/**
Auke Kok9a799d72007-09-15 14:07:45 -07004730 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4731 * @netdev: network interface device structure
4732 * @new_mtu: new value for maximum frame size
4733 *
4734 * Returns 0 on success, negative on failure
4735 **/
4736static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4737{
4738 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4739 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4740
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004741 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004742 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4743 return -EINVAL;
4744
4745 /*
4746 * For 82599EB we cannot allow PF to change MTU greater than 1500
4747 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
4748 * don't allocate and chain buffers correctly.
4749 */
4750 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4751 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4752 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00004753 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07004754
Emil Tantilov396e7992010-07-01 20:05:12 +00004755 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004756
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004757 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004758 netdev->mtu = new_mtu;
4759
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004760 if (netif_running(netdev))
4761 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004762
4763 return 0;
4764}
4765
4766/**
4767 * ixgbe_open - Called when a network interface is made active
4768 * @netdev: network interface device structure
4769 *
4770 * Returns 0 on success, negative value on failure
4771 *
4772 * The open entry point is called when a network interface is made
4773 * active by the system (IFF_UP). At this point all resources needed
4774 * for transmit and receive operations are allocated, the interrupt
4775 * handler is registered with the OS, the watchdog timer is started,
4776 * and the stack is notified that the interface is ready.
4777 **/
4778static int ixgbe_open(struct net_device *netdev)
4779{
4780 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4781 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004782
Auke Kok4bebfaa2008-02-11 09:26:01 -08004783 /* disallow open during test */
4784 if (test_bit(__IXGBE_TESTING, &adapter->state))
4785 return -EBUSY;
4786
Jesse Brandeburg54386462009-04-17 20:44:27 +00004787 netif_carrier_off(netdev);
4788
Auke Kok9a799d72007-09-15 14:07:45 -07004789 /* allocate transmit descriptors */
4790 err = ixgbe_setup_all_tx_resources(adapter);
4791 if (err)
4792 goto err_setup_tx;
4793
Auke Kok9a799d72007-09-15 14:07:45 -07004794 /* allocate receive descriptors */
4795 err = ixgbe_setup_all_rx_resources(adapter);
4796 if (err)
4797 goto err_setup_rx;
4798
4799 ixgbe_configure(adapter);
4800
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004801 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004802 if (err)
4803 goto err_req_irq;
4804
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004805 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004806
4807 return 0;
4808
Auke Kok9a799d72007-09-15 14:07:45 -07004809err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004810err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004811 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004812err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004813 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004814 ixgbe_reset(adapter);
4815
4816 return err;
4817}
4818
4819/**
4820 * ixgbe_close - Disables a network interface
4821 * @netdev: network interface device structure
4822 *
4823 * Returns 0, this is not allowed to fail
4824 *
4825 * The close entry point is called when an interface is de-activated
4826 * by the OS. The hardware is still under the drivers control, but
4827 * needs to be disabled. A global MAC reset is issued to stop the
4828 * hardware, and all transmit and receive resources are freed.
4829 **/
4830static int ixgbe_close(struct net_device *netdev)
4831{
4832 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004833
4834 ixgbe_down(adapter);
4835 ixgbe_free_irq(adapter);
4836
Alexander Duycke4911d52011-05-11 07:18:52 +00004837 ixgbe_fdir_filter_exit(adapter);
4838
Auke Kok9a799d72007-09-15 14:07:45 -07004839 ixgbe_free_all_tx_resources(adapter);
4840 ixgbe_free_all_rx_resources(adapter);
4841
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004842 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004843
4844 return 0;
4845}
4846
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004847#ifdef CONFIG_PM
4848static int ixgbe_resume(struct pci_dev *pdev)
4849{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004850 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4851 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004852 u32 err;
4853
4854 pci_set_power_state(pdev, PCI_D0);
4855 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004856 /*
4857 * pci_restore_state clears dev->state_saved so call
4858 * pci_save_state to restore it.
4859 */
4860 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004861
4862 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004863 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004864 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004865 return err;
4866 }
4867 pci_set_master(pdev);
4868
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004869 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004870
Benjamin Poirier34948a92012-04-06 07:20:21 +00004871 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004872 err = ixgbe_init_interrupt_scheme(adapter);
Benjamin Poirier34948a92012-04-06 07:20:21 +00004873 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004874 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004875 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004876 return err;
4877 }
4878
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004879 ixgbe_reset(adapter);
4880
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004881 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4882
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004883 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004884 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004885 if (err)
4886 return err;
4887 }
4888
4889 netif_device_attach(netdev);
4890
4891 return 0;
4892}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004893#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004894
4895static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004896{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004897 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4898 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004899 struct ixgbe_hw *hw = &adapter->hw;
4900 u32 ctrl, fctrl;
4901 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004902#ifdef CONFIG_PM
4903 int retval = 0;
4904#endif
4905
4906 netif_device_detach(netdev);
4907
4908 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00004909 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004910 ixgbe_down(adapter);
4911 ixgbe_free_irq(adapter);
4912 ixgbe_free_all_tx_resources(adapter);
4913 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00004914 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004915 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004916
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08004917 ixgbe_clear_interrupt_scheme(adapter);
4918
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004919#ifdef CONFIG_PM
4920 retval = pci_save_state(pdev);
4921 if (retval)
4922 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004923
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004924#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004925 if (wufc) {
4926 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004927
Don Skidmorec509e752012-04-05 08:12:05 +00004928 /*
4929 * enable the optics for both mult-speed fiber and
4930 * 82599 SFP+ fiber as we can WoL.
4931 */
4932 if (hw->mac.ops.enable_tx_laser &&
4933 (hw->phy.multispeed_fiber ||
4934 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
4935 hw->mac.type == ixgbe_mac_82599EB)))
4936 hw->mac.ops.enable_tx_laser(hw);
4937
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004938 /* turn on all-multi mode if wake on multicast is enabled */
4939 if (wufc & IXGBE_WUFC_MC) {
4940 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4941 fctrl |= IXGBE_FCTRL_MPE;
4942 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4943 }
4944
4945 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4946 ctrl |= IXGBE_CTRL_GIO_DIS;
4947 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4948
4949 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4950 } else {
4951 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4952 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4953 }
4954
Alexander Duyckbd508172010-11-16 19:27:03 -08004955 switch (hw->mac.type) {
4956 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004957 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08004958 break;
4959 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004960 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08004961 pci_wake_from_d3(pdev, !!wufc);
4962 break;
4963 default:
4964 break;
4965 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004966
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004967 *enable_wake = !!wufc;
4968
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004969 ixgbe_release_hw_control(adapter);
4970
4971 pci_disable_device(pdev);
4972
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004973 return 0;
4974}
4975
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004976#ifdef CONFIG_PM
4977static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4978{
4979 int retval;
4980 bool wake;
4981
4982 retval = __ixgbe_shutdown(pdev, &wake);
4983 if (retval)
4984 return retval;
4985
4986 if (wake) {
4987 pci_prepare_to_sleep(pdev);
4988 } else {
4989 pci_wake_from_d3(pdev, false);
4990 pci_set_power_state(pdev, PCI_D3hot);
4991 }
4992
4993 return 0;
4994}
4995#endif /* CONFIG_PM */
4996
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004997static void ixgbe_shutdown(struct pci_dev *pdev)
4998{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004999 bool wake;
5000
5001 __ixgbe_shutdown(pdev, &wake);
5002
5003 if (system_state == SYSTEM_POWER_OFF) {
5004 pci_wake_from_d3(pdev, wake);
5005 pci_set_power_state(pdev, PCI_D3hot);
5006 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005007}
5008
5009/**
Auke Kok9a799d72007-09-15 14:07:45 -07005010 * ixgbe_update_stats - Update the board statistics counters.
5011 * @adapter: board private structure
5012 **/
5013void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5014{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005015 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005016 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005017 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005018 u64 total_mpc = 0;
5019 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005020 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5021 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005022 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005023#ifdef IXGBE_FCOE
5024 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5025 unsigned int cpu;
5026 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5027#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005028
Don Skidmored08935c2010-06-11 13:20:29 +00005029 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5030 test_bit(__IXGBE_RESETTING, &adapter->state))
5031 return;
5032
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005033 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005034 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005035 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005036 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005037 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5038 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005039 }
5040 adapter->rsc_total_count = rsc_count;
5041 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005042 }
5043
Alexander Duyck5b7da512010-11-16 19:26:50 -08005044 for (i = 0; i < adapter->num_rx_queues; i++) {
5045 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5046 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5047 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5048 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005049 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005050 bytes += rx_ring->stats.bytes;
5051 packets += rx_ring->stats.packets;
5052 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005053 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005054 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5055 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005056 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005057 netdev->stats.rx_bytes = bytes;
5058 netdev->stats.rx_packets = packets;
5059
5060 bytes = 0;
5061 packets = 0;
5062 /* gather some stats to the adapter struct that are per queue */
5063 for (i = 0; i < adapter->num_tx_queues; i++) {
5064 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5065 restart_queue += tx_ring->tx_stats.restart_queue;
5066 tx_busy += tx_ring->tx_stats.tx_busy;
5067 bytes += tx_ring->stats.bytes;
5068 packets += tx_ring->stats.packets;
5069 }
5070 adapter->restart_queue = restart_queue;
5071 adapter->tx_busy = tx_busy;
5072 netdev->stats.tx_bytes = bytes;
5073 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005074
Joe Perches7ca647b2010-09-07 21:35:40 +00005075 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005076
5077 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005078 for (i = 0; i < 8; i++) {
5079 /* for packet buffers not used, the register should read 0 */
5080 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5081 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005082 hwstats->mpc[i] += mpc;
5083 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005084 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5085 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005086 switch (hw->mac.type) {
5087 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005088 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5089 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5090 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005091 hwstats->pxonrxc[i] +=
5092 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005093 break;
5094 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005095 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005096 hwstats->pxonrxc[i] +=
5097 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005098 break;
5099 default:
5100 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005101 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005102 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005103
5104 /*16 register reads */
5105 for (i = 0; i < 16; i++) {
5106 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5107 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5108 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5109 (hw->mac.type == ixgbe_mac_X540)) {
5110 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5111 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5112 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5113 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5114 }
5115 }
5116
Joe Perches7ca647b2010-09-07 21:35:40 +00005117 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005118 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005119 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005120
John Fastabendc84d3242010-11-16 19:27:12 -08005121 ixgbe_update_xoff_received(adapter);
5122
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005123 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005124 switch (hw->mac.type) {
5125 case ixgbe_mac_82598EB:
5126 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005127 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5128 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5129 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5130 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005131 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005132 /* OS2BMC stats are X540 only*/
5133 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5134 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5135 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5136 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5137 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005138 for (i = 0; i < 16; i++)
5139 adapter->hw_rx_no_dma_resources +=
5140 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005141 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005142 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005143 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005144 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005145 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005146 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005147 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005148 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5149 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005150#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005151 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5152 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5153 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5154 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5155 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5156 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005157 /* Add up per cpu counters for total ddp aloc fail */
5158 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5159 for_each_possible_cpu(cpu) {
5160 fcoe_noddp_counts_sum +=
5161 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5162 fcoe_noddp_ext_buff_counts_sum +=
5163 *per_cpu_ptr(fcoe->
5164 pcpu_noddp_ext_buff, cpu);
5165 }
5166 }
5167 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5168 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005169#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005170 break;
5171 default:
5172 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005173 }
Auke Kok9a799d72007-09-15 14:07:45 -07005174 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005175 hwstats->bprc += bprc;
5176 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005177 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005178 hwstats->mprc -= bprc;
5179 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5180 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5181 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5182 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5183 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5184 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5185 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5186 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005187 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005188 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005189 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005190 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005191 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5192 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005193 /*
5194 * 82598 errata - tx of flow control packets is included in tx counters
5195 */
5196 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005197 hwstats->gptc -= xon_off_tot;
5198 hwstats->mptc -= xon_off_tot;
5199 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5200 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5201 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5202 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5203 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5204 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5205 hwstats->ptc64 -= xon_off_tot;
5206 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5207 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5208 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5209 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5210 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5211 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005212
5213 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005214 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005215
5216 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005217 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005218 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005219 netdev->stats.rx_length_errors = hwstats->rlec;
5220 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005221 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005222}
5223
5224/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005225 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5226 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005227 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005228static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005229{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005230 struct ixgbe_hw *hw = &adapter->hw;
5231 int i;
5232
Alexander Duyckd034acf2011-04-27 09:25:34 +00005233 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5234 return;
5235
5236 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5237
5238 /* if interface is down do nothing */
5239 if (test_bit(__IXGBE_DOWN, &adapter->state))
5240 return;
5241
5242 /* do nothing if we are not using signature filters */
5243 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5244 return;
5245
5246 adapter->fdir_overflow++;
5247
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005248 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5249 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005250 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005251 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005252 /* re-enable flow director interrupts */
5253 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005254 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005255 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005256 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005257 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005258}
5259
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005260/**
5261 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5262 * @adapter - pointer to the device adapter structure
5263 *
5264 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005265 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005266 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005267 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005268 */
5269static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5270{
Auke Kok9a799d72007-09-15 14:07:45 -07005271 struct ixgbe_hw *hw = &adapter->hw;
5272 u64 eics = 0;
5273 int i;
5274
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005275 /* If we're down or resetting, just bail */
5276 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5277 test_bit(__IXGBE_RESETTING, &adapter->state))
5278 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005279
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005280 /* Force detection of hung controller */
5281 if (netif_carrier_ok(adapter->netdev)) {
5282 for (i = 0; i < adapter->num_tx_queues; i++)
5283 set_check_for_tx_hang(adapter->tx_ring[i]);
5284 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005285
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005286 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005287 /*
5288 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005289 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005290 * would set *both* EIMS and EICS for any bit in EIAM
5291 */
5292 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5293 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005294 } else {
5295 /* get one bit for every active tx/rx interrupt vector */
5296 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5297 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005298 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005299 eics |= ((u64)1 << i);
5300 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005301 }
5302
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005303 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005304 ixgbe_irq_rearm_queues(adapter, eics);
5305
Alexander Duyckfe49f042009-06-04 16:00:09 +00005306}
5307
5308/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005309 * ixgbe_watchdog_update_link - update the link status
5310 * @adapter - pointer to the device adapter structure
5311 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005312 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005313static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005314{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005315 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005316 u32 link_speed = adapter->link_speed;
5317 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005318 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005319
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005320 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5321 return;
5322
5323 if (hw->mac.ops.check_link) {
5324 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005325 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005326 /* always assume link is up, if no check link function */
5327 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5328 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005329 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005330
5331 if (adapter->ixgbe_ieee_pfc)
5332 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5333
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005334 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005335 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005336 ixgbe_set_rx_drop_en(adapter);
5337 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005338
5339 if (link_up ||
5340 time_after(jiffies, (adapter->link_check_timeout +
5341 IXGBE_TRY_LINK_TIMEOUT))) {
5342 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5343 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5344 IXGBE_WRITE_FLUSH(hw);
5345 }
5346
5347 adapter->link_up = link_up;
5348 adapter->link_speed = link_speed;
5349}
5350
5351/**
5352 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5353 * print link up message
5354 * @adapter - pointer to the device adapter structure
5355 **/
5356static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5357{
5358 struct net_device *netdev = adapter->netdev;
5359 struct ixgbe_hw *hw = &adapter->hw;
5360 u32 link_speed = adapter->link_speed;
5361 bool flow_rx, flow_tx;
5362
5363 /* only continue if link was previously down */
5364 if (netif_carrier_ok(netdev))
5365 return;
5366
5367 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5368
5369 switch (hw->mac.type) {
5370 case ixgbe_mac_82598EB: {
5371 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5372 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5373 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5374 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5375 }
5376 break;
5377 case ixgbe_mac_X540:
5378 case ixgbe_mac_82599EB: {
5379 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5380 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5381 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5382 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5383 }
5384 break;
5385 default:
5386 flow_tx = false;
5387 flow_rx = false;
5388 break;
5389 }
5390 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5391 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5392 "10 Gbps" :
5393 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5394 "1 Gbps" :
5395 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5396 "100 Mbps" :
5397 "unknown speed"))),
5398 ((flow_rx && flow_tx) ? "RX/TX" :
5399 (flow_rx ? "RX" :
5400 (flow_tx ? "TX" : "None"))));
5401
5402 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005403 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005404}
5405
5406/**
5407 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5408 * print link down message
5409 * @adapter - pointer to the adapter structure
5410 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005411static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005412{
5413 struct net_device *netdev = adapter->netdev;
5414 struct ixgbe_hw *hw = &adapter->hw;
5415
5416 adapter->link_up = false;
5417 adapter->link_speed = 0;
5418
5419 /* only continue if link was up previously */
5420 if (!netif_carrier_ok(netdev))
5421 return;
5422
5423 /* poll for SFP+ cable when link is down */
5424 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5425 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5426
5427 e_info(drv, "NIC Link is Down\n");
5428 netif_carrier_off(netdev);
5429}
5430
5431/**
5432 * ixgbe_watchdog_flush_tx - flush queues on link down
5433 * @adapter - pointer to the device adapter structure
5434 **/
5435static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5436{
5437 int i;
5438 int some_tx_pending = 0;
5439
5440 if (!netif_carrier_ok(adapter->netdev)) {
5441 for (i = 0; i < adapter->num_tx_queues; i++) {
5442 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5443 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5444 some_tx_pending = 1;
5445 break;
5446 }
5447 }
5448
5449 if (some_tx_pending) {
5450 /* We've lost link, so the controller stops DMA,
5451 * but we've got queued Tx work that's never going
5452 * to get done, so reset controller to flush Tx.
5453 * (Do the reset outside of interrupt context).
5454 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005455 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005456 }
5457 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005458}
5459
Greg Rosea985b6c32010-11-18 03:02:52 +00005460static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5461{
5462 u32 ssvpc;
5463
5464 /* Do not perform spoof check for 82598 */
5465 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5466 return;
5467
5468 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5469
5470 /*
5471 * ssvpc register is cleared on read, if zero then no
5472 * spoofed packets in the last interval.
5473 */
5474 if (!ssvpc)
5475 return;
5476
5477 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
5478}
5479
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005480/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005481 * ixgbe_watchdog_subtask - check and bring link up
5482 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005483 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005484static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005485{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005486 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005487 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5488 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005489 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005490
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005491 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005492
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005493 if (adapter->link_up)
5494 ixgbe_watchdog_link_is_up(adapter);
5495 else
5496 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005497
Greg Rosea985b6c32010-11-18 03:02:52 +00005498 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005499 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005500
5501 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005502}
5503
Alexander Duyck70864002011-04-27 09:13:56 +00005504/**
5505 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5506 * @adapter - the ixgbe adapter structure
5507 **/
5508static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5509{
5510 struct ixgbe_hw *hw = &adapter->hw;
5511 s32 err;
5512
5513 /* not searching for SFP so there is nothing to do here */
5514 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5515 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5516 return;
5517
5518 /* someone else is in init, wait until next service event */
5519 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5520 return;
5521
5522 err = hw->phy.ops.identify_sfp(hw);
5523 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5524 goto sfp_out;
5525
5526 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5527 /* If no cable is present, then we need to reset
5528 * the next time we find a good cable. */
5529 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5530 }
5531
5532 /* exit on error */
5533 if (err)
5534 goto sfp_out;
5535
5536 /* exit if reset not needed */
5537 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5538 goto sfp_out;
5539
5540 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5541
5542 /*
5543 * A module may be identified correctly, but the EEPROM may not have
5544 * support for that module. setup_sfp() will fail in that case, so
5545 * we should not allow that module to load.
5546 */
5547 if (hw->mac.type == ixgbe_mac_82598EB)
5548 err = hw->phy.ops.reset(hw);
5549 else
5550 err = hw->mac.ops.setup_sfp(hw);
5551
5552 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5553 goto sfp_out;
5554
5555 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5556 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5557
5558sfp_out:
5559 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5560
5561 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5562 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5563 e_dev_err("failed to initialize because an unsupported "
5564 "SFP+ module type was detected.\n");
5565 e_dev_err("Reload the driver after installing a "
5566 "supported module.\n");
5567 unregister_netdev(adapter->netdev);
5568 }
5569}
5570
5571/**
5572 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
5573 * @adapter - the ixgbe adapter structure
5574 **/
5575static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5576{
5577 struct ixgbe_hw *hw = &adapter->hw;
5578 u32 autoneg;
5579 bool negotiation;
5580
5581 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5582 return;
5583
5584 /* someone else is in init, wait until next service event */
5585 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5586 return;
5587
5588 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5589
5590 autoneg = hw->phy.autoneg_advertised;
5591 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5592 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005593 if (hw->mac.ops.setup_link)
5594 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5595
5596 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5597 adapter->link_check_timeout = jiffies;
5598 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5599}
5600
Greg Rose83c61fa2011-09-07 05:59:35 +00005601#ifdef CONFIG_PCI_IOV
5602static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5603{
5604 int vf;
5605 struct ixgbe_hw *hw = &adapter->hw;
5606 struct net_device *netdev = adapter->netdev;
5607 u32 gpc;
5608 u32 ciaa, ciad;
5609
5610 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5611 if (gpc) /* If incrementing then no need for the check below */
5612 return;
5613 /*
5614 * Check to see if a bad DMA write target from an errant or
5615 * malicious VF has caused a PCIe error. If so then we can
5616 * issue a VFLR to the offending VF(s) and then resume without
5617 * requesting a full slot reset.
5618 */
5619
5620 for (vf = 0; vf < adapter->num_vfs; vf++) {
5621 ciaa = (vf << 16) | 0x80000000;
5622 /* 32 bit read so align, we really want status at offset 6 */
5623 ciaa |= PCI_COMMAND;
5624 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5625 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5626 ciaa &= 0x7FFFFFFF;
5627 /* disable debug mode asap after reading data */
5628 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5629 /* Get the upper 16 bits which will be the PCI status reg */
5630 ciad >>= 16;
5631 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5632 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5633 /* Issue VFLR */
5634 ciaa = (vf << 16) | 0x80000000;
5635 ciaa |= 0xA8;
5636 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5637 ciad = 0x00008000; /* VFLR */
5638 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5639 ciaa &= 0x7FFFFFFF;
5640 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5641 }
5642 }
5643}
5644
5645#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005646/**
5647 * ixgbe_service_timer - Timer Call-back
5648 * @data: pointer to adapter cast into an unsigned long
5649 **/
5650static void ixgbe_service_timer(unsigned long data)
5651{
5652 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5653 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005654 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005655
5656 /* poll faster when waiting for link */
5657 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5658 next_event_offset = HZ / 10;
5659 else
5660 next_event_offset = HZ * 2;
5661
Greg Rose83c61fa2011-09-07 05:59:35 +00005662#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005663 /*
5664 * don't bother with SR-IOV VF DMA hang check if there are
5665 * no VFs or the link is down
5666 */
5667 if (!adapter->num_vfs ||
5668 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5669 goto normal_timer_service;
5670
5671 /* If we have VFs allocated then we must check for DMA hangs */
5672 ixgbe_check_for_bad_vf(adapter);
5673 next_event_offset = HZ / 50;
5674 adapter->timer_event_accumulator++;
5675
5676 if (adapter->timer_event_accumulator >= 100)
5677 adapter->timer_event_accumulator = 0;
5678 else
5679 ready = false;
5680
5681normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005682#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005683 /* Reset the timer */
5684 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5685
Greg Rose83c61fa2011-09-07 05:59:35 +00005686 if (ready)
5687 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005688}
5689
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005690static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5691{
5692 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5693 return;
5694
5695 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5696
5697 /* If we're already down or resetting, just bail */
5698 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5699 test_bit(__IXGBE_RESETTING, &adapter->state))
5700 return;
5701
5702 ixgbe_dump(adapter);
5703 netdev_err(adapter->netdev, "Reset adapter\n");
5704 adapter->tx_timeout_count++;
5705
5706 ixgbe_reinit_locked(adapter);
5707}
5708
Alexander Duyck70864002011-04-27 09:13:56 +00005709/**
5710 * ixgbe_service_task - manages and runs subtasks
5711 * @work: pointer to work_struct containing our data
5712 **/
5713static void ixgbe_service_task(struct work_struct *work)
5714{
5715 struct ixgbe_adapter *adapter = container_of(work,
5716 struct ixgbe_adapter,
5717 service_task);
5718
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005719 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005720 ixgbe_sfp_detection_subtask(adapter);
5721 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005722 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005723 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005724 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005725 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005726
5727 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005728}
5729
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005730static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5731 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005732 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005733{
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, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005736 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005737
Alexander Duyck897ab152011-05-27 05:31:47 +00005738 if (!skb_is_gso(skb))
5739 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005740
Alexander Duyck897ab152011-05-27 05:31:47 +00005741 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005742 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005743 if (err)
5744 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005745 }
5746
Alexander Duyck897ab152011-05-27 05:31:47 +00005747 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5748 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5749
Alexander Duyck244e27a2012-02-08 07:51:11 +00005750 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005751 struct iphdr *iph = ip_hdr(skb);
5752 iph->tot_len = 0;
5753 iph->check = 0;
5754 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5755 iph->daddr, 0,
5756 IPPROTO_TCP,
5757 0);
5758 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005759 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5760 IXGBE_TX_FLAGS_CSUM |
5761 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005762 } else if (skb_is_gso_v6(skb)) {
5763 ipv6_hdr(skb)->payload_len = 0;
5764 tcp_hdr(skb)->check =
5765 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5766 &ipv6_hdr(skb)->daddr,
5767 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005768 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5769 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005770 }
5771
Alexander Duyck091a6242012-02-08 07:51:01 +00005772 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005773 l4len = tcp_hdrlen(skb);
5774 *hdr_len = skb_transport_offset(skb) + l4len;
5775
Alexander Duyck091a6242012-02-08 07:51:01 +00005776 /* update gso size and bytecount with header size */
5777 first->gso_segs = skb_shinfo(skb)->gso_segs;
5778 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5779
Alexander Duyck897ab152011-05-27 05:31:47 +00005780 /* mss_l4len_id: use 1 as index for TSO */
5781 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5782 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5783 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5784
5785 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5786 vlan_macip_lens = skb_network_header_len(skb);
5787 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005788 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005789
5790 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005791 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005792
5793 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005794}
5795
Alexander Duyck244e27a2012-02-08 07:51:11 +00005796static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5797 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005798{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005799 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005800 u32 vlan_macip_lens = 0;
5801 u32 mss_l4len_idx = 0;
5802 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005803
Alexander Duyck897ab152011-05-27 05:31:47 +00005804 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005805 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
5806 !(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5807 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00005808 } else {
5809 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005810 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005811 case __constant_htons(ETH_P_IP):
5812 vlan_macip_lens |= skb_network_header_len(skb);
5813 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5814 l4_hdr = ip_hdr(skb)->protocol;
5815 break;
5816 case __constant_htons(ETH_P_IPV6):
5817 vlan_macip_lens |= skb_network_header_len(skb);
5818 l4_hdr = ipv6_hdr(skb)->nexthdr;
5819 break;
5820 default:
5821 if (unlikely(net_ratelimit())) {
5822 dev_warn(tx_ring->dev,
5823 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005824 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005825 }
5826 break;
5827 }
Auke Kok9a799d72007-09-15 14:07:45 -07005828
Alexander Duyck897ab152011-05-27 05:31:47 +00005829 switch (l4_hdr) {
5830 case IPPROTO_TCP:
5831 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5832 mss_l4len_idx = tcp_hdrlen(skb) <<
5833 IXGBE_ADVTXD_L4LEN_SHIFT;
5834 break;
5835 case IPPROTO_SCTP:
5836 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
5837 mss_l4len_idx = sizeof(struct sctphdr) <<
5838 IXGBE_ADVTXD_L4LEN_SHIFT;
5839 break;
5840 case IPPROTO_UDP:
5841 mss_l4len_idx = sizeof(struct udphdr) <<
5842 IXGBE_ADVTXD_L4LEN_SHIFT;
5843 break;
5844 default:
5845 if (unlikely(net_ratelimit())) {
5846 dev_warn(tx_ring->dev,
5847 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005848 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00005849 }
5850 break;
5851 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00005852
5853 /* update TX checksum flag */
5854 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005855 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005856
Alexander Duyck244e27a2012-02-08 07:51:11 +00005857 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00005858 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005859 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005860
5861 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
5862 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07005863}
5864
Alexander Duyckd3d00232011-07-15 02:31:25 +00005865static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
5866{
5867 /* set type for advanced descriptor with frame checksum insertion */
5868 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
5869 IXGBE_ADVTXD_DCMD_IFCS |
5870 IXGBE_ADVTXD_DCMD_DEXT);
5871
5872 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00005873 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005874 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
5875
5876 /* set segmentation enable bits for TSO/FSO */
5877#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005878 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005879#else
5880 if (tx_flags & IXGBE_TX_FLAGS_TSO)
5881#endif
5882 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
5883
5884 return cmd_type;
5885}
5886
Alexander Duyck729739b2012-02-08 07:51:06 +00005887static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
5888 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005889{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005890 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005891
5892 /* enable L4 checksum for TSO and TX checksum offload */
5893 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5894 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
5895
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005896 /* enble IPv4 checksum for TSO */
5897 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5898 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005899
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005900 /* use index 1 context for TSO/FSO/FCOE */
5901#ifdef IXGBE_FCOE
5902 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
5903#else
5904 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005905#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005906 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
5907
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005908 /*
5909 * Check Context must be set if Tx switch is enabled, which it
5910 * always is for case where virtual functions are running
5911 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005912#ifdef IXGBE_FCOE
5913 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
5914#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005915 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00005916#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00005917 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
5918
Alexander Duyck729739b2012-02-08 07:51:06 +00005919 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005920}
5921
5922#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
5923 IXGBE_TXD_CMD_RS)
5924
5925static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00005926 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00005927 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07005928{
Alexander Duyckd3d00232011-07-15 02:31:25 +00005929 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00005930 struct sk_buff *skb = first->skb;
5931 struct ixgbe_tx_buffer *tx_buffer;
5932 union ixgbe_adv_tx_desc *tx_desc;
5933 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00005934 unsigned int data_len = skb->data_len;
5935 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00005936 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005937 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00005938 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005939 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07005940
Alexander Duyck729739b2012-02-08 07:51:06 +00005941 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5942
5943 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
5944 cmd_type = ixgbe_tx_cmd_type(tx_flags);
5945
Alexander Duyckd3d00232011-07-15 02:31:25 +00005946#ifdef IXGBE_FCOE
5947 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005948 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00005949 size -= sizeof(struct fcoe_crc_eof) - data_len;
5950 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00005951 } else {
5952 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005953 }
Auke Kok9a799d72007-09-15 14:07:45 -07005954 }
5955
Alexander Duyckd3d00232011-07-15 02:31:25 +00005956#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00005957 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5958 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00005959 goto dma_error;
5960
Alexander Duyck729739b2012-02-08 07:51:06 +00005961 /* record length, and DMA address */
5962 dma_unmap_len_set(first, len, size);
5963 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005964
Alexander Duyck729739b2012-02-08 07:51:06 +00005965 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005966
5967 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00005968 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00005969 tx_desc->read.cmd_type_len =
5970 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005971
Alexander Duyckd3d00232011-07-15 02:31:25 +00005972 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00005973 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005974 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00005975 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005976 i = 0;
5977 }
Alexander Duyck729739b2012-02-08 07:51:06 +00005978
5979 dma += IXGBE_MAX_DATA_PER_TXD;
5980 size -= IXGBE_MAX_DATA_PER_TXD;
5981
5982 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5983 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005984 }
5985
Alexander Duyck729739b2012-02-08 07:51:06 +00005986 if (likely(!data_len))
5987 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00005988
Ben Greearf43f3132012-03-06 09:42:04 +00005989 if (unlikely(skb->no_fcs))
5990 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00005991 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00005992
Alexander Duyck729739b2012-02-08 07:51:06 +00005993 i++;
5994 tx_desc++;
5995 if (i == tx_ring->count) {
5996 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5997 i = 0;
5998 }
Auke Kok9a799d72007-09-15 14:07:45 -07005999
Alexander Duyckd3d00232011-07-15 02:31:25 +00006000#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006001 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006002#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006003 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006004#endif
6005 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006006
Alexander Duyck729739b2012-02-08 07:51:06 +00006007 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6008 DMA_TO_DEVICE);
6009 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006010 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006011
Alexander Duyck729739b2012-02-08 07:51:06 +00006012 tx_buffer = &tx_ring->tx_buffer_info[i];
6013 dma_unmap_len_set(tx_buffer, len, size);
6014 dma_unmap_addr_set(tx_buffer, dma, dma);
6015
6016 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6017 tx_desc->read.olinfo_status = 0;
6018
6019 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07006020 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006021
Alexander Duyck729739b2012-02-08 07:51:06 +00006022 /* write last descriptor with RS and EOP bits */
6023 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6024 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006025
Alexander Duyck091a6242012-02-08 07:51:01 +00006026 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006027
Alexander Duyckd3d00232011-07-15 02:31:25 +00006028 /* set the timestamp */
6029 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006030
6031 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006032 * Force memory writes to complete before letting h/w know there
6033 * are new descriptors to fetch. (Only applicable for weak-ordered
6034 * memory model archs, such as IA-64).
6035 *
6036 * We also need this memory barrier to make certain all of the
6037 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006038 */
6039 wmb();
6040
Alexander Duyckd3d00232011-07-15 02:31:25 +00006041 /* set next_to_watch value indicating a packet is present */
6042 first->next_to_watch = tx_desc;
6043
Alexander Duyck729739b2012-02-08 07:51:06 +00006044 i++;
6045 if (i == tx_ring->count)
6046 i = 0;
6047
6048 tx_ring->next_to_use = i;
6049
Alexander Duyckd3d00232011-07-15 02:31:25 +00006050 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006051 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006052
6053 return;
6054dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006055 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006056
6057 /* clear dma mappings for failed tx_buffer_info map */
6058 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006059 tx_buffer = &tx_ring->tx_buffer_info[i];
6060 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6061 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006062 break;
6063 if (i == 0)
6064 i = tx_ring->count;
6065 i--;
6066 }
6067
Alexander Duyckd3d00232011-07-15 02:31:25 +00006068 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006069}
6070
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006071static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006072 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006073{
Alexander Duyck69830522011-01-06 14:29:58 +00006074 struct ixgbe_q_vector *q_vector = ring->q_vector;
6075 union ixgbe_atr_hash_dword input = { .dword = 0 };
6076 union ixgbe_atr_hash_dword common = { .dword = 0 };
6077 union {
6078 unsigned char *network;
6079 struct iphdr *ipv4;
6080 struct ipv6hdr *ipv6;
6081 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006082 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006083 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006084
Alexander Duyck69830522011-01-06 14:29:58 +00006085 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6086 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006087 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006088
Alexander Duyck69830522011-01-06 14:29:58 +00006089 /* do nothing if sampling is disabled */
6090 if (!ring->atr_sample_rate)
6091 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006092
Alexander Duyck69830522011-01-06 14:29:58 +00006093 ring->atr_count++;
6094
6095 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006096 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006097
6098 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006099 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006100 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006101 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006102 hdr.ipv4->protocol != IPPROTO_TCP))
6103 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006104
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006105 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006106
Alexander Duyck66f32a82011-06-29 05:43:22 +00006107 /* skip this packet since it is invalid or the socket is closing */
6108 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006109 return;
6110
6111 /* sample on all syn packets or once every atr sample count */
6112 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6113 return;
6114
6115 /* reset sample count */
6116 ring->atr_count = 0;
6117
Alexander Duyck244e27a2012-02-08 07:51:11 +00006118 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006119
6120 /*
6121 * src and dst are inverted, think how the receiver sees them
6122 *
6123 * The input is broken into two sections, a non-compressed section
6124 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6125 * is XORed together and stored in the compressed dword.
6126 */
6127 input.formatted.vlan_id = vlan_id;
6128
6129 /*
6130 * since src port and flex bytes occupy the same word XOR them together
6131 * and write the value to source port portion of compressed dword
6132 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006133 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006134 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6135 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006136 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006137 common.port.dst ^= th->source;
6138
Alexander Duyck244e27a2012-02-08 07:51:11 +00006139 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006140 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6141 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6142 } else {
6143 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6144 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6145 hdr.ipv6->saddr.s6_addr32[1] ^
6146 hdr.ipv6->saddr.s6_addr32[2] ^
6147 hdr.ipv6->saddr.s6_addr32[3] ^
6148 hdr.ipv6->daddr.s6_addr32[0] ^
6149 hdr.ipv6->daddr.s6_addr32[1] ^
6150 hdr.ipv6->daddr.s6_addr32[2] ^
6151 hdr.ipv6->daddr.s6_addr32[3];
6152 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006153
6154 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006155 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6156 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006157}
6158
Alexander Duyck63544e92011-05-27 05:31:42 +00006159static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006160{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006161 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006162 /* Herbert's original patch had:
6163 * smp_mb__after_netif_stop_queue();
6164 * but since that doesn't exist yet, just open code it. */
6165 smp_mb();
6166
6167 /* We need to check again in a case another CPU has just
6168 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006169 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006170 return -EBUSY;
6171
6172 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006173 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006174 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006175 return 0;
6176}
6177
Alexander Duyck82d4e462011-06-11 01:44:58 +00006178static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006179{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006180 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006181 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006182 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006183}
6184
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006185static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6186{
6187 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006188 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6189 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006190#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006191 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006192
John Fastabende5b64632011-03-08 03:44:52 +00006193 if (((protocol == htons(ETH_P_FCOE)) ||
6194 (protocol == htons(ETH_P_FIP))) &&
6195 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6196 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6197 txq += adapter->ring_feature[RING_F_FCOE].mask;
6198 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006199 }
6200#endif
6201
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006202 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6203 while (unlikely(txq >= dev->real_num_tx_queues))
6204 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006205 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006206 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006207
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006208 return skb_tx_hash(dev, skb);
6209}
6210
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006211netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006212 struct ixgbe_adapter *adapter,
6213 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006214{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006215 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006216 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006217 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006218#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6219 unsigned short f;
6220#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006221 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006222 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006223 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006224
Alexander Duycka535c302011-05-27 05:31:52 +00006225 /*
6226 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006227 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006228 * + 2 desc gap to keep tail from touching head,
6229 * + 1 desc for context descriptor,
6230 * otherwise try next time
6231 */
6232#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6233 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6234 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6235#else
6236 count += skb_shinfo(skb)->nr_frags;
6237#endif
6238 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6239 tx_ring->tx_stats.tx_busy++;
6240 return NETDEV_TX_BUSY;
6241 }
6242
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006243 /* record the location of the first descriptor for this packet */
6244 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6245 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006246 first->bytecount = skb->len;
6247 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006248
Alexander Duyck66f32a82011-06-29 05:43:22 +00006249 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006250 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006251 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6252 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6253 /* else if it is a SW VLAN check the next protocol and store the tag */
6254 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6255 struct vlan_hdr *vhdr, _vhdr;
6256 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6257 if (!vhdr)
6258 goto out_drop;
6259
6260 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006261 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6262 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006263 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006264 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006265
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006266#ifdef CONFIG_PCI_IOV
6267 /*
6268 * Use the l2switch_enable flag - would be false if the DMA
6269 * Tx switch had been disabled.
6270 */
6271 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6272 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6273
6274#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006275 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006276 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006277 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6278 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006279 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006280 tx_flags |= (skb->priority & 0x7) <<
6281 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006282 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6283 struct vlan_ethhdr *vhdr;
6284 if (skb_header_cloned(skb) &&
6285 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6286 goto out_drop;
6287 vhdr = (struct vlan_ethhdr *)skb->data;
6288 vhdr->h_vlan_TCI = htons(tx_flags >>
6289 IXGBE_TX_FLAGS_VLAN_SHIFT);
6290 } else {
6291 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6292 }
6293 }
Alexander Duycka535c302011-05-27 05:31:52 +00006294
Alexander Duyck244e27a2012-02-08 07:51:11 +00006295 /* record initial flags and protocol */
6296 first->tx_flags = tx_flags;
6297 first->protocol = protocol;
6298
Yi Zoueacd73f2009-05-13 13:11:06 +00006299#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006300 /* setup tx offload for FCoE */
6301 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6302 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006303 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006304 if (tso < 0)
6305 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006306
Alexander Duyck66f32a82011-06-29 05:43:22 +00006307 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006308 }
Auke Kok9a799d72007-09-15 14:07:45 -07006309
Auke Kok9a799d72007-09-15 14:07:45 -07006310#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006311 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006312 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006313 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006314 else if (!tso)
6315 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006316
6317 /* add the ATR filter if ATR is on */
6318 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006319 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006320
6321#ifdef IXGBE_FCOE
6322xmit_fcoe:
6323#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006324 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006325
6326 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006327
6328 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006329
6330out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006331 dev_kfree_skb_any(first->skb);
6332 first->skb = NULL;
6333
Alexander Duyck897ab152011-05-27 05:31:47 +00006334 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006335}
6336
Alexander Duycka50c29d2012-02-08 07:50:40 +00006337static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6338 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006339{
6340 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006341 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006342
Alexander Duycka50c29d2012-02-08 07:50:40 +00006343 if (skb->len <= 0) {
6344 dev_kfree_skb_any(skb);
6345 return NETDEV_TX_OK;
6346 }
6347
6348 /*
6349 * The minimum packet size for olinfo paylen is 17 so pad the skb
6350 * in order to meet this minimum size requirement.
6351 */
6352 if (skb->len < 17) {
6353 if (skb_padto(skb, 17))
6354 return NETDEV_TX_OK;
6355 skb->len = 17;
6356 }
6357
Auke Kok9a799d72007-09-15 14:07:45 -07006358 tx_ring = adapter->tx_ring[skb->queue_mapping];
6359 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6360}
6361
6362/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006363 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006364 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006365 * @p: pointer to an address structure
6366 *
Auke Kok9a799d72007-09-15 14:07:45 -07006367 * Returns 0 on success, negative on failure
6368 **/
6369static int ixgbe_set_mac(struct net_device *netdev, void *p)
6370{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006371 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6372 struct ixgbe_hw *hw = &adapter->hw;
6373 struct sockaddr *addr = p;
6374
6375 if (!is_valid_ether_addr(addr->sa_data))
6376 return -EADDRNOTAVAIL;
6377
6378 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6379 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6380
6381 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6382 IXGBE_RAH_AV);
6383
6384 return 0;
6385}
6386
6387static int
6388ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6389{
6390 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6391 struct ixgbe_hw *hw = &adapter->hw;
6392 u16 value;
6393 int rc;
6394
6395 if (prtad != hw->phy.mdio.prtad)
6396 return -EINVAL;
6397 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6398 if (!rc)
6399 rc = value;
6400 return rc;
6401}
6402
6403static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6404 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006405{
6406 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00006407 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006408
6409 if (prtad != hw->phy.mdio.prtad)
6410 return -EINVAL;
6411 return hw->phy.ops.write_reg(hw, addr, devad, value);
6412}
6413
6414static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6415{
6416 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6417
6418 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6419}
6420
6421/**
6422 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6423 * netdev->dev_addrs
6424 * @netdev: network interface device structure
6425 *
6426 * Returns non-zero on failure
6427 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00006428static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006429{
6430 int err = 0;
6431 struct ixgbe_adapter *adapter = netdev_priv(dev);
6432 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6433
6434 if (is_valid_ether_addr(mac->san_addr)) {
6435 rtnl_lock();
6436 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6437 rtnl_unlock();
6438 }
6439 return err;
6440}
6441
6442/**
6443 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6444 * netdev->dev_addrs
6445 * @netdev: network interface device structure
6446 *
Auke Kok9a799d72007-09-15 14:07:45 -07006447 * Returns non-zero on failure
6448 **/
6449static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6450{
6451 int err = 0;
6452 struct ixgbe_adapter *adapter = netdev_priv(dev);
6453 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6454
6455 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006456 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07006457 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006458 rtnl_unlock();
6459 }
6460 return err;
6461}
Auke Kok9a799d72007-09-15 14:07:45 -07006462
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006463#ifdef CONFIG_NET_POLL_CONTROLLER
6464/*
6465 * Polling 'interrupt' - used by things like netconsole to send skbs
6466 * without having to re-enable interrupts. It's not called while
6467 * the interrupt routine is executing.
6468 */
6469static void ixgbe_netpoll(struct net_device *netdev)
6470{
6471 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006472 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006473
6474 /* if interface is down do nothing */
6475 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006476 return;
6477
6478 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08006479 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006480 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00006481 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006482 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00006483 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006484 }
6485 } else {
6486 ixgbe_intr(adapter->pdev->irq, netdev);
6487 }
6488 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6489}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006490
Alexander Duyck581330b2012-02-08 07:51:47 +00006491#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006492static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6493 struct rtnl_link_stats64 *stats)
6494{
6495 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6496 int i;
6497
Eric Dumazet1a515022010-11-16 19:26:42 -08006498 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006499 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006500 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006501 u64 bytes, packets;
6502 unsigned int start;
6503
Eric Dumazet1a515022010-11-16 19:26:42 -08006504 if (ring) {
6505 do {
6506 start = u64_stats_fetch_begin_bh(&ring->syncp);
6507 packets = ring->stats.packets;
6508 bytes = ring->stats.bytes;
6509 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6510 stats->rx_packets += packets;
6511 stats->rx_bytes += bytes;
6512 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006513 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006514
6515 for (i = 0; i < adapter->num_tx_queues; i++) {
6516 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6517 u64 bytes, packets;
6518 unsigned int start;
6519
6520 if (ring) {
6521 do {
6522 start = u64_stats_fetch_begin_bh(&ring->syncp);
6523 packets = ring->stats.packets;
6524 bytes = ring->stats.bytes;
6525 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6526 stats->tx_packets += packets;
6527 stats->tx_bytes += bytes;
6528 }
6529 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006530 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006531 /* following stats updated by ixgbe_watchdog_task() */
6532 stats->multicast = netdev->stats.multicast;
6533 stats->rx_errors = netdev->stats.rx_errors;
6534 stats->rx_length_errors = netdev->stats.rx_length_errors;
6535 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6536 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6537 return stats;
6538}
6539
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006540#ifdef CONFIG_IXGBE_DCB
John Fastabend8b1c0b22011-05-03 02:26:48 +00006541/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6542 * #adapter: pointer to ixgbe_adapter
6543 * @tc: number of traffic classes currently enabled
6544 *
6545 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6546 * 802.1Q priority maps to a packet buffer that exists.
6547 */
6548static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6549{
6550 struct ixgbe_hw *hw = &adapter->hw;
6551 u32 reg, rsave;
6552 int i;
6553
6554 /* 82598 have a static priority to TC mapping that can not
6555 * be changed so no validation is needed.
6556 */
6557 if (hw->mac.type == ixgbe_mac_82598EB)
6558 return;
6559
6560 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6561 rsave = reg;
6562
6563 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6564 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6565
6566 /* If up2tc is out of bounds default to zero */
6567 if (up2tc > tc)
6568 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6569 }
6570
6571 if (reg != rsave)
6572 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6573
6574 return;
6575}
6576
John Fastabend8b1c0b22011-05-03 02:26:48 +00006577/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
6578 * classes.
6579 *
6580 * @netdev: net device to configure
6581 * @tc: number of traffic classes to enable
6582 */
6583int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6584{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006585 struct ixgbe_adapter *adapter = netdev_priv(dev);
6586 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006587
John Fastabende7589ea2011-07-18 22:38:36 +00006588 /* Multiple traffic classes requires multiple queues */
6589 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6590 e_err(drv, "Enable failed, needs MSI-X\n");
6591 return -EINVAL;
6592 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00006593
6594 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006595 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006596 (hw->mac.type == ixgbe_mac_82598EB &&
6597 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006598 return -EINVAL;
6599
6600 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006601 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006602 * hardware is not flexible enough to do this dynamically.
6603 */
6604 if (netif_running(dev))
6605 ixgbe_close(dev);
6606 ixgbe_clear_interrupt_scheme(adapter);
6607
John Fastabende7589ea2011-07-18 22:38:36 +00006608 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006609 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00006610 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
6611 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6612
Alexander Duyck943561d2012-05-09 22:14:44 -07006613 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6614 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006615 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006616 }
John Fastabende7589ea2011-07-18 22:38:36 +00006617 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006618 netdev_reset_tc(dev);
Alexander Duyck943561d2012-05-09 22:14:44 -07006619 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6620 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006621
6622 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6623 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6624
6625 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6626 adapter->dcb_cfg.pfc_mode_enable = false;
6627 }
6628
John Fastabend8b1c0b22011-05-03 02:26:48 +00006629 ixgbe_init_interrupt_scheme(adapter);
6630 ixgbe_validate_rtr(adapter, tc);
6631 if (netif_running(dev))
6632 ixgbe_open(dev);
6633
6634 return 0;
6635}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006636
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006637#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006638void ixgbe_do_reset(struct net_device *netdev)
6639{
6640 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6641
6642 if (netif_running(netdev))
6643 ixgbe_reinit_locked(adapter);
6644 else
6645 ixgbe_reset(adapter);
6646}
6647
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006648static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006649 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006650{
6651 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6652
6653#ifdef CONFIG_DCB
6654 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Alexander Duyck567d2de2012-02-11 07:18:57 +00006655 features &= ~NETIF_F_HW_VLAN_RX;
Don Skidmore082757a2011-07-21 05:55:00 +00006656#endif
6657
6658 /* return error if RXHASH is being enabled when RSS is not supported */
6659 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
Alexander Duyck567d2de2012-02-11 07:18:57 +00006660 features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00006661
6662 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006663 if (!(features & NETIF_F_RXCSUM))
6664 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006665
Alexander Duyck567d2de2012-02-11 07:18:57 +00006666 /* Turn off LRO if not RSC capable */
6667 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6668 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006669
Don Skidmore082757a2011-07-21 05:55:00 +00006670
Alexander Duyck567d2de2012-02-11 07:18:57 +00006671 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006672}
6673
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006674static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006675 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006676{
6677 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006678 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006679 bool need_reset = false;
6680
Don Skidmore082757a2011-07-21 05:55:00 +00006681 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006682 if (!(features & NETIF_F_LRO)) {
6683 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006684 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006685 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6686 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6687 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6688 if (adapter->rx_itr_setting == 1 ||
6689 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6690 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6691 need_reset = true;
6692 } else if ((changed ^ features) & NETIF_F_LRO) {
6693 e_info(probe, "rx-usecs set too low, "
6694 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006695 }
6696 }
6697
6698 /*
6699 * Check if Flow Director n-tuple support was enabled or disabled. If
6700 * the state changed, we need to reset.
6701 */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006702 if (!(features & NETIF_F_NTUPLE)) {
6703 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
6704 /* turn off Flow Director, set ATR and reset */
6705 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
6706 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
6707 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00006708 need_reset = true;
6709 }
Don Skidmore082757a2011-07-21 05:55:00 +00006710 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006711 } else if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
6712 /* turn off ATR, enable perfect filters and reset */
6713 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6714 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00006715 need_reset = true;
6716 }
6717
Ben Greear3f2d1c02012-03-08 08:28:41 +00006718 if (changed & NETIF_F_RXALL)
6719 need_reset = true;
6720
Alexander Duyck567d2de2012-02-11 07:18:57 +00006721 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006722 if (need_reset)
6723 ixgbe_do_reset(netdev);
6724
6725 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006726}
6727
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006728static int ixgbe_ndo_fdb_add(struct ndmsg *ndm,
6729 struct net_device *dev,
6730 unsigned char *addr,
6731 u16 flags)
6732{
6733 struct ixgbe_adapter *adapter = netdev_priv(dev);
6734 int err = -EOPNOTSUPP;
6735
6736 if (ndm->ndm_state & NUD_PERMANENT) {
6737 pr_info("%s: FDB only supports static addresses\n",
6738 ixgbe_driver_name);
6739 return -EINVAL;
6740 }
6741
6742 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6743 if (is_unicast_ether_addr(addr))
6744 err = dev_uc_add_excl(dev, addr);
6745 else if (is_multicast_ether_addr(addr))
6746 err = dev_mc_add_excl(dev, addr);
6747 else
6748 err = -EINVAL;
6749 }
6750
6751 /* Only return duplicate errors if NLM_F_EXCL is set */
6752 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6753 err = 0;
6754
6755 return err;
6756}
6757
6758static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6759 struct net_device *dev,
6760 unsigned char *addr)
6761{
6762 struct ixgbe_adapter *adapter = netdev_priv(dev);
6763 int err = -EOPNOTSUPP;
6764
6765 if (ndm->ndm_state & NUD_PERMANENT) {
6766 pr_info("%s: FDB only supports static addresses\n",
6767 ixgbe_driver_name);
6768 return -EINVAL;
6769 }
6770
6771 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6772 if (is_unicast_ether_addr(addr))
6773 err = dev_uc_del(dev, addr);
6774 else if (is_multicast_ether_addr(addr))
6775 err = dev_mc_del(dev, addr);
6776 else
6777 err = -EINVAL;
6778 }
6779
6780 return err;
6781}
6782
6783static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
6784 struct netlink_callback *cb,
6785 struct net_device *dev,
6786 int idx)
6787{
6788 struct ixgbe_adapter *adapter = netdev_priv(dev);
6789
6790 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6791 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
6792
6793 return idx;
6794}
6795
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006796static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00006797 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006798 .ndo_stop = ixgbe_close,
6799 .ndo_start_xmit = ixgbe_xmit_frame,
6800 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00006801 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006802 .ndo_validate_addr = eth_validate_addr,
6803 .ndo_set_mac_address = ixgbe_set_mac,
6804 .ndo_change_mtu = ixgbe_change_mtu,
6805 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006806 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
6807 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00006808 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00006809 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
6810 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
6811 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00006812 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00006813 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00006814 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006815#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00006816 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006817#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006818#ifdef CONFIG_NET_POLL_CONTROLLER
6819 .ndo_poll_controller = ixgbe_netpoll,
6820#endif
Yi Zou332d4a72009-05-13 13:11:53 +00006821#ifdef IXGBE_FCOE
6822 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00006823 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00006824 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00006825 .ndo_fcoe_enable = ixgbe_fcoe_enable,
6826 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00006827 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00006828 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00006829#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00006830 .ndo_set_features = ixgbe_set_features,
6831 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006832 .ndo_fdb_add = ixgbe_ndo_fdb_add,
6833 .ndo_fdb_del = ixgbe_ndo_fdb_del,
6834 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006835};
6836
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006837static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006838 const struct ixgbe_info *ii)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006839{
6840#ifdef CONFIG_PCI_IOV
6841 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006842
Greg Rosec6bda302011-08-24 02:37:55 +00006843 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006844 return;
6845
6846 /* The 82599 supports up to 64 VFs per physical function
6847 * but this implementation limits allocation to 63 so that
6848 * basic networking resources are still available to the
Greg Rose6b42a9c2012-04-17 04:29:29 +00006849 * physical function. If the user requests greater thn
6850 * 63 VFs then it is an error - reset to default of zero.
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006851 */
Greg Rose6b42a9c2012-04-17 04:29:29 +00006852 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00006853 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006854#endif /* CONFIG_PCI_IOV */
6855}
6856
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006857/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00006858 * ixgbe_wol_supported - Check whether device supports WoL
6859 * @hw: hw specific details
6860 * @device_id: the device ID
6861 * @subdev_id: the subsystem device ID
6862 *
6863 * This function is used by probe and ethtool to determine
6864 * which devices have WoL support
6865 *
6866 **/
6867int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
6868 u16 subdevice_id)
6869{
6870 struct ixgbe_hw *hw = &adapter->hw;
6871 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
6872 int is_wol_supported = 0;
6873
6874 switch (device_id) {
6875 case IXGBE_DEV_ID_82599_SFP:
6876 /* Only these subdevices could supports WOL */
6877 switch (subdevice_id) {
6878 case IXGBE_SUBDEV_ID_82599_560FLR:
6879 /* only support first port */
6880 if (hw->bus.func != 0)
6881 break;
6882 case IXGBE_SUBDEV_ID_82599_SFP:
6883 is_wol_supported = 1;
6884 break;
6885 }
6886 break;
6887 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
6888 /* All except this subdevice support WOL */
6889 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
6890 is_wol_supported = 1;
6891 break;
6892 case IXGBE_DEV_ID_82599_KX4:
6893 is_wol_supported = 1;
6894 break;
6895 case IXGBE_DEV_ID_X540T:
6896 /* check eeprom to see if enabled wol */
6897 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
6898 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
6899 (hw->bus.func == 0))) {
6900 is_wol_supported = 1;
6901 }
6902 break;
6903 }
6904
6905 return is_wol_supported;
6906}
6907
6908/**
Auke Kok9a799d72007-09-15 14:07:45 -07006909 * ixgbe_probe - Device Initialization Routine
6910 * @pdev: PCI device information struct
6911 * @ent: entry in ixgbe_pci_tbl
6912 *
6913 * Returns 0 on success, negative on failure
6914 *
6915 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
6916 * The OS initialization, configuring of the adapter private structure,
6917 * and a hardware reset occur.
6918 **/
6919static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00006920 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07006921{
6922 struct net_device *netdev;
6923 struct ixgbe_adapter *adapter = NULL;
6924 struct ixgbe_hw *hw;
6925 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07006926 static int cards_found;
6927 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00006928 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00006929 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00006930#ifdef IXGBE_FCOE
6931 u16 device_caps;
6932#endif
Don Skidmore289700db2010-12-03 03:32:58 +00006933 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07006934
Andy Gospodarekbded64a2010-07-21 06:40:31 +00006935 /* Catch broken hardware that put the wrong VF device ID in
6936 * the PCIe SR-IOV capability.
6937 */
6938 if (pdev->is_virtfn) {
6939 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
6940 pci_name(pdev), pdev->vendor, pdev->device);
6941 return -EINVAL;
6942 }
6943
gouji-new9ce77662009-05-06 10:44:45 +00006944 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006945 if (err)
6946 return err;
6947
Nick Nunley1b507732010-04-27 13:10:27 +00006948 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
6949 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07006950 pci_using_dac = 1;
6951 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00006952 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07006953 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00006954 err = dma_set_coherent_mask(&pdev->dev,
6955 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07006956 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00006957 dev_err(&pdev->dev,
6958 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006959 goto err_dma;
6960 }
6961 }
6962 pci_using_dac = 0;
6963 }
6964
gouji-new9ce77662009-05-06 10:44:45 +00006965 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00006966 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07006967 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00006968 dev_err(&pdev->dev,
6969 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07006970 goto err_pci_reg;
6971 }
6972
Frans Pop19d5afd2009-10-02 10:04:12 -07006973 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006974
Auke Kok9a799d72007-09-15 14:07:45 -07006975 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07006976 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006977
John Fastabende901acd2011-04-26 07:26:08 +00006978#ifdef CONFIG_IXGBE_DCB
6979 indices *= MAX_TRAFFIC_CLASS;
6980#endif
6981
John Fastabendc85a2612010-02-25 23:15:21 +00006982 if (ii->mac == ixgbe_mac_82598EB)
6983 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
6984 else
6985 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
6986
John Fastabende901acd2011-04-26 07:26:08 +00006987#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00006988 indices += min_t(unsigned int, num_possible_cpus(),
6989 IXGBE_MAX_FCOE_INDICES);
6990#endif
John Fastabendc85a2612010-02-25 23:15:21 +00006991 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07006992 if (!netdev) {
6993 err = -ENOMEM;
6994 goto err_alloc_etherdev;
6995 }
6996
Auke Kok9a799d72007-09-15 14:07:45 -07006997 SET_NETDEV_DEV(netdev, &pdev->dev);
6998
Auke Kok9a799d72007-09-15 14:07:45 -07006999 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007000 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007001
7002 adapter->netdev = netdev;
7003 adapter->pdev = pdev;
7004 hw = &adapter->hw;
7005 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007006 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007007
Jeff Kirsher05857982008-09-11 19:57:00 -07007008 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007009 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007010 if (!hw->hw_addr) {
7011 err = -EIO;
7012 goto err_ioremap;
7013 }
7014
7015 for (i = 1; i <= 5; i++) {
7016 if (pci_resource_len(pdev, i) == 0)
7017 continue;
7018 }
7019
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007020 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007021 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007022 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007023 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007024
Auke Kok9a799d72007-09-15 14:07:45 -07007025 adapter->bd_number = cards_found;
7026
Auke Kok9a799d72007-09-15 14:07:45 -07007027 /* Setup hw api */
7028 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007029 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007030
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007031 /* EEPROM */
7032 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7033 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7034 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7035 if (!(eec & (1 << 8)))
7036 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7037
7038 /* PHY */
7039 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007040 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007041 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7042 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7043 hw->phy.mdio.mmds = 0;
7044 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7045 hw->phy.mdio.dev = netdev;
7046 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7047 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007048
Don Skidmore8ca783a2009-05-26 20:40:47 -07007049 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007050
7051 /* setup the private structure */
7052 err = ixgbe_sw_init(adapter);
7053 if (err)
7054 goto err_sw_init;
7055
Don Skidmoree86bff02010-02-11 04:14:08 +00007056 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007057 switch (adapter->hw.mac.type) {
7058 case ixgbe_mac_82599EB:
7059 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007060 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007061 break;
7062 default:
7063 break;
7064 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007065
Don Skidmorebf069c92009-05-07 10:39:54 +00007066 /*
7067 * If there is a fan on this device and it has failed log the
7068 * failure.
7069 */
7070 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7071 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7072 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007073 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007074 }
7075
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007076 if (allow_unsupported_sfp)
7077 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7078
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007079 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007080 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007081 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007082 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007083 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7084 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007085 err = 0;
7086 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007087 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007088 "module type was detected.\n");
7089 e_dev_err("Reload the driver after installing a supported "
7090 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007091 goto err_sw_init;
7092 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007093 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007094 goto err_sw_init;
7095 }
7096
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007097 ixgbe_probe_vf(adapter, ii);
7098
Emil Tantilov396e7992010-07-01 20:05:12 +00007099 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007100 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007101 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007102 NETIF_F_HW_VLAN_TX |
7103 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007104 NETIF_F_HW_VLAN_FILTER |
7105 NETIF_F_TSO |
7106 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007107 NETIF_F_RXHASH |
7108 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007109
Don Skidmore082757a2011-07-21 05:55:00 +00007110 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007111
Don Skidmore58be7662011-04-12 09:42:11 +00007112 switch (adapter->hw.mac.type) {
7113 case ixgbe_mac_82599EB:
7114 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007115 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007116 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7117 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007118 break;
7119 default:
7120 break;
7121 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007122
Ben Greear3f2d1c02012-03-08 08:28:41 +00007123 netdev->hw_features |= NETIF_F_RXALL;
7124
Jeff Kirsherad31c402008-06-05 04:05:30 -07007125 netdev->vlan_features |= NETIF_F_TSO;
7126 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007127 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007128 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007129 netdev->vlan_features |= NETIF_F_SG;
7130
Jiri Pirko01789342011-08-16 06:29:00 +00007131 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007132 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007133
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007134 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7135 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7136 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007137
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007138#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007139 netdev->dcbnl_ops = &dcbnl_ops;
7140#endif
7141
Yi Zoueacd73f2009-05-13 13:11:06 +00007142#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007143 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007144 if (hw->mac.ops.get_device_caps) {
7145 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007146 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7147 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007148 }
7149 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007150 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7151 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7152 netdev->vlan_features |= NETIF_F_FSO;
7153 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7154 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007155#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007156 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007157 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007158 netdev->vlan_features |= NETIF_F_HIGHDMA;
7159 }
Auke Kok9a799d72007-09-15 14:07:45 -07007160
Don Skidmore082757a2011-07-21 05:55:00 +00007161 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7162 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007163 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007164 netdev->features |= NETIF_F_LRO;
7165
Auke Kok9a799d72007-09-15 14:07:45 -07007166 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007167 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007168 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007169 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007170 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007171 }
7172
7173 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7174 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7175
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007176 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007177 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007178 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007179 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007180 }
7181
Alexander Duyck70864002011-04-27 09:13:56 +00007182 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007183 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007184
Alexander Duyck70864002011-04-27 09:13:56 +00007185 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7186 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007187
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007188 err = ixgbe_init_interrupt_scheme(adapter);
7189 if (err)
7190 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007191
Don Skidmore082757a2011-07-21 05:55:00 +00007192 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7193 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007194 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007195 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007196
Jacob Keller8e2813f2012-04-21 06:05:40 +00007197 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007198 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007199 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7200 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007201 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007202
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007203 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7204
Emil Tantilov15e52092011-09-29 05:01:29 +00007205 /* save off EEPROM version number */
7206 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7207 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7208
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007209 /* pick up the PCI bus settings for reporting later */
7210 hw->mac.ops.get_bus_info(hw);
7211
Auke Kok9a799d72007-09-15 14:07:45 -07007212 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007213 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007214 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7215 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007216 "Unknown"),
7217 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7218 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7219 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7220 "Unknown"),
7221 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007222
7223 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7224 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007225 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007226 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007227 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007228 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007229 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007230 else
Don Skidmore289700db2010-12-03 03:32:58 +00007231 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7232 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007233
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007234 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007235 e_dev_warn("PCI-Express bandwidth available for this card is "
7236 "not sufficient for optimal performance.\n");
7237 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7238 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007239 }
7240
Auke Kok9a799d72007-09-15 14:07:45 -07007241 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007242 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007243 if (err == IXGBE_ERR_EEPROM_VERSION) {
7244 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007245 e_dev_warn("This device is a pre-production adapter/LOM. "
7246 "Please be aware there may be issues associated "
7247 "with your hardware. If you are experiencing "
7248 "problems please contact your Intel or hardware "
7249 "representative who provided you with this "
7250 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007251 }
Auke Kok9a799d72007-09-15 14:07:45 -07007252 strcpy(netdev->name, "eth%d");
7253 err = register_netdev(netdev);
7254 if (err)
7255 goto err_register;
7256
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007257 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7258 if (hw->mac.ops.disable_tx_laser &&
7259 ((hw->phy.multispeed_fiber) ||
7260 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7261 (hw->mac.type == ixgbe_mac_82599EB))))
7262 hw->mac.ops.disable_tx_laser(hw);
7263
Jesse Brandeburg54386462009-04-17 20:44:27 +00007264 /* carrier off reporting is important to ethtool even BEFORE open */
7265 netif_carrier_off(netdev);
7266
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007267#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007268 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007269 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007270 ixgbe_setup_dca(adapter);
7271 }
7272#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007273 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007274 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007275 for (i = 0; i < adapter->num_vfs; i++)
7276 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7277 }
7278
Jacob Keller2466dd92011-09-08 03:50:54 +00007279 /* firmware requires driver version to be 0xFFFFFFFF
7280 * since os does not support feature
7281 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007282 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007283 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7284 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007285
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007286 /* add san mac addr to netdev */
7287 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007288
Neerav Parikhea818752012-01-04 20:23:40 +00007289 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007290 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007291
7292 if (ixgbe_sysfs_init(adapter))
7293 e_err(probe, "failed to allocate sysfs resources\n");
7294
Auke Kok9a799d72007-09-15 14:07:45 -07007295 return 0;
7296
7297err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007298 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007299 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007300err_sw_init:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007301 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7302 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007303 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007304 iounmap(hw->hw_addr);
7305err_ioremap:
7306 free_netdev(netdev);
7307err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007308 pci_release_selected_regions(pdev,
7309 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007310err_pci_reg:
7311err_dma:
7312 pci_disable_device(pdev);
7313 return err;
7314}
7315
7316/**
7317 * ixgbe_remove - Device Removal Routine
7318 * @pdev: PCI device information struct
7319 *
7320 * ixgbe_remove is called by the PCI subsystem to alert the driver
7321 * that it should release a PCI device. The could be caused by a
7322 * Hot-Plug event, or because the driver is going to be removed from
7323 * memory.
7324 **/
7325static void __devexit ixgbe_remove(struct pci_dev *pdev)
7326{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007327 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7328 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007329
7330 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007331 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007332
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007333#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007334 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7335 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7336 dca_remove_requester(&pdev->dev);
7337 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7338 }
7339
7340#endif
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007341 ixgbe_sysfs_exit(adapter);
7342
Yi Zou332d4a72009-05-13 13:11:53 +00007343#ifdef IXGBE_FCOE
7344 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7345 ixgbe_cleanup_fcoe(adapter);
7346
7347#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007348
7349 /* remove the added san mac */
7350 ixgbe_del_sanmac_netdev(netdev);
7351
Donald Skidmorec4900be2008-11-20 21:11:42 -08007352 if (netdev->reg_state == NETREG_REGISTERED)
7353 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007354
Greg Rosec6bda302011-08-24 02:37:55 +00007355 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7356 if (!(ixgbe_check_vf_assignment(adapter)))
7357 ixgbe_disable_sriov(adapter);
7358 else
7359 e_dev_warn("Unloading driver while VFs are assigned "
7360 "- VFs will not be deallocated\n");
7361 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007362
Alexander Duyck7a921c92009-05-06 10:43:28 +00007363 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007364
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007365 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007366
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007367#ifdef CONFIG_DCB
7368 kfree(adapter->ixgbe_ieee_pfc);
7369 kfree(adapter->ixgbe_ieee_ets);
7370
7371#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007372 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007373 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007374 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007375
Emil Tantilov849c4542010-06-03 16:53:41 +00007376 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007377
Auke Kok9a799d72007-09-15 14:07:45 -07007378 free_netdev(netdev);
7379
Frans Pop19d5afd2009-10-02 10:04:12 -07007380 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007381
Auke Kok9a799d72007-09-15 14:07:45 -07007382 pci_disable_device(pdev);
7383}
7384
7385/**
7386 * ixgbe_io_error_detected - called when PCI error is detected
7387 * @pdev: Pointer to PCI device
7388 * @state: The current pci connection state
7389 *
7390 * This function is called after a PCI bus error affecting
7391 * this device has been detected.
7392 */
7393static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007394 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007395{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007396 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7397 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007398
Greg Rose83c61fa2011-09-07 05:59:35 +00007399#ifdef CONFIG_PCI_IOV
7400 struct pci_dev *bdev, *vfdev;
7401 u32 dw0, dw1, dw2, dw3;
7402 int vf, pos;
7403 u16 req_id, pf_func;
7404
7405 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7406 adapter->num_vfs == 0)
7407 goto skip_bad_vf_detection;
7408
7409 bdev = pdev->bus->self;
7410 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
7411 bdev = bdev->bus->self;
7412
7413 if (!bdev)
7414 goto skip_bad_vf_detection;
7415
7416 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7417 if (!pos)
7418 goto skip_bad_vf_detection;
7419
7420 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7421 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7422 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7423 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7424
7425 req_id = dw1 >> 16;
7426 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7427 if (!(req_id & 0x0080))
7428 goto skip_bad_vf_detection;
7429
7430 pf_func = req_id & 0x01;
7431 if ((pf_func & 1) == (pdev->devfn & 1)) {
7432 unsigned int device_id;
7433
7434 vf = (req_id & 0x7F) >> 1;
7435 e_dev_err("VF %d has caused a PCIe error\n", vf);
7436 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7437 "%8.8x\tdw3: %8.8x\n",
7438 dw0, dw1, dw2, dw3);
7439 switch (adapter->hw.mac.type) {
7440 case ixgbe_mac_82599EB:
7441 device_id = IXGBE_82599_VF_DEVICE_ID;
7442 break;
7443 case ixgbe_mac_X540:
7444 device_id = IXGBE_X540_VF_DEVICE_ID;
7445 break;
7446 default:
7447 device_id = 0;
7448 break;
7449 }
7450
7451 /* Find the pci device of the offending VF */
7452 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
7453 while (vfdev) {
7454 if (vfdev->devfn == (req_id & 0xFF))
7455 break;
7456 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
7457 device_id, vfdev);
7458 }
7459 /*
7460 * There's a slim chance the VF could have been hot plugged,
7461 * so if it is no longer present we don't need to issue the
7462 * VFLR. Just clean up the AER in that case.
7463 */
7464 if (vfdev) {
7465 e_dev_err("Issuing VFLR to VF %d\n", vf);
7466 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7467 }
7468
7469 pci_cleanup_aer_uncorrect_error_status(pdev);
7470 }
7471
7472 /*
7473 * Even though the error may have occurred on the other port
7474 * we still need to increment the vf error reference count for
7475 * both ports because the I/O resume function will be called
7476 * for both of them.
7477 */
7478 adapter->vferr_refcount++;
7479
7480 return PCI_ERS_RESULT_RECOVERED;
7481
7482skip_bad_vf_detection:
7483#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007484 netif_device_detach(netdev);
7485
Breno Leitao3044b8d2009-05-06 10:44:26 +00007486 if (state == pci_channel_io_perm_failure)
7487 return PCI_ERS_RESULT_DISCONNECT;
7488
Auke Kok9a799d72007-09-15 14:07:45 -07007489 if (netif_running(netdev))
7490 ixgbe_down(adapter);
7491 pci_disable_device(pdev);
7492
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007493 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007494 return PCI_ERS_RESULT_NEED_RESET;
7495}
7496
7497/**
7498 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7499 * @pdev: Pointer to PCI device
7500 *
7501 * Restart the card from scratch, as if from a cold-boot.
7502 */
7503static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7504{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007505 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007506 pci_ers_result_t result;
7507 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007508
gouji-new9ce77662009-05-06 10:44:45 +00007509 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007510 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007511 result = PCI_ERS_RESULT_DISCONNECT;
7512 } else {
7513 pci_set_master(pdev);
7514 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007515 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007516
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007517 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007518
7519 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007520 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007521 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007522 }
Auke Kok9a799d72007-09-15 14:07:45 -07007523
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007524 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7525 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007526 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7527 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007528 /* non-fatal, continue */
7529 }
Auke Kok9a799d72007-09-15 14:07:45 -07007530
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007531 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007532}
7533
7534/**
7535 * ixgbe_io_resume - called when traffic can start flowing again.
7536 * @pdev: Pointer to PCI device
7537 *
7538 * This callback is called when the error recovery driver tells us that
7539 * its OK to resume normal operation.
7540 */
7541static void ixgbe_io_resume(struct pci_dev *pdev)
7542{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007543 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7544 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007545
Greg Rose83c61fa2011-09-07 05:59:35 +00007546#ifdef CONFIG_PCI_IOV
7547 if (adapter->vferr_refcount) {
7548 e_info(drv, "Resuming after VF err\n");
7549 adapter->vferr_refcount--;
7550 return;
7551 }
7552
7553#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007554 if (netif_running(netdev))
7555 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007556
7557 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007558}
7559
7560static struct pci_error_handlers ixgbe_err_handler = {
7561 .error_detected = ixgbe_io_error_detected,
7562 .slot_reset = ixgbe_io_slot_reset,
7563 .resume = ixgbe_io_resume,
7564};
7565
7566static struct pci_driver ixgbe_driver = {
7567 .name = ixgbe_driver_name,
7568 .id_table = ixgbe_pci_tbl,
7569 .probe = ixgbe_probe,
7570 .remove = __devexit_p(ixgbe_remove),
7571#ifdef CONFIG_PM
7572 .suspend = ixgbe_suspend,
7573 .resume = ixgbe_resume,
7574#endif
7575 .shutdown = ixgbe_shutdown,
7576 .err_handler = &ixgbe_err_handler
7577};
7578
7579/**
7580 * ixgbe_init_module - Driver Registration Routine
7581 *
7582 * ixgbe_init_module is the first routine called when the driver is
7583 * loaded. All it does is register with the PCI subsystem.
7584 **/
7585static int __init ixgbe_init_module(void)
7586{
7587 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007588 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007589 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007590
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007591#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007592 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007593#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007594
Auke Kok9a799d72007-09-15 14:07:45 -07007595 ret = pci_register_driver(&ixgbe_driver);
7596 return ret;
7597}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007598
Auke Kok9a799d72007-09-15 14:07:45 -07007599module_init(ixgbe_init_module);
7600
7601/**
7602 * ixgbe_exit_module - Driver Exit Cleanup Routine
7603 *
7604 * ixgbe_exit_module is called just before the driver is removed
7605 * from memory.
7606 **/
7607static void __exit ixgbe_exit_module(void)
7608{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007609#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007610 dca_unregister_notify(&dca_notifier);
7611#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007612 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007613 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007614}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007615
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007616#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007617static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007618 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007619{
7620 int ret_val;
7621
7622 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007623 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007624
7625 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7626}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007627
Alexander Duyckb4533682009-03-31 21:32:42 +00007628#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007629
Auke Kok9a799d72007-09-15 14:07:45 -07007630module_exit(ixgbe_exit_module);
7631
7632/* ixgbe_main.c */