blob: e2a6691cbd7c52f94d5053f300579a9a90637b49 [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 Skidmoreeef45602012-04-28 03:29:22 +000066#define MIN 9
67#define BUILD 15
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000068#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000069 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070070const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000071static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000072 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070073
74static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070075 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000076 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e2010-11-16 19:27:16 -080077 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070078};
79
80/* ixgbe_pci_tbl - PCI Device ID Table
81 *
82 * Wildcard entries (PCI_ANY_ID) should come last
83 * Last entry must be all 0s
84 *
85 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
86 * Class, Class Mask, private data (not used) }
87 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000088static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700118 /* required last entry */
119 {0, }
120};
121MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
122
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400123#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800124static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000125 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800126static struct notifier_block dca_notifier = {
127 .notifier_call = ixgbe_notify_dca,
128 .next = NULL,
129 .priority = 0
130};
131#endif
132
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000133#ifdef CONFIG_PCI_IOV
134static unsigned int max_vfs;
135module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000136MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000137 "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 +0000138#endif /* CONFIG_PCI_IOV */
139
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000140static unsigned int allow_unsupported_sfp;
141module_param(allow_unsupported_sfp, uint, 0);
142MODULE_PARM_DESC(allow_unsupported_sfp,
143 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
144
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000145#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
146static int debug = -1;
147module_param(debug, int, 0);
148MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
149
Auke Kok9a799d72007-09-15 14:07:45 -0700150MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
151MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
152MODULE_LICENSE("GPL");
153MODULE_VERSION(DRV_VERSION);
154
Alexander Duyck70864002011-04-27 09:13:56 +0000155static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
156{
157 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
158 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
159 schedule_work(&adapter->service_task);
160}
161
162static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
163{
164 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
165
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000166 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000167 smp_mb__before_clear_bit();
168 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
169}
170
Taku Izumidcd79ae2010-04-27 14:39:53 +0000171struct ixgbe_reg_info {
172 u32 ofs;
173 char *name;
174};
175
176static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
177
178 /* General Registers */
179 {IXGBE_CTRL, "CTRL"},
180 {IXGBE_STATUS, "STATUS"},
181 {IXGBE_CTRL_EXT, "CTRL_EXT"},
182
183 /* Interrupt Registers */
184 {IXGBE_EICR, "EICR"},
185
186 /* RX Registers */
187 {IXGBE_SRRCTL(0), "SRRCTL"},
188 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
189 {IXGBE_RDLEN(0), "RDLEN"},
190 {IXGBE_RDH(0), "RDH"},
191 {IXGBE_RDT(0), "RDT"},
192 {IXGBE_RXDCTL(0), "RXDCTL"},
193 {IXGBE_RDBAL(0), "RDBAL"},
194 {IXGBE_RDBAH(0), "RDBAH"},
195
196 /* TX Registers */
197 {IXGBE_TDBAL(0), "TDBAL"},
198 {IXGBE_TDBAH(0), "TDBAH"},
199 {IXGBE_TDLEN(0), "TDLEN"},
200 {IXGBE_TDH(0), "TDH"},
201 {IXGBE_TDT(0), "TDT"},
202 {IXGBE_TXDCTL(0), "TXDCTL"},
203
204 /* List Terminator */
205 {}
206};
207
208
209/*
210 * ixgbe_regdump - register printout routine
211 */
212static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
213{
214 int i = 0, j = 0;
215 char rname[16];
216 u32 regs[64];
217
218 switch (reginfo->ofs) {
219 case IXGBE_SRRCTL(0):
220 for (i = 0; i < 64; i++)
221 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
222 break;
223 case IXGBE_DCA_RXCTRL(0):
224 for (i = 0; i < 64; i++)
225 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
226 break;
227 case IXGBE_RDLEN(0):
228 for (i = 0; i < 64; i++)
229 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
230 break;
231 case IXGBE_RDH(0):
232 for (i = 0; i < 64; i++)
233 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
234 break;
235 case IXGBE_RDT(0):
236 for (i = 0; i < 64; i++)
237 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
238 break;
239 case IXGBE_RXDCTL(0):
240 for (i = 0; i < 64; i++)
241 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
242 break;
243 case IXGBE_RDBAL(0):
244 for (i = 0; i < 64; i++)
245 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
246 break;
247 case IXGBE_RDBAH(0):
248 for (i = 0; i < 64; i++)
249 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
250 break;
251 case IXGBE_TDBAL(0):
252 for (i = 0; i < 64; i++)
253 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
254 break;
255 case IXGBE_TDBAH(0):
256 for (i = 0; i < 64; i++)
257 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
258 break;
259 case IXGBE_TDLEN(0):
260 for (i = 0; i < 64; i++)
261 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
262 break;
263 case IXGBE_TDH(0):
264 for (i = 0; i < 64; i++)
265 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
266 break;
267 case IXGBE_TDT(0):
268 for (i = 0; i < 64; i++)
269 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
270 break;
271 case IXGBE_TXDCTL(0):
272 for (i = 0; i < 64; i++)
273 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
274 break;
275 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000277 IXGBE_READ_REG(hw, reginfo->ofs));
278 return;
279 }
280
281 for (i = 0; i < 8; i++) {
282 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000283 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000284 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000285 pr_cont(" %08x", regs[i*8+j]);
286 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000287 }
288
289}
290
291/*
292 * ixgbe_dump - Print registers, tx-rings and rx-rings
293 */
294static void ixgbe_dump(struct ixgbe_adapter *adapter)
295{
296 struct net_device *netdev = adapter->netdev;
297 struct ixgbe_hw *hw = &adapter->hw;
298 struct ixgbe_reg_info *reginfo;
299 int n = 0;
300 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000301 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000302 union ixgbe_adv_tx_desc *tx_desc;
303 struct my_u0 { u64 a; u64 b; } *u0;
304 struct ixgbe_ring *rx_ring;
305 union ixgbe_adv_rx_desc *rx_desc;
306 struct ixgbe_rx_buffer *rx_buffer_info;
307 u32 staterr;
308 int i = 0;
309
310 if (!netif_msg_hw(adapter))
311 return;
312
313 /* Print netdevice Info */
314 if (netdev) {
315 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000316 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000317 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info("%-15s %016lX %016lX %016lX\n",
319 netdev->name,
320 netdev->state,
321 netdev->trans_start,
322 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000323 }
324
325 /* Print Registers */
326 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000327 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000328 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
329 reginfo->name; reginfo++) {
330 ixgbe_regdump(hw, reginfo);
331 }
332
333 /* Print TX Ring Summary */
334 if (!netdev || !netif_running(netdev))
335 goto exit;
336
337 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000338 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000339 for (n = 0; n < adapter->num_tx_queues; n++) {
340 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000341 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000342 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000343 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000344 (u64)dma_unmap_addr(tx_buffer, dma),
345 dma_unmap_len(tx_buffer, len),
346 tx_buffer->next_to_watch,
347 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000348 }
349
350 /* Print TX Rings */
351 if (!netif_msg_tx_done(adapter))
352 goto rx_ring_summary;
353
354 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
355
356 /* Transmit Descriptor Formats
357 *
358 * Advanced Transmit Descriptor
359 * +--------------------------------------------------------------+
360 * 0 | Buffer Address [63:0] |
361 * +--------------------------------------------------------------+
362 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
363 * +--------------------------------------------------------------+
364 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
365 */
366
367 for (n = 0; n < adapter->num_tx_queues; n++) {
368 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000369 pr_info("------------------------------------\n");
370 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
371 pr_info("------------------------------------\n");
372 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000373 "[PlPOIdStDDt Ln] [bi->dma ] "
374 "leng ntw timestamp bi->skb\n");
375
376 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000377 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000378 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000379 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000380 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000381 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000382 le64_to_cpu(u0->a),
383 le64_to_cpu(u0->b),
Alexander Duyck729739b2012-02-08 07:51:06 +0000384 (u64)dma_unmap_addr(tx_buffer, dma),
385 dma_unmap_len(tx_buffer, len),
386 tx_buffer->next_to_watch,
387 (u64)tx_buffer->time_stamp,
388 tx_buffer->skb);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000389 if (i == tx_ring->next_to_use &&
390 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000391 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000392 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000393 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000394 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000395 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000396 else
Joe Perchesc7689572010-09-07 21:35:17 +0000397 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000398
399 if (netif_msg_pktdata(adapter) &&
Emil Tantilov9c50c032012-07-26 01:21:24 +0000400 tx_buffer->skb)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000401 print_hex_dump(KERN_INFO, "",
402 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000403 tx_buffer->skb->data,
Alexander Duyck729739b2012-02-08 07:51:06 +0000404 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
Emil Tantilov9c50c032012-07-26 01:21:24 +0000477 if (netif_msg_pktdata(adapter) &&
478 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000479 print_hex_dump(KERN_INFO, "",
480 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000481 page_address(rx_buffer_info->page) +
482 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000483 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000484 }
485 }
486
487 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000488 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000489 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000490 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000491 else
Joe Perchesc7689572010-09-07 21:35:17 +0000492 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000493
494 }
495 }
496
497exit:
498 return;
499}
500
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800501static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
502{
503 u32 ctrl_ext;
504
505 /* Let firmware take over control of h/w */
506 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
507 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000508 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800509}
510
511static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
512{
513 u32 ctrl_ext;
514
515 /* Let firmware know the driver has taken over */
516 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
517 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000518 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800519}
Auke Kok9a799d72007-09-15 14:07:45 -0700520
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000521/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000522 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
523 * @adapter: pointer to adapter struct
524 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
525 * @queue: queue to map the corresponding interrupt to
526 * @msix_vector: the vector to map to the corresponding queue
527 *
528 */
529static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000530 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700531{
532 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000533 struct ixgbe_hw *hw = &adapter->hw;
534 switch (hw->mac.type) {
535 case ixgbe_mac_82598EB:
536 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
537 if (direction == -1)
538 direction = 0;
539 index = (((direction * 64) + queue) >> 2) & 0x1F;
540 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
541 ivar &= ~(0xFF << (8 * (queue & 0x3)));
542 ivar |= (msix_vector << (8 * (queue & 0x3)));
543 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
544 break;
545 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800546 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000547 if (direction == -1) {
548 /* other causes */
549 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
550 index = ((queue & 1) * 8);
551 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
552 ivar &= ~(0xFF << index);
553 ivar |= (msix_vector << index);
554 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
555 break;
556 } else {
557 /* tx or rx causes */
558 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
559 index = ((16 * (queue & 1)) + (8 * direction));
560 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
561 ivar &= ~(0xFF << index);
562 ivar |= (msix_vector << index);
563 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
564 break;
565 }
566 default:
567 break;
568 }
Auke Kok9a799d72007-09-15 14:07:45 -0700569}
570
Alexander Duyckfe49f042009-06-04 16:00:09 +0000571static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000572 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000573{
574 u32 mask;
575
Alexander Duyckbd508172010-11-16 19:27:03 -0800576 switch (adapter->hw.mac.type) {
577 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000578 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
579 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800580 break;
581 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800582 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000583 mask = (qmask & 0xFFFFFFFF);
584 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
585 mask = (qmask >> 32);
586 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800587 break;
588 default:
589 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000590 }
591}
592
Alexander Duyck729739b2012-02-08 07:51:06 +0000593void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
594 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000595{
Alexander Duyck729739b2012-02-08 07:51:06 +0000596 if (tx_buffer->skb) {
597 dev_kfree_skb_any(tx_buffer->skb);
598 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000599 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000600 dma_unmap_addr(tx_buffer, dma),
601 dma_unmap_len(tx_buffer, len),
602 DMA_TO_DEVICE);
603 } else if (dma_unmap_len(tx_buffer, len)) {
604 dma_unmap_page(ring->dev,
605 dma_unmap_addr(tx_buffer, dma),
606 dma_unmap_len(tx_buffer, len),
607 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000608 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000609 tx_buffer->next_to_watch = NULL;
610 tx_buffer->skb = NULL;
611 dma_unmap_len_set(tx_buffer, len, 0);
612 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700613}
614
Alexander Duyck943561d2012-05-09 22:14:44 -0700615static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
616{
617 struct ixgbe_hw *hw = &adapter->hw;
618 struct ixgbe_hw_stats *hwstats = &adapter->stats;
619 int i;
620 u32 data;
621
622 if ((hw->fc.current_mode != ixgbe_fc_full) &&
623 (hw->fc.current_mode != ixgbe_fc_rx_pause))
624 return;
625
626 switch (hw->mac.type) {
627 case ixgbe_mac_82598EB:
628 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
629 break;
630 default:
631 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
632 }
633 hwstats->lxoffrxc += data;
634
635 /* refill credits (no tx hang) if we received xoff */
636 if (!data)
637 return;
638
639 for (i = 0; i < adapter->num_tx_queues; i++)
640 clear_bit(__IXGBE_HANG_CHECK_ARMED,
641 &adapter->tx_ring[i]->state);
642}
643
John Fastabendc84d3242010-11-16 19:27:12 -0800644static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700645{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700646 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800647 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800648 u32 xoff[8] = {0};
649 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700650 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700651
Alexander Duyck943561d2012-05-09 22:14:44 -0700652 if (adapter->ixgbe_ieee_pfc)
653 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800654
Alexander Duyck943561d2012-05-09 22:14:44 -0700655 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
656 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800657 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700658 }
John Fastabendc84d3242010-11-16 19:27:12 -0800659
660 /* update stats for each tc, only valid with PFC enabled */
661 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
662 switch (hw->mac.type) {
663 case ixgbe_mac_82598EB:
664 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
665 break;
666 default:
667 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
668 }
669 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700670 }
671
John Fastabendc84d3242010-11-16 19:27:12 -0800672 /* disarm tx queues that have received xoff frames */
673 for (i = 0; i < adapter->num_tx_queues; i++) {
674 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000675 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800676
677 if (xoff[tc])
678 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
679 }
680}
681
682static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
683{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000684 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800685}
686
687static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
688{
689 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
690 struct ixgbe_hw *hw = &adapter->hw;
691
692 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
693 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
694
695 if (head != tail)
696 return (head < tail) ?
697 tail - head : (tail + ring->count - head);
698
699 return 0;
700}
701
702static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
703{
704 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
705 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
706 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
707 bool ret = false;
708
709 clear_check_for_tx_hang(tx_ring);
710
711 /*
712 * Check for a hung queue, but be thorough. This verifies
713 * that a transmit has been completed since the previous
714 * check AND there is at least one packet pending. The
715 * ARMED bit is set to indicate a potential hang. The
716 * bit is cleared if a pause frame is received to remove
717 * false hang detection due to PFC or 802.3x frames. By
718 * requiring this to fail twice we avoid races with
719 * pfc clearing the ARMED bit and conditions where we
720 * run the check_tx_hang logic with a transmit completion
721 * pending but without time to complete it yet.
722 */
723 if ((tx_done_old == tx_done) && tx_pending) {
724 /* make sure it is true for two checks in a row */
725 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
726 &tx_ring->state);
727 } else {
728 /* update completed stats and continue */
729 tx_ring->tx_stats.tx_done_old = tx_done;
730 /* reset the countdown */
731 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
732 }
733
734 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700735}
736
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000737/**
738 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
739 * @adapter: driver private struct
740 **/
741static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
742{
743
744 /* Do the reset outside of interrupt context */
745 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
746 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
747 ixgbe_service_event_schedule(adapter);
748 }
749}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700750
Auke Kok9a799d72007-09-15 14:07:45 -0700751/**
752 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000753 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700754 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700755 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000756static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000757 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700758{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000759 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000760 struct ixgbe_tx_buffer *tx_buffer;
761 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700762 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000763 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000764 unsigned int i = tx_ring->next_to_clean;
765
766 if (test_bit(__IXGBE_DOWN, &adapter->state))
767 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700768
Alexander Duyckd3d00232011-07-15 02:31:25 +0000769 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000770 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000771 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800772
Alexander Duyck729739b2012-02-08 07:51:06 +0000773 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000774 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700775
Alexander Duyckd3d00232011-07-15 02:31:25 +0000776 /* if next_to_watch is not set then there is no work pending */
777 if (!eop_desc)
778 break;
779
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000780 /* prevent any other reads prior to eop_desc */
781 rmb();
782
Alexander Duyckd3d00232011-07-15 02:31:25 +0000783 /* if DD is not set pending work has not been completed */
784 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
785 break;
786
Alexander Duyckd3d00232011-07-15 02:31:25 +0000787 /* clear next_to_watch to prevent false hangs */
788 tx_buffer->next_to_watch = NULL;
789
Alexander Duyck091a6242012-02-08 07:51:01 +0000790 /* update the statistics for this packet */
791 total_bytes += tx_buffer->bytecount;
792 total_packets += tx_buffer->gso_segs;
793
Jacob Keller3a6a4ed2012-05-01 05:24:58 +0000794#ifdef CONFIG_IXGBE_PTP
Jacob Keller0ede4a62012-05-22 06:08:32 +0000795 if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP))
796 ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +0000797#endif
Jacob Keller0ede4a62012-05-22 06:08:32 +0000798
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000799 /* free the skb */
800 dev_kfree_skb_any(tx_buffer->skb);
801
Alexander Duyck729739b2012-02-08 07:51:06 +0000802 /* unmap skb header data */
803 dma_unmap_single(tx_ring->dev,
804 dma_unmap_addr(tx_buffer, dma),
805 dma_unmap_len(tx_buffer, len),
806 DMA_TO_DEVICE);
807
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000808 /* clear tx_buffer data */
809 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000810 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000811
Alexander Duyck729739b2012-02-08 07:51:06 +0000812 /* unmap remaining buffers */
813 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000814 tx_buffer++;
815 tx_desc++;
816 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000817 if (unlikely(!i)) {
818 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000819 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000820 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000821 }
822
Alexander Duyck729739b2012-02-08 07:51:06 +0000823 /* unmap any remaining paged data */
824 if (dma_unmap_len(tx_buffer, len)) {
825 dma_unmap_page(tx_ring->dev,
826 dma_unmap_addr(tx_buffer, dma),
827 dma_unmap_len(tx_buffer, len),
828 DMA_TO_DEVICE);
829 dma_unmap_len_set(tx_buffer, len, 0);
830 }
831 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800832
Alexander Duyck729739b2012-02-08 07:51:06 +0000833 /* move us one more past the eop_desc for start of next pkt */
834 tx_buffer++;
835 tx_desc++;
836 i++;
837 if (unlikely(!i)) {
838 i -= tx_ring->count;
839 tx_buffer = tx_ring->tx_buffer_info;
840 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
841 }
842
843 /* issue prefetch for next Tx descriptor */
844 prefetch(tx_desc);
845
846 /* update budget accounting */
847 budget--;
848 } while (likely(budget));
849
850 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700851 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000852 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800853 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000854 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000855 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000856 q_vector->tx.total_bytes += total_bytes;
857 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800858
John Fastabendc84d3242010-11-16 19:27:12 -0800859 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800860 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800861 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800862 e_err(drv, "Detected Tx Unit Hang\n"
863 " Tx Queue <%d>\n"
864 " TDH, TDT <%x>, <%x>\n"
865 " next_to_use <%x>\n"
866 " next_to_clean <%x>\n"
867 "tx_buffer_info[next_to_clean]\n"
868 " time_stamp <%lx>\n"
869 " jiffies <%lx>\n",
870 tx_ring->queue_index,
871 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
872 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000873 tx_ring->next_to_use, i,
874 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800875
876 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
877
878 e_info(probe,
879 "tx hang %d detected on queue %d, resetting adapter\n",
880 adapter->tx_timeout_count + 1, tx_ring->queue_index);
881
882 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000883 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800884
885 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000886 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800887 }
Auke Kok9a799d72007-09-15 14:07:45 -0700888
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000889 netdev_tx_completed_queue(txring_txq(tx_ring),
890 total_packets, total_bytes);
891
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800892#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000893 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000894 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800895 /* Make sure that anybody stopping the queue after this
896 * sees the new next_to_clean.
897 */
898 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000899 if (__netif_subqueue_stopped(tx_ring->netdev,
900 tx_ring->queue_index)
901 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
902 netif_wake_subqueue(tx_ring->netdev,
903 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800904 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800905 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800906 }
Auke Kok9a799d72007-09-15 14:07:45 -0700907
Alexander Duyck59224552011-08-31 00:01:06 +0000908 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700909}
910
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400911#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800912static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800913 struct ixgbe_ring *tx_ring,
914 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800915{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000916 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000917 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
918 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800919
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800920 switch (hw->mac.type) {
921 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000922 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800923 break;
924 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800925 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000926 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
927 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
928 break;
929 default:
930 /* for unknown hardware do not write register */
931 return;
932 }
933
934 /*
935 * We can enable relaxed ordering for reads, but not writes when
936 * DCA is enabled. This is due to a known issue in some chipsets
937 * which will cause the DCA tag to be cleared.
938 */
939 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
940 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
941 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
942
943 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
944}
945
946static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
947 struct ixgbe_ring *rx_ring,
948 int cpu)
949{
950 struct ixgbe_hw *hw = &adapter->hw;
951 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
952 u8 reg_idx = rx_ring->reg_idx;
953
954
955 switch (hw->mac.type) {
956 case ixgbe_mac_82599EB:
957 case ixgbe_mac_X540:
958 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800959 break;
960 default:
961 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800962 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000963
964 /*
965 * We can enable relaxed ordering for reads, but not writes when
966 * DCA is enabled. This is due to a known issue in some chipsets
967 * which will cause the DCA tag to be cleared.
968 */
969 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
970 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
971 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
972
973 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800974}
975
976static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
977{
978 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000979 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800980 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800981
982 if (q_vector->cpu == cpu)
983 goto out_no_update;
984
Alexander Duycka5579282012-02-08 07:50:04 +0000985 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000986 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800987
Alexander Duycka5579282012-02-08 07:50:04 +0000988 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000989 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800990
991 q_vector->cpu = cpu;
992out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800993 put_cpu();
994}
995
996static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
997{
998 int i;
999
1000 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1001 return;
1002
Alexander Duycke35ec122009-05-21 13:07:12 +00001003 /* always use CB2 mode, difference is masked in the CB driver */
1004 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1005
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001006 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001007 adapter->q_vector[i]->cpu = -1;
1008 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001009 }
1010}
1011
1012static int __ixgbe_notify_dca(struct device *dev, void *data)
1013{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001014 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001015 unsigned long event = *(unsigned long *)data;
1016
Don Skidmore2a72c312011-07-20 02:27:05 +00001017 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001018 return 0;
1019
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001020 switch (event) {
1021 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001022 /* if we're already enabled, don't do it again */
1023 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1024 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001025 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001026 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001027 ixgbe_setup_dca(adapter);
1028 break;
1029 }
1030 /* Fall Through since DCA is disabled. */
1031 case DCA_PROVIDER_REMOVE:
1032 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1033 dca_remove_requester(dev);
1034 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1035 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1036 }
1037 break;
1038 }
1039
Denis V. Lunev652f0932008-03-27 14:39:17 +03001040 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001041}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001042
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001043#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001044static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1045 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001046 struct sk_buff *skb)
1047{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001048 if (ring->netdev->features & NETIF_F_RXHASH)
1049 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001050}
1051
Alexander Duyckf8003262012-03-03 02:35:52 +00001052#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001053/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001054 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001055 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001056 * @rx_desc: advanced rx descriptor
1057 *
1058 * Returns : true if it is FCoE pkt
1059 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001060static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001061 union ixgbe_adv_rx_desc *rx_desc)
1062{
1063 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1064
Alexander Duyck57efd442012-06-25 21:54:46 +00001065 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001066 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1067 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1068 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1069}
1070
Alexander Duyckf8003262012-03-03 02:35:52 +00001071#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001072/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001073 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001074 * @ring: structure containing ring specific data
1075 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001076 * @skb: skb currently being received and modified
1077 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001078static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001079 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001080 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001081{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001082 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001083
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001084 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001085 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001086 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001087
1088 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001089 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1090 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001091 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001092 return;
1093 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001094
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001095 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001096 return;
1097
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001098 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001099 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001100
1101 /*
1102 * 82599 errata, UDP frames with a 0 checksum can be marked as
1103 * checksum errors.
1104 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001105 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1106 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001107 return;
1108
Alexander Duyck8a0da212012-01-31 02:59:49 +00001109 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001110 return;
1111 }
1112
Auke Kok9a799d72007-09-15 14:07:45 -07001113 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001114 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001115}
1116
Alexander Duyck84ea2592010-11-16 19:26:49 -08001117static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001118{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001119 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001120
1121 /* update next to alloc since we have filled the ring */
1122 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001123 /*
1124 * Force memory writes to complete before letting h/w
1125 * know there are new descriptors to fetch. (Only
1126 * applicable for weak-ordered memory model archs,
1127 * such as IA-64).
1128 */
1129 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001130 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001131}
1132
Alexander Duyckf990b792012-01-31 02:59:34 +00001133static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1134 struct ixgbe_rx_buffer *bi)
1135{
1136 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001137 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001138
Alexander Duyckf8003262012-03-03 02:35:52 +00001139 /* since we are recycling buffers we should seldom need to alloc */
1140 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001141 return true;
1142
Alexander Duyckf8003262012-03-03 02:35:52 +00001143 /* alloc new page for storage */
1144 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001145 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1146 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001147 if (unlikely(!page)) {
1148 rx_ring->rx_stats.alloc_rx_page_failed++;
1149 return false;
1150 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001151 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001152 }
1153
Alexander Duyckf8003262012-03-03 02:35:52 +00001154 /* map page for use */
1155 dma = dma_map_page(rx_ring->dev, page, 0,
1156 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001157
Alexander Duyckf8003262012-03-03 02:35:52 +00001158 /*
1159 * if mapping failed free memory back to system since
1160 * there isn't much point in holding memory we can't use
1161 */
1162 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001163 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001164 bi->page = NULL;
1165
Alexander Duyckf990b792012-01-31 02:59:34 +00001166 rx_ring->rx_stats.alloc_rx_page_failed++;
1167 return false;
1168 }
1169
Alexander Duyckf8003262012-03-03 02:35:52 +00001170 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001171 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001172
Alexander Duyckf990b792012-01-31 02:59:34 +00001173 return true;
1174}
1175
Auke Kok9a799d72007-09-15 14:07:45 -07001176/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001177 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001178 * @rx_ring: ring to place buffers on
1179 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001180 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001181void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001182{
Auke Kok9a799d72007-09-15 14:07:45 -07001183 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001184 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001185 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001186
Alexander Duyckf8003262012-03-03 02:35:52 +00001187 /* nothing to do */
1188 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001189 return;
1190
Alexander Duycke4f74022012-01-31 02:59:44 +00001191 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001192 bi = &rx_ring->rx_buffer_info[i];
1193 i -= rx_ring->count;
1194
Alexander Duyckf8003262012-03-03 02:35:52 +00001195 do {
1196 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001197 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001198
Alexander Duyckf8003262012-03-03 02:35:52 +00001199 /*
1200 * Refresh the desc even if buffer_addrs didn't change
1201 * because each write-back erases this info.
1202 */
1203 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001204
Alexander Duyckf990b792012-01-31 02:59:34 +00001205 rx_desc++;
1206 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001207 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001208 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001209 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001210 bi = rx_ring->rx_buffer_info;
1211 i -= rx_ring->count;
1212 }
1213
1214 /* clear the hdr_addr for the next_to_use descriptor */
1215 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001216
1217 cleaned_count--;
1218 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001219
Alexander Duyckf990b792012-01-31 02:59:34 +00001220 i += rx_ring->count;
1221
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001222 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001223 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001224}
1225
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001226/**
1227 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1228 * @data: pointer to the start of the headers
1229 * @max_len: total length of section to find headers in
1230 *
1231 * This function is meant to determine the length of headers that will
1232 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1233 * motivation of doing this is to only perform one pull for IPv4 TCP
1234 * packets so that we can do basic things like calculating the gso_size
1235 * based on the average data per packet.
1236 **/
1237static unsigned int ixgbe_get_headlen(unsigned char *data,
1238 unsigned int max_len)
1239{
1240 union {
1241 unsigned char *network;
1242 /* l2 headers */
1243 struct ethhdr *eth;
1244 struct vlan_hdr *vlan;
1245 /* l3 headers */
1246 struct iphdr *ipv4;
1247 } hdr;
1248 __be16 protocol;
1249 u8 nexthdr = 0; /* default to not TCP */
1250 u8 hlen;
1251
1252 /* this should never happen, but better safe than sorry */
1253 if (max_len < ETH_HLEN)
1254 return max_len;
1255
1256 /* initialize network frame pointer */
1257 hdr.network = data;
1258
1259 /* set first protocol and move network header forward */
1260 protocol = hdr.eth->h_proto;
1261 hdr.network += ETH_HLEN;
1262
1263 /* handle any vlan tag if present */
1264 if (protocol == __constant_htons(ETH_P_8021Q)) {
1265 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1266 return max_len;
1267
1268 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1269 hdr.network += VLAN_HLEN;
1270 }
1271
1272 /* handle L3 protocols */
1273 if (protocol == __constant_htons(ETH_P_IP)) {
1274 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1275 return max_len;
1276
1277 /* access ihl as a u8 to avoid unaligned access on ia64 */
1278 hlen = (hdr.network[0] & 0x0F) << 2;
1279
1280 /* verify hlen meets minimum size requirements */
1281 if (hlen < sizeof(struct iphdr))
1282 return hdr.network - data;
1283
1284 /* record next protocol */
1285 nexthdr = hdr.ipv4->protocol;
1286 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001287#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001288 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1289 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1290 return max_len;
1291 hdr.network += FCOE_HEADER_LEN;
1292#endif
1293 } else {
1294 return hdr.network - data;
1295 }
1296
1297 /* finally sort out TCP */
1298 if (nexthdr == IPPROTO_TCP) {
1299 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1300 return max_len;
1301
1302 /* access doff as a u8 to avoid unaligned access on ia64 */
1303 hlen = (hdr.network[12] & 0xF0) >> 2;
1304
1305 /* verify hlen meets minimum size requirements */
1306 if (hlen < sizeof(struct tcphdr))
1307 return hdr.network - data;
1308
1309 hdr.network += hlen;
1310 }
1311
1312 /*
1313 * If everything has gone correctly hdr.network should be the
1314 * data section of the packet and will be the end of the header.
1315 * If not then it probably represents the end of the last recognized
1316 * header.
1317 */
1318 if ((hdr.network - data) < max_len)
1319 return hdr.network - data;
1320 else
1321 return max_len;
1322}
1323
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001324static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1325 struct sk_buff *skb)
1326{
Alexander Duyckf8003262012-03-03 02:35:52 +00001327 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001328
1329 /* set gso_size to avoid messing up TCP MSS */
1330 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1331 IXGBE_CB(skb)->append_cnt);
1332}
1333
1334static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1335 struct sk_buff *skb)
1336{
1337 /* if append_cnt is 0 then frame is not RSC */
1338 if (!IXGBE_CB(skb)->append_cnt)
1339 return;
1340
1341 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1342 rx_ring->rx_stats.rsc_flush++;
1343
1344 ixgbe_set_rsc_gso_size(rx_ring, skb);
1345
1346 /* gso_size is computed using append_cnt so always clear it last */
1347 IXGBE_CB(skb)->append_cnt = 0;
1348}
1349
Alexander Duyck8a0da212012-01-31 02:59:49 +00001350/**
1351 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1352 * @rx_ring: rx descriptor ring packet is being transacted on
1353 * @rx_desc: pointer to the EOP Rx descriptor
1354 * @skb: pointer to current skb being populated
1355 *
1356 * This function checks the ring, descriptor, and packet information in
1357 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1358 * other fields within the skb.
1359 **/
1360static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1361 union ixgbe_adv_rx_desc *rx_desc,
1362 struct sk_buff *skb)
1363{
John Fastabend43e95f12012-05-15 06:12:17 +00001364 struct net_device *dev = rx_ring->netdev;
1365
Alexander Duyck8a0da212012-01-31 02:59:49 +00001366 ixgbe_update_rsc_stats(rx_ring, skb);
1367
1368 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1369
1370 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1371
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001372#ifdef CONFIG_IXGBE_PTP
Jacob Keller1d1a79b2012-05-22 06:18:08 +00001373 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001374#endif
1375
John Fastabend43e95f12012-05-15 06:12:17 +00001376 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1377 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001378 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1379 __vlan_hwaccel_put_tag(skb, vid);
1380 }
1381
1382 skb_record_rx_queue(skb, rx_ring->queue_index);
1383
John Fastabend43e95f12012-05-15 06:12:17 +00001384 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001385}
1386
1387static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1388 struct sk_buff *skb)
1389{
1390 struct ixgbe_adapter *adapter = q_vector->adapter;
1391
1392 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1393 napi_gro_receive(&q_vector->napi, skb);
1394 else
1395 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001396}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001397
Alexander Duyckf8003262012-03-03 02:35:52 +00001398/**
1399 * ixgbe_is_non_eop - process handling of non-EOP buffers
1400 * @rx_ring: Rx ring being processed
1401 * @rx_desc: Rx descriptor for current buffer
1402 * @skb: Current socket buffer containing buffer in progress
1403 *
1404 * This function updates next to clean. If the buffer is an EOP buffer
1405 * this function exits returning false, otherwise it will place the
1406 * sk_buff in the next buffer to be chained and return true indicating
1407 * that this is in fact a non-EOP buffer.
1408 **/
1409static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1410 union ixgbe_adv_rx_desc *rx_desc,
1411 struct sk_buff *skb)
1412{
1413 u32 ntc = rx_ring->next_to_clean + 1;
1414
1415 /* fetch, update, and store next to clean */
1416 ntc = (ntc < rx_ring->count) ? ntc : 0;
1417 rx_ring->next_to_clean = ntc;
1418
1419 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1420
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001421 /* update RSC append count if present */
1422 if (ring_is_rsc_enabled(rx_ring)) {
1423 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1424 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1425
1426 if (unlikely(rsc_enabled)) {
1427 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1428
1429 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1430 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1431
1432 /* update ntc based on RSC value */
1433 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1434 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1435 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1436 }
1437 }
1438
1439 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001440 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1441 return false;
1442
Alexander Duyckf8003262012-03-03 02:35:52 +00001443 /* place skb in next buffer to be received */
1444 rx_ring->rx_buffer_info[ntc].skb = skb;
1445 rx_ring->rx_stats.non_eop_descs++;
1446
1447 return true;
1448}
1449
1450/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001451 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1452 * @rx_ring: rx descriptor ring packet is being transacted on
1453 * @skb: pointer to current skb being adjusted
1454 *
1455 * This function is an ixgbe specific version of __pskb_pull_tail. The
1456 * main difference between this version and the original function is that
1457 * this function can make several assumptions about the state of things
1458 * that allow for significant optimizations versus the standard function.
1459 * As a result we can do things like drop a frag and maintain an accurate
1460 * truesize for the skb.
1461 */
1462static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1463 struct sk_buff *skb)
1464{
1465 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1466 unsigned char *va;
1467 unsigned int pull_len;
1468
1469 /*
1470 * it is valid to use page_address instead of kmap since we are
1471 * working with pages allocated out of the lomem pool per
1472 * alloc_page(GFP_ATOMIC)
1473 */
1474 va = skb_frag_address(frag);
1475
1476 /*
1477 * we need the header to contain the greater of either ETH_HLEN or
1478 * 60 bytes if the skb->len is less than 60 for skb_pad.
1479 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001480 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001481
1482 /* align pull length to size of long to optimize memcpy performance */
1483 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1484
1485 /* update all of the pointers */
1486 skb_frag_size_sub(frag, pull_len);
1487 frag->page_offset += pull_len;
1488 skb->data_len -= pull_len;
1489 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001490}
1491
1492/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001493 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1494 * @rx_ring: rx descriptor ring packet is being transacted on
1495 * @skb: pointer to current skb being updated
1496 *
1497 * This function provides a basic DMA sync up for the first fragment of an
1498 * skb. The reason for doing this is that the first fragment cannot be
1499 * unmapped until we have reached the end of packet descriptor for a buffer
1500 * chain.
1501 */
1502static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1503 struct sk_buff *skb)
1504{
1505 /* if the page was released unmap it, else just sync our portion */
1506 if (unlikely(IXGBE_CB(skb)->page_released)) {
1507 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1508 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1509 IXGBE_CB(skb)->page_released = false;
1510 } else {
1511 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1512
1513 dma_sync_single_range_for_cpu(rx_ring->dev,
1514 IXGBE_CB(skb)->dma,
1515 frag->page_offset,
1516 ixgbe_rx_bufsz(rx_ring),
1517 DMA_FROM_DEVICE);
1518 }
1519 IXGBE_CB(skb)->dma = 0;
1520}
1521
1522/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001523 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1524 * @rx_ring: rx descriptor ring packet is being transacted on
1525 * @rx_desc: pointer to the EOP Rx descriptor
1526 * @skb: pointer to current skb being fixed
1527 *
1528 * Check for corrupted packet headers caused by senders on the local L2
1529 * embedded NIC switch not setting up their Tx Descriptors right. These
1530 * should be very rare.
1531 *
1532 * Also address the case where we are pulling data in on pages only
1533 * and as such no data is present in the skb header.
1534 *
1535 * In addition if skb is not at least 60 bytes we need to pad it so that
1536 * it is large enough to qualify as a valid Ethernet frame.
1537 *
1538 * Returns true if an error was encountered and skb was freed.
1539 **/
1540static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1541 union ixgbe_adv_rx_desc *rx_desc,
1542 struct sk_buff *skb)
1543{
Alexander Duyckf8003262012-03-03 02:35:52 +00001544 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001545
1546 /* verify that the packet does not have any known errors */
1547 if (unlikely(ixgbe_test_staterr(rx_desc,
1548 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1549 !(netdev->features & NETIF_F_RXALL))) {
1550 dev_kfree_skb_any(skb);
1551 return true;
1552 }
1553
Alexander Duyck19861ce2012-07-20 08:08:33 +00001554 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001555 if (skb_is_nonlinear(skb))
1556 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001557
Alexander Duyck57efd442012-06-25 21:54:46 +00001558#ifdef IXGBE_FCOE
1559 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1560 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1561 return false;
1562
1563#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001564 /* if skb_pad returns an error the skb was freed */
1565 if (unlikely(skb->len < 60)) {
1566 int pad_len = 60 - skb->len;
1567
1568 if (skb_pad(skb, pad_len))
1569 return true;
1570 __skb_put(skb, pad_len);
1571 }
1572
1573 return false;
1574}
1575
1576/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001577 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1578 * @rx_ring: rx descriptor ring to store buffers on
1579 * @old_buff: donor buffer to have page reused
1580 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001581 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001582 **/
1583static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1584 struct ixgbe_rx_buffer *old_buff)
1585{
1586 struct ixgbe_rx_buffer *new_buff;
1587 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001588
1589 new_buff = &rx_ring->rx_buffer_info[nta];
1590
1591 /* update, and store next to alloc */
1592 nta++;
1593 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1594
1595 /* transfer page from old buffer to new buffer */
1596 new_buff->page = old_buff->page;
1597 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001598 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001599
1600 /* sync the buffer for use by the device */
1601 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001602 new_buff->page_offset,
1603 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001604 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001605}
1606
1607/**
1608 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1609 * @rx_ring: rx descriptor ring to transact packets on
1610 * @rx_buffer: buffer containing page to add
1611 * @rx_desc: descriptor containing length of buffer written by hardware
1612 * @skb: sk_buff to place the data into
1613 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001614 * This function will add the data contained in rx_buffer->page to the skb.
1615 * This is done either through a direct copy if the data in the buffer is
1616 * less than the skb header size, otherwise it will just attach the page as
1617 * a frag to the skb.
1618 *
1619 * The function will then update the page offset if necessary and return
1620 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001621 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001622static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001623 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001624 union ixgbe_adv_rx_desc *rx_desc,
1625 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001626{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001627 struct page *page = rx_buffer->page;
1628 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001629#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001630 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001631#else
1632 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1633 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1634 ixgbe_rx_bufsz(rx_ring);
1635#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001636
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001637 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1638 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1639
1640 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1641
1642 /* we can reuse buffer as-is, just make sure it is local */
1643 if (likely(page_to_nid(page) == numa_node_id()))
1644 return true;
1645
1646 /* this page cannot be reused so discard it */
1647 put_page(page);
1648 return false;
1649 }
1650
Alexander Duyck0549ae22012-07-20 08:08:18 +00001651 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1652 rx_buffer->page_offset, size, truesize);
1653
Alexander Duyck09816fb2012-07-20 08:08:23 +00001654 /* avoid re-using remote pages */
1655 if (unlikely(page_to_nid(page) != numa_node_id()))
1656 return false;
1657
1658#if (PAGE_SIZE < 8192)
1659 /* if we are only owner of page we can reuse it */
1660 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001661 return false;
1662
1663 /* flip page offset to other buffer */
1664 rx_buffer->page_offset ^= truesize;
1665
Alexander Duyck09816fb2012-07-20 08:08:23 +00001666 /*
1667 * since we are the only owner of the page and we need to
1668 * increment it, just set the value to 2 in order to avoid
1669 * an unecessary locked operation
1670 */
1671 atomic_set(&page->_count, 2);
1672#else
1673 /* move offset up to the next cache line */
1674 rx_buffer->page_offset += truesize;
1675
1676 if (rx_buffer->page_offset > last_offset)
1677 return false;
1678
Alexander Duyck0549ae22012-07-20 08:08:18 +00001679 /* bump ref count on page before it is given to the stack */
1680 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001681#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001682
1683 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001684}
1685
Alexander Duyck18806c92012-07-20 08:08:44 +00001686static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1687 union ixgbe_adv_rx_desc *rx_desc)
1688{
1689 struct ixgbe_rx_buffer *rx_buffer;
1690 struct sk_buff *skb;
1691 struct page *page;
1692
1693 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1694 page = rx_buffer->page;
1695 prefetchw(page);
1696
1697 skb = rx_buffer->skb;
1698
1699 if (likely(!skb)) {
1700 void *page_addr = page_address(page) +
1701 rx_buffer->page_offset;
1702
1703 /* prefetch first cache line of first page */
1704 prefetch(page_addr);
1705#if L1_CACHE_BYTES < 128
1706 prefetch(page_addr + L1_CACHE_BYTES);
1707#endif
1708
1709 /* allocate a skb to store the frags */
1710 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1711 IXGBE_RX_HDR_SIZE);
1712 if (unlikely(!skb)) {
1713 rx_ring->rx_stats.alloc_rx_buff_failed++;
1714 return NULL;
1715 }
1716
1717 /*
1718 * we will be copying header into skb->data in
1719 * pskb_may_pull so it is in our interest to prefetch
1720 * it now to avoid a possible cache miss
1721 */
1722 prefetchw(skb->data);
1723
1724 /*
1725 * Delay unmapping of the first packet. It carries the
1726 * header information, HW may still access the header
1727 * after the writeback. Only unmap it when EOP is
1728 * reached
1729 */
1730 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1731 goto dma_sync;
1732
1733 IXGBE_CB(skb)->dma = rx_buffer->dma;
1734 } else {
1735 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1736 ixgbe_dma_sync_frag(rx_ring, skb);
1737
1738dma_sync:
1739 /* we are reusing so sync this buffer for CPU use */
1740 dma_sync_single_range_for_cpu(rx_ring->dev,
1741 rx_buffer->dma,
1742 rx_buffer->page_offset,
1743 ixgbe_rx_bufsz(rx_ring),
1744 DMA_FROM_DEVICE);
1745 }
1746
1747 /* pull page into skb */
1748 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1749 /* hand second half of page back to the ring */
1750 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1751 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1752 /* the page has been released from the ring */
1753 IXGBE_CB(skb)->page_released = true;
1754 } else {
1755 /* we are not reusing the buffer so unmap it */
1756 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1757 ixgbe_rx_pg_size(rx_ring),
1758 DMA_FROM_DEVICE);
1759 }
1760
1761 /* clear contents of buffer_info */
1762 rx_buffer->skb = NULL;
1763 rx_buffer->dma = 0;
1764 rx_buffer->page = NULL;
1765
1766 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001767}
1768
1769/**
1770 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1771 * @q_vector: structure containing interrupt and ring information
1772 * @rx_ring: rx descriptor ring to transact packets on
1773 * @budget: Total limit on number of packets to process
1774 *
1775 * This function provides a "bounce buffer" approach to Rx interrupt
1776 * processing. The advantage to this is that on systems that have
1777 * expensive overhead for IOMMU access this provides a means of avoiding
1778 * it by maintaining the mapping of the page to the syste.
1779 *
1780 * Returns true if all work is completed without reaching budget
1781 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001782static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001783 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001784 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001785{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001786 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001787#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001788 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001789 int ddp_bytes;
1790 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001791#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001792 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001793
Alexander Duyckf8003262012-03-03 02:35:52 +00001794 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001795 union ixgbe_adv_rx_desc *rx_desc;
1796 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001797
Alexander Duyckf8003262012-03-03 02:35:52 +00001798 /* return some buffers to hardware, one at a time is too slow */
1799 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1800 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1801 cleaned_count = 0;
1802 }
Auke Kok9a799d72007-09-15 14:07:45 -07001803
Alexander Duyck18806c92012-07-20 08:08:44 +00001804 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001805
Alexander Duyckf8003262012-03-03 02:35:52 +00001806 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1807 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001808
Alexander Duyckf8003262012-03-03 02:35:52 +00001809 /*
1810 * This memory barrier is needed to keep us from reading
1811 * any other fields out of the rx_desc until we know the
1812 * RXD_STAT_DD bit is set
1813 */
1814 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001815
Alexander Duyck18806c92012-07-20 08:08:44 +00001816 /* retrieve a buffer from the ring */
1817 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001818
Alexander Duyck18806c92012-07-20 08:08:44 +00001819 /* exit if we failed to retrieve a buffer */
1820 if (!skb)
1821 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001822
Auke Kok9a799d72007-09-15 14:07:45 -07001823 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001824
Alexander Duyckf8003262012-03-03 02:35:52 +00001825 /* place incomplete frames back on ring for completion */
1826 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1827 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001828
Alexander Duyckf8003262012-03-03 02:35:52 +00001829 /* verify the packet layout is correct */
1830 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1831 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001832
1833 /* probably a little skewed due to removing CRC */
1834 total_rx_bytes += skb->len;
1835 total_rx_packets++;
1836
Alexander Duyck8a0da212012-01-31 02:59:49 +00001837 /* populate checksum, timestamp, VLAN, and protocol */
1838 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1839
Yi Zou332d4a72009-05-13 13:11:53 +00001840#ifdef IXGBE_FCOE
1841 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001842 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001843 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001844 /* include DDPed FCoE data */
1845 if (ddp_bytes > 0) {
1846 if (!mss) {
1847 mss = rx_ring->netdev->mtu -
1848 sizeof(struct fcoe_hdr) -
1849 sizeof(struct fc_frame_header) -
1850 sizeof(struct fcoe_crc_eof);
1851 if (mss > 512)
1852 mss &= ~511;
1853 }
1854 total_rx_bytes += ddp_bytes;
1855 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1856 mss);
1857 }
David S. Miller823dcd22011-08-20 10:39:12 -07001858 if (!ddp_bytes) {
1859 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001860 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001861 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001862 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001863
Yi Zou332d4a72009-05-13 13:11:53 +00001864#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001865 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001866
Alexander Duyckf8003262012-03-03 02:35:52 +00001867 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001868 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001869 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001870
Alexander Duyckc267fc12010-11-16 19:27:00 -08001871 u64_stats_update_begin(&rx_ring->syncp);
1872 rx_ring->stats.packets += total_rx_packets;
1873 rx_ring->stats.bytes += total_rx_bytes;
1874 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001875 q_vector->rx.total_packets += total_rx_packets;
1876 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001877
Alexander Duyckf8003262012-03-03 02:35:52 +00001878 if (cleaned_count)
1879 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1880
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001881 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001882}
1883
Auke Kok9a799d72007-09-15 14:07:45 -07001884/**
1885 * ixgbe_configure_msix - Configure MSI-X hardware
1886 * @adapter: board private structure
1887 *
1888 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1889 * interrupts.
1890 **/
1891static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1892{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001893 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001894 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001895 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001896
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001897 /* Populate MSIX to EITR Select */
1898 if (adapter->num_vfs > 32) {
1899 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1901 }
1902
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001903 /*
1904 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001905 * corresponding register.
1906 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001907 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001908 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001909 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001910
Alexander Duycka5579282012-02-08 07:50:04 +00001911 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001912 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001913
Alexander Duycka5579282012-02-08 07:50:04 +00001914 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001915 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001916
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001917 if (q_vector->tx.ring && !q_vector->rx.ring) {
1918 /* tx only vector */
1919 if (adapter->tx_itr_setting == 1)
1920 q_vector->itr = IXGBE_10K_ITR;
1921 else
1922 q_vector->itr = adapter->tx_itr_setting;
1923 } else {
1924 /* rx or rx/tx vector */
1925 if (adapter->rx_itr_setting == 1)
1926 q_vector->itr = IXGBE_20K_ITR;
1927 else
1928 q_vector->itr = adapter->rx_itr_setting;
1929 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001930
Alexander Duyckfe49f042009-06-04 16:00:09 +00001931 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001932 }
1933
Alexander Duyckbd508172010-11-16 19:27:03 -08001934 switch (adapter->hw.mac.type) {
1935 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001936 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001937 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001938 break;
1939 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001940 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001941 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001942 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001943 default:
1944 break;
1945 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001946 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001947
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001948 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001949 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001950 mask &= ~(IXGBE_EIMS_OTHER |
1951 IXGBE_EIMS_MAILBOX |
1952 IXGBE_EIMS_LSC);
1953
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001954 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001955}
1956
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001957enum latency_range {
1958 lowest_latency = 0,
1959 low_latency = 1,
1960 bulk_latency = 2,
1961 latency_invalid = 255
1962};
1963
1964/**
1965 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001966 * @q_vector: structure containing interrupt and ring information
1967 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001968 *
1969 * Stores a new ITR value based on packets and byte
1970 * counts during the last interrupt. The advantage of per interrupt
1971 * computation is faster updates and more accurate ITR for the current
1972 * traffic pattern. Constants in this function were computed
1973 * based on theoretical maximum wire speed and thresholds were set based
1974 * on testing data as well as attempting to minimize response time
1975 * while increasing bulk throughput.
1976 * this functionality is controlled by the InterruptThrottleRate module
1977 * parameter (see ixgbe_param.c)
1978 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001979static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1980 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001981{
Alexander Duyckbd198052011-06-11 01:45:08 +00001982 int bytes = ring_container->total_bytes;
1983 int packets = ring_container->total_packets;
1984 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001985 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001986 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001987
1988 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001989 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001990
1991 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001992 * 0-10MB/s lowest (100000 ints/s)
1993 * 10-20MB/s low (20000 ints/s)
1994 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001995 */
1996 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001997 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001998 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1999
2000 switch (itr_setting) {
2001 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002002 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002003 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002004 break;
2005 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002006 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002007 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002008 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002009 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002010 break;
2011 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002012 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002013 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002014 break;
2015 }
2016
Alexander Duyckbd198052011-06-11 01:45:08 +00002017 /* clear work counters since we have the values we need */
2018 ring_container->total_bytes = 0;
2019 ring_container->total_packets = 0;
2020
2021 /* write updated itr to ring container */
2022 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002023}
2024
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002025/**
2026 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002027 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002028 *
2029 * This function is made to be called by ethtool and by the driver
2030 * when it needs to update EITR registers at runtime. Hardware
2031 * specific quirks/differences are taken care of here.
2032 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002033void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002034{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002035 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002036 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002037 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002038 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002039
Alexander Duyckbd508172010-11-16 19:27:03 -08002040 switch (adapter->hw.mac.type) {
2041 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002042 /* must write high and low 16 bits to reset counter */
2043 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002044 break;
2045 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002046 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002047 /*
2048 * set the WDIS bit to not clear the timer bits and cause an
2049 * immediate assertion of the interrupt
2050 */
2051 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002052 break;
2053 default:
2054 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002055 }
2056 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2057}
2058
Alexander Duyckbd198052011-06-11 01:45:08 +00002059static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002060{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002061 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002062 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002063
Alexander Duyckbd198052011-06-11 01:45:08 +00002064 ixgbe_update_itr(q_vector, &q_vector->tx);
2065 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002066
Alexander Duyck08c88332011-06-11 01:45:03 +00002067 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002068
2069 switch (current_itr) {
2070 /* counts and packets in update_itr are dependent on these numbers */
2071 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002072 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002073 break;
2074 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002075 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002076 break;
2077 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002078 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002079 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002080 default:
2081 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002082 }
2083
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002084 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002085 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002086 new_itr = (10 * new_itr * q_vector->itr) /
2087 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002088
Alexander Duyckbd198052011-06-11 01:45:08 +00002089 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002090 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002091
2092 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002093 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002094}
2095
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002096/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002097 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002098 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002099 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002100static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002101{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002102 struct ixgbe_hw *hw = &adapter->hw;
2103 u32 eicr = adapter->interrupt_event;
2104
Alexander Duyckf0f97782011-04-22 04:08:09 +00002105 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002106 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002107
Alexander Duyckf0f97782011-04-22 04:08:09 +00002108 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2109 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2110 return;
2111
2112 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2113
Joe Perches7ca647b2010-09-07 21:35:40 +00002114 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002115 case IXGBE_DEV_ID_82599_T3_LOM:
2116 /*
2117 * Since the warning interrupt is for both ports
2118 * we don't have to check if:
2119 * - This interrupt wasn't for our port.
2120 * - We may have missed the interrupt so always have to
2121 * check if we got a LSC
2122 */
2123 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2124 !(eicr & IXGBE_EICR_LSC))
2125 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002126
Alexander Duyckf0f97782011-04-22 04:08:09 +00002127 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2128 u32 autoneg;
2129 bool link_up = false;
2130
Joe Perches7ca647b2010-09-07 21:35:40 +00002131 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2132
Alexander Duyckf0f97782011-04-22 04:08:09 +00002133 if (link_up)
2134 return;
2135 }
2136
2137 /* Check if this is not due to overtemp */
2138 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2139 return;
2140
2141 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002142 default:
2143 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2144 return;
2145 break;
2146 }
2147 e_crit(drv,
2148 "Network adapter has been stopped because it has over heated. "
2149 "Restart the computer. If the problem persists, "
2150 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002151
2152 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002153}
2154
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002155static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2156{
2157 struct ixgbe_hw *hw = &adapter->hw;
2158
2159 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2160 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002161 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002162 /* write to clear the interrupt */
2163 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2164 }
2165}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002166
Jacob Keller4f51bf72011-08-20 04:49:45 +00002167static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2168{
2169 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2170 return;
2171
2172 switch (adapter->hw.mac.type) {
2173 case ixgbe_mac_82599EB:
2174 /*
2175 * Need to check link state so complete overtemp check
2176 * on service task
2177 */
2178 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2179 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2180 adapter->interrupt_event = eicr;
2181 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2182 ixgbe_service_event_schedule(adapter);
2183 return;
2184 }
2185 return;
2186 case ixgbe_mac_X540:
2187 if (!(eicr & IXGBE_EICR_TS))
2188 return;
2189 break;
2190 default:
2191 return;
2192 }
2193
2194 e_crit(drv,
2195 "Network adapter has been stopped because it has over heated. "
2196 "Restart the computer. If the problem persists, "
2197 "power off the system and replace the adapter\n");
2198}
2199
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002200static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2201{
2202 struct ixgbe_hw *hw = &adapter->hw;
2203
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002204 if (eicr & IXGBE_EICR_GPI_SDP2) {
2205 /* Clear the interrupt */
2206 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002207 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2208 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2209 ixgbe_service_event_schedule(adapter);
2210 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002211 }
2212
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002213 if (eicr & IXGBE_EICR_GPI_SDP1) {
2214 /* Clear the interrupt */
2215 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002216 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2217 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2218 ixgbe_service_event_schedule(adapter);
2219 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002220 }
2221}
2222
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002223static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2224{
2225 struct ixgbe_hw *hw = &adapter->hw;
2226
2227 adapter->lsc_int++;
2228 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2229 adapter->link_check_timeout = jiffies;
2230 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2231 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002232 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002233 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002234 }
2235}
2236
Alexander Duyckfe49f042009-06-04 16:00:09 +00002237static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2238 u64 qmask)
2239{
2240 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002241 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002242
Alexander Duyckbd508172010-11-16 19:27:03 -08002243 switch (hw->mac.type) {
2244 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002245 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002246 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2247 break;
2248 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002249 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002250 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002251 if (mask)
2252 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002253 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002254 if (mask)
2255 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2256 break;
2257 default:
2258 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002259 }
2260 /* skip the flush */
2261}
2262
2263static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002264 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002265{
2266 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002267 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002268
Alexander Duyckbd508172010-11-16 19:27:03 -08002269 switch (hw->mac.type) {
2270 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002271 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002272 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2273 break;
2274 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002275 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002276 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002277 if (mask)
2278 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002279 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002280 if (mask)
2281 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2282 break;
2283 default:
2284 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002285 }
2286 /* skip the flush */
2287}
2288
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002289/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002290 * ixgbe_irq_enable - Enable default interrupt generation settings
2291 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002293static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2294 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002295{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002296 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002297
Alexander Duyck2c4af692011-07-15 07:29:55 +00002298 /* don't reenable LSC while waiting for link */
2299 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2300 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002301
Alexander Duyck2c4af692011-07-15 07:29:55 +00002302 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002303 switch (adapter->hw.mac.type) {
2304 case ixgbe_mac_82599EB:
2305 mask |= IXGBE_EIMS_GPI_SDP0;
2306 break;
2307 case ixgbe_mac_X540:
2308 mask |= IXGBE_EIMS_TS;
2309 break;
2310 default:
2311 break;
2312 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002313 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2314 mask |= IXGBE_EIMS_GPI_SDP1;
2315 switch (adapter->hw.mac.type) {
2316 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002317 mask |= IXGBE_EIMS_GPI_SDP1;
2318 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002319 case ixgbe_mac_X540:
2320 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002321 mask |= IXGBE_EIMS_MAILBOX;
2322 break;
2323 default:
2324 break;
2325 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002326
2327#ifdef CONFIG_IXGBE_PTP
2328 if (adapter->hw.mac.type == ixgbe_mac_X540)
2329 mask |= IXGBE_EIMS_TIMESYNC;
2330#endif
2331
Alexander Duyck2c4af692011-07-15 07:29:55 +00002332 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2333 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2334 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002335
Alexander Duyck2c4af692011-07-15 07:29:55 +00002336 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2337 if (queues)
2338 ixgbe_irq_enable_queues(adapter, ~0);
2339 if (flush)
2340 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002341}
2342
Alexander Duyck2c4af692011-07-15 07:29:55 +00002343static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002345 struct ixgbe_adapter *adapter = data;
2346 struct ixgbe_hw *hw = &adapter->hw;
2347 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002348
Alexander Duyck2c4af692011-07-15 07:29:55 +00002349 /*
2350 * Workaround for Silicon errata. Use clear-by-write instead
2351 * of clear-by-read. Reading with EICS will return the
2352 * interrupt causes without clearing, which later be done
2353 * with the write to EICR.
2354 */
2355 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2356 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002357
Alexander Duyck2c4af692011-07-15 07:29:55 +00002358 if (eicr & IXGBE_EICR_LSC)
2359 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002360
Alexander Duyck2c4af692011-07-15 07:29:55 +00002361 if (eicr & IXGBE_EICR_MAILBOX)
2362 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002363
Alexander Duyck2c4af692011-07-15 07:29:55 +00002364 switch (hw->mac.type) {
2365 case ixgbe_mac_82599EB:
2366 case ixgbe_mac_X540:
2367 if (eicr & IXGBE_EICR_ECC)
2368 e_info(link, "Received unrecoverable ECC Err, please "
2369 "reboot\n");
2370 /* Handle Flow Director Full threshold interrupt */
2371 if (eicr & IXGBE_EICR_FLOW_DIR) {
2372 int reinit_count = 0;
2373 int i;
2374 for (i = 0; i < adapter->num_tx_queues; i++) {
2375 struct ixgbe_ring *ring = adapter->tx_ring[i];
2376 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2377 &ring->state))
2378 reinit_count++;
2379 }
2380 if (reinit_count) {
2381 /* no more flow director interrupts until after init */
2382 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2383 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2384 ixgbe_service_event_schedule(adapter);
2385 }
2386 }
2387 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002388 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002389 break;
2390 default:
2391 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002392 }
2393
Alexander Duyck2c4af692011-07-15 07:29:55 +00002394 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002395
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002396#ifdef CONFIG_IXGBE_PTP
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002397 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2398 ixgbe_ptp_check_pps_event(adapter, eicr);
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002399#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002400
Alexander Duyck2c4af692011-07-15 07:29:55 +00002401 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002402 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002403 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002404
Alexander Duyck2c4af692011-07-15 07:29:55 +00002405 return IRQ_HANDLED;
2406}
2407
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002408static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002409{
2410 struct ixgbe_q_vector *q_vector = data;
2411
Auke Kok9a799d72007-09-15 14:07:45 -07002412 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002413
2414 if (q_vector->rx.ring || q_vector->tx.ring)
2415 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002416
2417 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002418}
2419
Auke Kok9a799d72007-09-15 14:07:45 -07002420/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002421 * ixgbe_poll - NAPI Rx polling callback
2422 * @napi: structure for representing this polling device
2423 * @budget: how many packets driver is allowed to clean
2424 *
2425 * This function is used for legacy and MSI, NAPI mode
2426 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002427int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002428{
2429 struct ixgbe_q_vector *q_vector =
2430 container_of(napi, struct ixgbe_q_vector, napi);
2431 struct ixgbe_adapter *adapter = q_vector->adapter;
2432 struct ixgbe_ring *ring;
2433 int per_ring_budget;
2434 bool clean_complete = true;
2435
2436#ifdef CONFIG_IXGBE_DCA
2437 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2438 ixgbe_update_dca(q_vector);
2439#endif
2440
2441 ixgbe_for_each_ring(ring, q_vector->tx)
2442 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2443
2444 /* attempt to distribute budget to each queue fairly, but don't allow
2445 * the budget to go below 1 because we'll exit polling */
2446 if (q_vector->rx.count > 1)
2447 per_ring_budget = max(budget/q_vector->rx.count, 1);
2448 else
2449 per_ring_budget = budget;
2450
2451 ixgbe_for_each_ring(ring, q_vector->rx)
2452 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2453 per_ring_budget);
2454
2455 /* If all work not completed, return budget and keep polling */
2456 if (!clean_complete)
2457 return budget;
2458
2459 /* all work done, exit the polling mode */
2460 napi_complete(napi);
2461 if (adapter->rx_itr_setting & 1)
2462 ixgbe_set_itr(q_vector);
2463 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2464 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2465
2466 return 0;
2467}
2468
2469/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002470 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2471 * @adapter: board private structure
2472 *
2473 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2474 * interrupts from the kernel.
2475 **/
2476static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2477{
2478 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002479 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002480 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002481
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002482 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002483 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002484 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002485
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002486 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002487 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002488 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002489 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002490 } else if (q_vector->rx.ring) {
2491 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2492 "%s-%s-%d", netdev->name, "rx", ri++);
2493 } else if (q_vector->tx.ring) {
2494 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2495 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002496 } else {
2497 /* skip this unused q_vector */
2498 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002499 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002500 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2501 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002502 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002503 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002504 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002505 goto free_queue_irqs;
2506 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002507 /* If Flow Director is enabled, set interrupt affinity */
2508 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2509 /* assign the mask for this irq */
2510 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002511 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002512 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002513 }
2514
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002515 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002516 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002518 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002519 goto free_queue_irqs;
2520 }
2521
2522 return 0;
2523
2524free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002525 while (vector) {
2526 vector--;
2527 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2528 NULL);
2529 free_irq(adapter->msix_entries[vector].vector,
2530 adapter->q_vector[vector]);
2531 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2533 pci_disable_msix(adapter->pdev);
2534 kfree(adapter->msix_entries);
2535 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002536 return err;
2537}
2538
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002539/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002540 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002541 * @irq: interrupt number
2542 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002543 **/
2544static irqreturn_t ixgbe_intr(int irq, void *data)
2545{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002546 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002547 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002548 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002549 u32 eicr;
2550
Don Skidmore54037502009-02-21 15:42:56 -08002551 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002552 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002553 * before the read of EICR.
2554 */
2555 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2556
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002558 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002559 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002560 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002561 /*
2562 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002563 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002564 * have disabled interrupts due to EIAM
2565 * finish the workaround of silicon errata on 82598. Unmask
2566 * the interrupt that we masked before the EICR read.
2567 */
2568 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2569 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002570 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002571 }
Auke Kok9a799d72007-09-15 14:07:45 -07002572
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002573 if (eicr & IXGBE_EICR_LSC)
2574 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002575
Alexander Duyckbd508172010-11-16 19:27:03 -08002576 switch (hw->mac.type) {
2577 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002578 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002579 /* Fall through */
2580 case ixgbe_mac_X540:
2581 if (eicr & IXGBE_EICR_ECC)
2582 e_info(link, "Received unrecoverable ECC err, please "
2583 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002584 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002585 break;
2586 default:
2587 break;
2588 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002589
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002590 ixgbe_check_fan_failure(adapter, eicr);
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002591#ifdef CONFIG_IXGBE_PTP
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002592 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2593 ixgbe_ptp_check_pps_event(adapter, eicr);
Jacob E Keller681ae1a2012-05-01 05:24:41 +00002594#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002595
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002596 /* would disable interrupts here but EIAM disabled it */
2597 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002598
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002599 /*
2600 * re-enable link(maybe) and non-queue interrupts, no flush.
2601 * ixgbe_poll will re-enable the queue interrupts
2602 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002603 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2604 ixgbe_irq_enable(adapter, false, false);
2605
Auke Kok9a799d72007-09-15 14:07:45 -07002606 return IRQ_HANDLED;
2607}
2608
2609/**
2610 * ixgbe_request_irq - initialize interrupts
2611 * @adapter: board private structure
2612 *
2613 * Attempts to configure interrupts using the best available
2614 * capabilities of the hardware and kernel.
2615 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002617{
2618 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002619 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002620
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002621 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002622 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002623 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002624 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002625 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002626 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002627 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002628 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002629
Alexander Duyckde88eee2012-02-08 07:49:59 +00002630 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002631 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002632
Auke Kok9a799d72007-09-15 14:07:45 -07002633 return err;
2634}
2635
2636static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2637{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002638 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002639
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002640 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002641 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002642 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002643 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002644
2645 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2646 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2647 struct msix_entry *entry = &adapter->msix_entries[vector];
2648
2649 /* free only the irqs that were actually requested */
2650 if (!q_vector->rx.ring && !q_vector->tx.ring)
2651 continue;
2652
2653 /* clear the affinity_mask in the IRQ descriptor */
2654 irq_set_affinity_hint(entry->vector, NULL);
2655
2656 free_irq(entry->vector, q_vector);
2657 }
2658
2659 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002660}
2661
2662/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002663 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2664 * @adapter: board private structure
2665 **/
2666static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2667{
Alexander Duyckbd508172010-11-16 19:27:03 -08002668 switch (adapter->hw.mac.type) {
2669 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002670 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002671 break;
2672 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002673 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002674 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2675 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002676 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002677 break;
2678 default:
2679 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002680 }
2681 IXGBE_WRITE_FLUSH(&adapter->hw);
2682 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002683 int vector;
2684
2685 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2686 synchronize_irq(adapter->msix_entries[vector].vector);
2687
2688 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002689 } else {
2690 synchronize_irq(adapter->pdev->irq);
2691 }
2692}
2693
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002694/**
Auke Kok9a799d72007-09-15 14:07:45 -07002695 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2696 *
2697 **/
2698static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2699{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002700 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002701
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002702 /* rx/tx vector */
2703 if (adapter->rx_itr_setting == 1)
2704 q_vector->itr = IXGBE_20K_ITR;
2705 else
2706 q_vector->itr = adapter->rx_itr_setting;
2707
2708 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002709
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002710 ixgbe_set_ivar(adapter, 0, 0, 0);
2711 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002712
Emil Tantilov396e7992010-07-01 20:05:12 +00002713 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002714}
2715
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002716/**
2717 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2718 * @adapter: board private structure
2719 * @ring: structure containing ring specific data
2720 *
2721 * Configure the Tx descriptor ring after a reset.
2722 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002723void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2724 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002725{
2726 struct ixgbe_hw *hw = &adapter->hw;
2727 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002728 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002729 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002730 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002731
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002732 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002733 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002734 IXGBE_WRITE_FLUSH(hw);
2735
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002736 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002737 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002738 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2739 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2740 ring->count * sizeof(union ixgbe_adv_tx_desc));
2741 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2742 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002743 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002744
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002745 /*
2746 * set WTHRESH to encourage burst writeback, it should not be set
2747 * higher than 1 when ITR is 0 as it could cause false TX hangs
2748 *
2749 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2750 * to or less than the number of on chip descriptors, which is
2751 * currently 40.
2752 */
Alexander Duycke954b372012-02-08 07:49:38 +00002753 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002754 txdctl |= (1 << 16); /* WTHRESH = 1 */
2755 else
2756 txdctl |= (8 << 16); /* WTHRESH = 8 */
2757
Alexander Duycke954b372012-02-08 07:49:38 +00002758 /*
2759 * Setting PTHRESH to 32 both improves performance
2760 * and avoids a TX hang with DFP enabled
2761 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002762 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2763 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002764
2765 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002766 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002767 ring->atr_sample_rate = adapter->atr_sample_rate;
2768 ring->atr_count = 0;
2769 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2770 } else {
2771 ring->atr_sample_rate = 0;
2772 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002773
John Fastabendc84d3242010-11-16 19:27:12 -08002774 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2775
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002776 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002777 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2778
2779 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2780 if (hw->mac.type == ixgbe_mac_82598EB &&
2781 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2782 return;
2783
2784 /* poll to verify queue is enabled */
2785 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002786 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002787 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2788 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2789 if (!wait_loop)
2790 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002791}
2792
Alexander Duyck120ff942010-08-19 13:34:50 +00002793static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2794{
2795 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002796 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002797 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002798
2799 if (hw->mac.type == ixgbe_mac_82598EB)
2800 return;
2801
2802 /* disable the arbiter while setting MTQC */
2803 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2804 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2805 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2806
2807 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002808 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2809 mtqc = IXGBE_MTQC_VT_ENA;
2810 if (tcs > 4)
2811 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2812 else if (tcs > 1)
2813 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2814 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2815 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002816 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002817 mtqc |= IXGBE_MTQC_64VF;
2818 } else {
2819 if (tcs > 4)
2820 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2821 else if (tcs > 1)
2822 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2823 else
2824 mtqc = IXGBE_MTQC_64Q_1PB;
2825 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002826
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002827 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002828
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002829 /* Enable Security TX Buffer IFG for multiple pb */
2830 if (tcs) {
2831 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2832 sectx |= IXGBE_SECTX_DCB;
2833 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002834 }
2835
2836 /* re-enable the arbiter */
2837 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2838 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2839}
2840
Auke Kok9a799d72007-09-15 14:07:45 -07002841/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002842 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002843 * @adapter: board private structure
2844 *
2845 * Configure the Tx unit of the MAC after a reset.
2846 **/
2847static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2848{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002849 struct ixgbe_hw *hw = &adapter->hw;
2850 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002851 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002852
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002853 ixgbe_setup_mtqc(adapter);
2854
2855 if (hw->mac.type != ixgbe_mac_82598EB) {
2856 /* DMATXCTL.EN must be before Tx queues are enabled */
2857 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2858 dmatxctl |= IXGBE_DMATXCTL_TE;
2859 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2860 }
2861
Auke Kok9a799d72007-09-15 14:07:45 -07002862 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002863 for (i = 0; i < adapter->num_tx_queues; i++)
2864 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002865}
2866
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002867static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2868 struct ixgbe_ring *ring)
2869{
2870 struct ixgbe_hw *hw = &adapter->hw;
2871 u8 reg_idx = ring->reg_idx;
2872 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2873
2874 srrctl |= IXGBE_SRRCTL_DROP_EN;
2875
2876 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2877}
2878
2879static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2880 struct ixgbe_ring *ring)
2881{
2882 struct ixgbe_hw *hw = &adapter->hw;
2883 u8 reg_idx = ring->reg_idx;
2884 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2885
2886 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2887
2888 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2889}
2890
2891#ifdef CONFIG_IXGBE_DCB
2892void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2893#else
2894static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2895#endif
2896{
2897 int i;
2898 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2899
2900 if (adapter->ixgbe_ieee_pfc)
2901 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2902
2903 /*
2904 * We should set the drop enable bit if:
2905 * SR-IOV is enabled
2906 * or
2907 * Number of Rx queues > 1 and flow control is disabled
2908 *
2909 * This allows us to avoid head of line blocking for security
2910 * and performance reasons.
2911 */
2912 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2913 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2914 for (i = 0; i < adapter->num_rx_queues; i++)
2915 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2916 } else {
2917 for (i = 0; i < adapter->num_rx_queues; i++)
2918 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2919 }
2920}
2921
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002922#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002923
Yi Zoua6616b42009-08-06 13:05:23 +00002924static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002925 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002926{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002927 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002928 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002929 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002930
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002931 if (hw->mac.type == ixgbe_mac_82598EB) {
2932 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2933
2934 /*
2935 * if VMDq is not active we must program one srrctl register
2936 * per RSS queue since we have enabled RDRXCTL.MVMEN
2937 */
2938 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002939 }
2940
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002941 /* configure header buffer length, needed for RSC */
2942 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002943
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002944 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00002945 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002946
2947 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00002948 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002949
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002950 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002951}
2952
Alexander Duyck05abb122010-08-19 13:35:41 +00002953static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002954{
Alexander Duyck05abb122010-08-19 13:35:41 +00002955 struct ixgbe_hw *hw = &adapter->hw;
2956 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002957 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2958 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002959 u32 mrqc = 0, reta = 0;
2960 u32 rxcsum;
2961 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002962 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00002963
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002964 /*
2965 * Program table for at least 2 queues w/ SR-IOV so that VFs can
2966 * make full use of any rings they may have. We will use the
2967 * PSRTYPE register to control how many rings we use within the PF.
2968 */
2969 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
2970 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002971
Alexander Duyck05abb122010-08-19 13:35:41 +00002972 /* Fill out hash function seeds */
2973 for (i = 0; i < 10; i++)
2974 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002975
Alexander Duyck05abb122010-08-19 13:35:41 +00002976 /* Fill out redirection table */
2977 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002978 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00002979 j = 0;
2980 /* reta = 4-byte sliding window of
2981 * 0x00..(indices-1)(indices-1)00..etc. */
2982 reta = (reta << 8) | (j * 0x11);
2983 if ((i & 3) == 3)
2984 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2985 }
2986
2987 /* Disable indicating checksum in descriptor, enables RSS hash */
2988 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2989 rxcsum |= IXGBE_RXCSUM_PCSD;
2990 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2991
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002992 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00002993 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002994 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002995 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002996 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002997
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002998 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2999 if (tcs > 4)
3000 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3001 else if (tcs > 1)
3002 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3003 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3004 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3005 else
3006 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3007 } else {
3008 if (tcs > 4)
3009 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3010 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003011 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3012 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003013 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003014 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003015 }
3016
Alexander Duyck05abb122010-08-19 13:35:41 +00003017 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003018 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3019 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3020 IXGBE_MRQC_RSS_FIELD_IPV6 |
3021 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003022
Alexander Duyckef6afc02012-02-08 07:51:53 +00003023 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3024 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3025 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3026 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3027
Alexander Duyck05abb122010-08-19 13:35:41 +00003028 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003029}
3030
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003031/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003032 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3033 * @adapter: address of board private structure
3034 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003035 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003036static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003037 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003038{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003039 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003040 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003041 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003042
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003043 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003044 return;
3045
Alexander Duyck73670962010-08-19 13:38:34 +00003046 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003047 rscctrl |= IXGBE_RSCCTL_RSCEN;
3048 /*
3049 * we must limit the number of descriptors so that the
3050 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003051 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003052 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003053 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003054 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003055}
3056
Alexander Duyck9e10e042010-08-19 13:40:06 +00003057#define IXGBE_MAX_RX_DESC_POLL 10
3058static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3059 struct ixgbe_ring *ring)
3060{
3061 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003062 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3063 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003064 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003065
3066 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3067 if (hw->mac.type == ixgbe_mac_82598EB &&
3068 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3069 return;
3070
3071 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003072 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003073 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3074 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3075
3076 if (!wait_loop) {
3077 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3078 "the polling period\n", reg_idx);
3079 }
3080}
3081
Yi Zou2d39d572011-01-06 14:29:56 +00003082void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3083 struct ixgbe_ring *ring)
3084{
3085 struct ixgbe_hw *hw = &adapter->hw;
3086 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3087 u32 rxdctl;
3088 u8 reg_idx = ring->reg_idx;
3089
3090 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3091 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3092
3093 /* write value back with RXDCTL.ENABLE bit cleared */
3094 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3095
3096 if (hw->mac.type == ixgbe_mac_82598EB &&
3097 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3098 return;
3099
3100 /* the hardware may take up to 100us to really disable the rx queue */
3101 do {
3102 udelay(10);
3103 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3104 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3105
3106 if (!wait_loop) {
3107 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3108 "the polling period\n", reg_idx);
3109 }
3110}
3111
Alexander Duyck84418e32010-08-19 13:40:54 +00003112void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3113 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003114{
3115 struct ixgbe_hw *hw = &adapter->hw;
3116 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003117 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003118 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003119
Alexander Duyck9e10e042010-08-19 13:40:06 +00003120 /* disable queue to avoid issues while updating state */
3121 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003122 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003123
Alexander Duyckacd37172010-08-19 13:36:05 +00003124 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3125 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3126 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3127 ring->count * sizeof(union ixgbe_adv_rx_desc));
3128 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3129 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003130 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003131
3132 ixgbe_configure_srrctl(adapter, ring);
3133 ixgbe_configure_rscctl(adapter, ring);
3134
Greg Rosee9f98072011-01-26 01:06:07 +00003135 /* If operating in IOV mode set RLPML for X540 */
3136 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3137 hw->mac.type == ixgbe_mac_X540) {
3138 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3139 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3140 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3141 }
3142
Alexander Duyck9e10e042010-08-19 13:40:06 +00003143 if (hw->mac.type == ixgbe_mac_82598EB) {
3144 /*
3145 * enable cache line friendly hardware writes:
3146 * PTHRESH=32 descriptors (half the internal cache),
3147 * this also removes ugly rx_no_buffer_count increment
3148 * HTHRESH=4 descriptors (to minimize latency on fetch)
3149 * WTHRESH=8 burst writeback up to two cache lines
3150 */
3151 rxdctl &= ~0x3FFFFF;
3152 rxdctl |= 0x080420;
3153 }
3154
3155 /* enable receive descriptor ring */
3156 rxdctl |= IXGBE_RXDCTL_ENABLE;
3157 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3158
3159 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003160 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003161}
3162
Alexander Duyck48654522010-08-19 13:36:27 +00003163static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3164{
3165 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003166 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003167 int p;
3168
3169 /* PSRTYPE must be initialized in non 82598 adapters */
3170 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003171 IXGBE_PSRTYPE_UDPHDR |
3172 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003173 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003174 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003175
3176 if (hw->mac.type == ixgbe_mac_82598EB)
3177 return;
3178
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003179 if (rss_i > 3)
3180 psrtype |= 2 << 29;
3181 else if (rss_i > 1)
3182 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003183
3184 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003185 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003186 psrtype);
3187}
3188
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003189static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3190{
3191 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003192 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003193 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003194 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003195
3196 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3197 return;
3198
3199 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003200 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3201 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003202 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003203 vmdctl |= IXGBE_VT_CTL_REPLEN;
3204 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003205
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003206 vf_shift = VMDQ_P(0) % 32;
3207 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003208
3209 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003210 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3211 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3212 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3213 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003214 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3215
3216 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003217 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003218
3219 /*
3220 * Set up VF register offsets for selected VT Mode,
3221 * i.e. 32 or 64 VFs for SR-IOV
3222 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003223 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3224 case IXGBE_82599_VMDQ_8Q_MASK:
3225 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3226 break;
3227 case IXGBE_82599_VMDQ_4Q_MASK:
3228 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3229 break;
3230 default:
3231 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3232 break;
3233 }
3234
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003235 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3236
3237 /* enable Tx loopback for VF/PF communication */
3238 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003239
Greg Rosea985b6c32010-11-18 03:02:52 +00003240 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003241 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003242 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003243 /* For VFs that have spoof checking turned off */
3244 for (i = 0; i < adapter->num_vfs; i++) {
3245 if (!adapter->vfinfo[i].spoofchk_enabled)
3246 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3247 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003248}
3249
Alexander Duyck477de6e2010-08-19 13:38:11 +00003250static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003251{
Auke Kok9a799d72007-09-15 14:07:45 -07003252 struct ixgbe_hw *hw = &adapter->hw;
3253 struct net_device *netdev = adapter->netdev;
3254 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003255 struct ixgbe_ring *rx_ring;
3256 int i;
3257 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003258
Alexander Duyck477de6e2010-08-19 13:38:11 +00003259#ifdef IXGBE_FCOE
3260 /* adjust max frame to be able to do baby jumbo for FCoE */
3261 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3262 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3263 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3264
3265#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003266
3267 /* adjust max frame to be at least the size of a standard frame */
3268 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3269 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3270
Alexander Duyck477de6e2010-08-19 13:38:11 +00003271 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3272 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3273 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3274 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3275
3276 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003277 }
3278
Alexander Duyck919e78a2011-08-26 09:52:38 +00003279 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3280 max_frame += VLAN_HLEN;
3281
Auke Kok9a799d72007-09-15 14:07:45 -07003282 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003283 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3284 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003285 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3286
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003287 /*
3288 * Setup the HW Rx Head and Tail Descriptor Pointers and
3289 * the Base and Length of the Rx Descriptor Ring
3290 */
Auke Kok9a799d72007-09-15 14:07:45 -07003291 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003292 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003293 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3294 set_ring_rsc_enabled(rx_ring);
3295 else
3296 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003297 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003298}
3299
Alexander Duyck73670962010-08-19 13:38:34 +00003300static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3301{
3302 struct ixgbe_hw *hw = &adapter->hw;
3303 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3304
3305 switch (hw->mac.type) {
3306 case ixgbe_mac_82598EB:
3307 /*
3308 * For VMDq support of different descriptor types or
3309 * buffer sizes through the use of multiple SRRCTL
3310 * registers, RDRXCTL.MVMEN must be set to 1
3311 *
3312 * also, the manual doesn't mention it clearly but DCA hints
3313 * will only use queue 0's tags unless this bit is set. Side
3314 * effects of setting this bit are only that SRRCTL must be
3315 * fully programmed [0..15]
3316 */
3317 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3318 break;
3319 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003320 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003321 /* Disable RSC for ACK packets */
3322 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3323 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3324 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3325 /* hardware requires some bits to be set by default */
3326 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3327 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3328 break;
3329 default:
3330 /* We should do nothing since we don't know this hardware */
3331 return;
3332 }
3333
3334 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3335}
3336
Alexander Duyck477de6e2010-08-19 13:38:11 +00003337/**
3338 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3339 * @adapter: board private structure
3340 *
3341 * Configure the Rx unit of the MAC after a reset.
3342 **/
3343static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3344{
3345 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003346 int i;
3347 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003348
3349 /* disable receives while setting up the descriptors */
3350 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3351 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3352
3353 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003354 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003355
Alexander Duyck9e10e042010-08-19 13:40:06 +00003356 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003357 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003358
Alexander Duyck477de6e2010-08-19 13:38:11 +00003359 /* set_rx_buffer_len must be called before ring initialization */
3360 ixgbe_set_rx_buffer_len(adapter);
3361
3362 /*
3363 * Setup the HW Rx Head and Tail Descriptor Pointers and
3364 * the Base and Length of the Rx Descriptor Ring
3365 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003366 for (i = 0; i < adapter->num_rx_queues; i++)
3367 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003368
Alexander Duyck9e10e042010-08-19 13:40:06 +00003369 /* disable drop enable for 82598 parts */
3370 if (hw->mac.type == ixgbe_mac_82598EB)
3371 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3372
3373 /* enable all receives */
3374 rxctrl |= IXGBE_RXCTRL_RXEN;
3375 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003376}
3377
Jiri Pirko8e586132011-12-08 19:52:37 -05003378static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003379{
3380 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003381 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003382
3383 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003384 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003385 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003386
3387 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003388}
3389
Jiri Pirko8e586132011-12-08 19:52:37 -05003390static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003391{
3392 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003393 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003394
Auke Kok9a799d72007-09-15 14:07:45 -07003395 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003396 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003397 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003398
3399 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003400}
3401
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003402/**
3403 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3404 * @adapter: driver data
3405 */
3406static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3407{
3408 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003409 u32 vlnctrl;
3410
3411 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3412 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3413 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3414}
3415
3416/**
3417 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3418 * @adapter: driver data
3419 */
3420static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3421{
3422 struct ixgbe_hw *hw = &adapter->hw;
3423 u32 vlnctrl;
3424
3425 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3426 vlnctrl |= IXGBE_VLNCTRL_VFE;
3427 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3428 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3429}
3430
3431/**
3432 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3433 * @adapter: driver data
3434 */
3435static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3436{
3437 struct ixgbe_hw *hw = &adapter->hw;
3438 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003439 int i, j;
3440
3441 switch (hw->mac.type) {
3442 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003443 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3444 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003445 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3446 break;
3447 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003448 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003449 for (i = 0; i < adapter->num_rx_queues; i++) {
3450 j = adapter->rx_ring[i]->reg_idx;
3451 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3452 vlnctrl &= ~IXGBE_RXDCTL_VME;
3453 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3454 }
3455 break;
3456 default:
3457 break;
3458 }
3459}
3460
3461/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003462 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003463 * @adapter: driver data
3464 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003465static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003466{
3467 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003468 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003469 int i, j;
3470
3471 switch (hw->mac.type) {
3472 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003473 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3474 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003475 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3476 break;
3477 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003478 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003479 for (i = 0; i < adapter->num_rx_queues; i++) {
3480 j = adapter->rx_ring[i]->reg_idx;
3481 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3482 vlnctrl |= IXGBE_RXDCTL_VME;
3483 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3484 }
3485 break;
3486 default:
3487 break;
3488 }
3489}
3490
Auke Kok9a799d72007-09-15 14:07:45 -07003491static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3492{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003493 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003494
Jesse Grossf62bbb52010-10-20 13:56:10 +00003495 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3496
3497 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3498 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003499}
3500
3501/**
Alexander Duyck28500622010-06-15 09:25:48 +00003502 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3503 * @netdev: network interface device structure
3504 *
3505 * Writes unicast address list to the RAR table.
3506 * Returns: -ENOMEM on failure/insufficient address space
3507 * 0 on no addresses written
3508 * X on writing X addresses to the RAR table
3509 **/
3510static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3511{
3512 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3513 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003514 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003515 int count = 0;
3516
John Fastabend95447462012-05-31 12:42:26 +00003517 /* In SR-IOV mode significantly less RAR entries are available */
3518 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3519 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3520
Alexander Duyck28500622010-06-15 09:25:48 +00003521 /* return ENOMEM indicating insufficient memory for addresses */
3522 if (netdev_uc_count(netdev) > rar_entries)
3523 return -ENOMEM;
3524
John Fastabend95447462012-05-31 12:42:26 +00003525 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003526 struct netdev_hw_addr *ha;
3527 /* return error if we do not support writing to RAR table */
3528 if (!hw->mac.ops.set_rar)
3529 return -ENOMEM;
3530
3531 netdev_for_each_uc_addr(ha, netdev) {
3532 if (!rar_entries)
3533 break;
3534 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003535 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003536 count++;
3537 }
3538 }
3539 /* write the addresses in reverse order to avoid write combining */
3540 for (; rar_entries > 0 ; rar_entries--)
3541 hw->mac.ops.clear_rar(hw, rar_entries);
3542
3543 return count;
3544}
3545
3546/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003547 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003548 * @netdev: network interface device structure
3549 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003550 * The set_rx_method entry point is called whenever the unicast/multicast
3551 * address list or the network interface flags are updated. This routine is
3552 * responsible for configuring the hardware for proper unicast, multicast and
3553 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003554 **/
Greg Rose7f870472010-01-09 02:25:29 +00003555void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003556{
3557 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3558 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003559 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3560 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003561
3562 /* Check for Promiscuous and All Multicast modes */
3563
3564 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3565
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003566 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003567 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003568 fctrl |= IXGBE_FCTRL_BAM;
3569 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3570 fctrl |= IXGBE_FCTRL_PMCF;
3571
Alexander Duyck28500622010-06-15 09:25:48 +00003572 /* clear the bits we are changing the status of */
3573 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3574
Auke Kok9a799d72007-09-15 14:07:45 -07003575 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003576 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003577 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003578 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003579 /* don't hardware filter vlans in promisc mode */
3580 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003581 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003582 if (netdev->flags & IFF_ALLMULTI) {
3583 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003584 vmolr |= IXGBE_VMOLR_MPE;
3585 } else {
3586 /*
3587 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003588 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003589 * that we can at least receive multicast traffic
3590 */
3591 hw->mac.ops.update_mc_addr_list(hw, netdev);
3592 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003593 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003594 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003595 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003596 }
3597
3598 /*
3599 * Write addresses to available RAR registers, if there is not
3600 * sufficient space to store all the addresses then enable
3601 * unicast promiscuous mode
3602 */
3603 count = ixgbe_write_uc_addr_list(netdev);
3604 if (count < 0) {
3605 fctrl |= IXGBE_FCTRL_UPE;
3606 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003607 }
3608
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003609 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003610 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003611
3612 if (hw->mac.type != ixgbe_mac_82598EB) {
3613 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003614 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3615 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003616 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003617 }
3618
Ben Greear3f2d1c02012-03-08 08:28:41 +00003619 /* This is useful for sniffing bad packets. */
3620 if (adapter->netdev->features & NETIF_F_RXALL) {
3621 /* UPE and MPE will be handled by normal PROMISC logic
3622 * in e1000e_set_rx_mode */
3623 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3624 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3625 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3626
3627 fctrl &= ~(IXGBE_FCTRL_DPF);
3628 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3629 }
3630
Auke Kok9a799d72007-09-15 14:07:45 -07003631 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003632
3633 if (netdev->features & NETIF_F_HW_VLAN_RX)
3634 ixgbe_vlan_strip_enable(adapter);
3635 else
3636 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003637}
3638
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003639static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3640{
3641 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003642
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003643 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3644 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003645}
3646
3647static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3648{
3649 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003650
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003651 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3652 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003653}
3654
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003655#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003656/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003657 * ixgbe_configure_dcb - Configure DCB hardware
3658 * @adapter: ixgbe adapter struct
3659 *
3660 * This is called by the driver on open to configure the DCB hardware.
3661 * This is also called by the gennetlink interface when reconfiguring
3662 * the DCB state.
3663 */
3664static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3665{
3666 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003667 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003668
Alexander Duyck67ebd792010-08-19 13:34:04 +00003669 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3670 if (hw->mac.type == ixgbe_mac_82598EB)
3671 netif_set_gso_max_size(adapter->netdev, 65536);
3672 return;
3673 }
3674
3675 if (hw->mac.type == ixgbe_mac_82598EB)
3676 netif_set_gso_max_size(adapter->netdev, 32768);
3677
John Fastabendb1208182011-10-15 05:00:10 +00003678#ifdef IXGBE_FCOE
3679 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3680 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3681#endif
3682
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003683 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003684 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003685 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3686 DCB_TX_CONFIG);
3687 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3688 DCB_RX_CONFIG);
3689 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003690 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3691 ixgbe_dcb_hw_ets(&adapter->hw,
3692 adapter->ixgbe_ieee_ets,
3693 max_frame);
3694 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3695 adapter->ixgbe_ieee_pfc->pfc_en,
3696 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003697 }
John Fastabend8187cd42011-02-23 05:58:08 +00003698
3699 /* Enable RSS Hash per TC */
3700 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003701 u32 msb = 0;
3702 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003703
Alexander Duyckd411a932012-06-30 00:14:01 +00003704 while (rss_i) {
3705 msb++;
3706 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003707 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003708
Alexander Duyck4ae63732012-06-22 06:46:33 +00003709 /* write msb to all 8 TCs in one write */
3710 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003711 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003712}
John Fastabend9da712d2011-08-23 03:14:22 +00003713#endif
3714
3715/* Additional bittime to account for IXGBE framing */
3716#define IXGBE_ETH_FRAMING 20
3717
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003718/**
John Fastabend9da712d2011-08-23 03:14:22 +00003719 * ixgbe_hpbthresh - calculate high water mark for flow control
3720 *
3721 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003722 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003723 */
3724static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3725{
3726 struct ixgbe_hw *hw = &adapter->hw;
3727 struct net_device *dev = adapter->netdev;
3728 int link, tc, kb, marker;
3729 u32 dv_id, rx_pba;
3730
3731 /* Calculate max LAN frame size */
3732 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3733
3734#ifdef IXGBE_FCOE
3735 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003736 if ((dev->features & NETIF_F_FCOE_MTU) &&
3737 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3738 (pb == ixgbe_fcoe_get_tc(adapter)))
3739 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003740
3741#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003742 /* Calculate delay value for device */
3743 switch (hw->mac.type) {
3744 case ixgbe_mac_X540:
3745 dv_id = IXGBE_DV_X540(link, tc);
3746 break;
3747 default:
3748 dv_id = IXGBE_DV(link, tc);
3749 break;
3750 }
3751
3752 /* Loopback switch introduces additional latency */
3753 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3754 dv_id += IXGBE_B2BT(tc);
3755
3756 /* Delay value is calculated in bit times convert to KB */
3757 kb = IXGBE_BT2KB(dv_id);
3758 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3759
3760 marker = rx_pba - kb;
3761
3762 /* It is possible that the packet buffer is not large enough
3763 * to provide required headroom. In this case throw an error
3764 * to user and a do the best we can.
3765 */
3766 if (marker < 0) {
3767 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3768 "headroom to support flow control."
3769 "Decrease MTU or number of traffic classes\n", pb);
3770 marker = tc + 1;
3771 }
3772
3773 return marker;
3774}
3775
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003776/**
John Fastabend9da712d2011-08-23 03:14:22 +00003777 * ixgbe_lpbthresh - calculate low water mark for for flow control
3778 *
3779 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003780 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003781 */
3782static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3783{
3784 struct ixgbe_hw *hw = &adapter->hw;
3785 struct net_device *dev = adapter->netdev;
3786 int tc;
3787 u32 dv_id;
3788
3789 /* Calculate max LAN frame size */
3790 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3791
3792 /* Calculate delay value for device */
3793 switch (hw->mac.type) {
3794 case ixgbe_mac_X540:
3795 dv_id = IXGBE_LOW_DV_X540(tc);
3796 break;
3797 default:
3798 dv_id = IXGBE_LOW_DV(tc);
3799 break;
3800 }
3801
3802 /* Delay value is calculated in bit times convert to KB */
3803 return IXGBE_BT2KB(dv_id);
3804}
3805
3806/*
3807 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3808 */
3809static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3810{
3811 struct ixgbe_hw *hw = &adapter->hw;
3812 int num_tc = netdev_get_num_tc(adapter->netdev);
3813 int i;
3814
3815 if (!num_tc)
3816 num_tc = 1;
3817
3818 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3819
3820 for (i = 0; i < num_tc; i++) {
3821 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3822
3823 /* Low water marks must not be larger than high water marks */
3824 if (hw->fc.low_water > hw->fc.high_water[i])
3825 hw->fc.low_water = 0;
3826 }
3827}
John Fastabend80605c652011-05-02 12:34:10 +00003828
3829static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3830{
John Fastabend80605c652011-05-02 12:34:10 +00003831 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003832 int hdrm;
3833 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003834
3835 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3836 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003837 hdrm = 32 << adapter->fdir_pballoc;
3838 else
3839 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003840
Alexander Duyckf7e10272011-07-21 00:40:35 +00003841 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003842 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003843}
3844
Alexander Duycke4911d52011-05-11 07:18:52 +00003845static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3846{
3847 struct ixgbe_hw *hw = &adapter->hw;
3848 struct hlist_node *node, *node2;
3849 struct ixgbe_fdir_filter *filter;
3850
3851 spin_lock(&adapter->fdir_perfect_lock);
3852
3853 if (!hlist_empty(&adapter->fdir_filter_list))
3854 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3855
3856 hlist_for_each_entry_safe(filter, node, node2,
3857 &adapter->fdir_filter_list, fdir_node) {
3858 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003859 &filter->filter,
3860 filter->sw_idx,
3861 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3862 IXGBE_FDIR_DROP_QUEUE :
3863 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003864 }
3865
3866 spin_unlock(&adapter->fdir_perfect_lock);
3867}
3868
Auke Kok9a799d72007-09-15 14:07:45 -07003869static void ixgbe_configure(struct ixgbe_adapter *adapter)
3870{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003871 struct ixgbe_hw *hw = &adapter->hw;
3872
John Fastabend80605c652011-05-02 12:34:10 +00003873 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003874#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003875 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003876#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00003877 /*
3878 * We must restore virtualization before VLANs or else
3879 * the VLVF registers will not be populated
3880 */
3881 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003882
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003883 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003884 ixgbe_restore_vlan(adapter);
3885
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003886 switch (hw->mac.type) {
3887 case ixgbe_mac_82599EB:
3888 case ixgbe_mac_X540:
3889 hw->mac.ops.disable_rx_buff(hw);
3890 break;
3891 default:
3892 break;
3893 }
3894
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003895 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003896 ixgbe_init_fdir_signature_82599(&adapter->hw,
3897 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003898 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3899 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3900 adapter->fdir_pballoc);
3901 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003902 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003903
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003904 switch (hw->mac.type) {
3905 case ixgbe_mac_82599EB:
3906 case ixgbe_mac_X540:
3907 hw->mac.ops.enable_rx_buff(hw);
3908 break;
3909 default:
3910 break;
3911 }
3912
Alexander Duyck7c8ae652012-05-05 05:32:47 +00003913#ifdef IXGBE_FCOE
3914 /* configure FCoE L2 filters, redirection table, and Rx control */
3915 ixgbe_configure_fcoe(adapter);
3916
3917#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07003918 ixgbe_configure_tx(adapter);
3919 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003920}
3921
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003922static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3923{
3924 switch (hw->phy.type) {
3925 case ixgbe_phy_sfp_avago:
3926 case ixgbe_phy_sfp_ftl:
3927 case ixgbe_phy_sfp_intel:
3928 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003929 case ixgbe_phy_sfp_passive_tyco:
3930 case ixgbe_phy_sfp_passive_unknown:
3931 case ixgbe_phy_sfp_active_unknown:
3932 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003933 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003934 case ixgbe_phy_nl:
3935 if (hw->mac.type == ixgbe_mac_82598EB)
3936 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003937 default:
3938 return false;
3939 }
3940}
3941
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003942/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003943 * ixgbe_sfp_link_config - set up SFP+ link
3944 * @adapter: pointer to private adapter struct
3945 **/
3946static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3947{
Alexander Duyck70864002011-04-27 09:13:56 +00003948 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003949 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003950 * is that an SFP was inserted/removed after the reset
3951 * but before SFP detection was enabled. As such the best
3952 * solution is to just start searching as soon as we start
3953 */
3954 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3955 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003956
Alexander Duyck70864002011-04-27 09:13:56 +00003957 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003958}
3959
3960/**
3961 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003962 * @hw: pointer to private hardware struct
3963 *
3964 * Returns 0 on success, negative on failure
3965 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003966static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003967{
3968 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003969 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003970 u32 ret = IXGBE_ERR_LINK_SETUP;
3971
3972 if (hw->mac.ops.check_link)
3973 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3974
3975 if (ret)
3976 goto link_cfg_out;
3977
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003978 autoneg = hw->phy.autoneg_advertised;
3979 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003980 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3981 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003982 if (ret)
3983 goto link_cfg_out;
3984
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003985 if (hw->mac.ops.setup_link)
3986 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003987link_cfg_out:
3988 return ret;
3989}
3990
Alexander Duycka34bcff2010-08-19 13:39:20 +00003991static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003992{
Auke Kok9a799d72007-09-15 14:07:45 -07003993 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003994 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003995
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003996 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003997 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3998 IXGBE_GPIE_OCD;
3999 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004000 /*
4001 * use EIAM to auto-mask when MSI-X interrupt is asserted
4002 * this saves a register write for every interrupt
4003 */
4004 switch (hw->mac.type) {
4005 case ixgbe_mac_82598EB:
4006 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4007 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004008 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004009 case ixgbe_mac_X540:
4010 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004011 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4012 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4013 break;
4014 }
4015 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004016 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4017 * specifically only auto mask tx and rx interrupts */
4018 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004019 }
4020
Alexander Duycka34bcff2010-08-19 13:39:20 +00004021 /* XXX: to interrupt immediately for EICS writes, enable this */
4022 /* gpie |= IXGBE_GPIE_EIMEN; */
4023
4024 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4025 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004026
4027 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4028 case IXGBE_82599_VMDQ_8Q_MASK:
4029 gpie |= IXGBE_GPIE_VTMODE_16;
4030 break;
4031 case IXGBE_82599_VMDQ_4Q_MASK:
4032 gpie |= IXGBE_GPIE_VTMODE_32;
4033 break;
4034 default:
4035 gpie |= IXGBE_GPIE_VTMODE_64;
4036 break;
4037 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004038 }
4039
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004040 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004041 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4042 switch (adapter->hw.mac.type) {
4043 case ixgbe_mac_82599EB:
4044 gpie |= IXGBE_SDP0_GPIEN;
4045 break;
4046 case ixgbe_mac_X540:
4047 gpie |= IXGBE_EIMS_TS;
4048 break;
4049 default:
4050 break;
4051 }
4052 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004053
Alexander Duycka34bcff2010-08-19 13:39:20 +00004054 /* Enable fan failure interrupt */
4055 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004056 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004057
Don Skidmore2698b202011-04-13 07:01:52 +00004058 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004059 gpie |= IXGBE_SDP1_GPIEN;
4060 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004061 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004062
4063 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4064}
4065
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004066static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004067{
4068 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004069 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004070 u32 ctrl_ext;
4071
4072 ixgbe_get_hw_control(adapter);
4073 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004074
Auke Kok9a799d72007-09-15 14:07:45 -07004075 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4076 ixgbe_configure_msix(adapter);
4077 else
4078 ixgbe_configure_msi_and_legacy(adapter);
4079
Don Skidmorec6ecf392010-12-03 03:31:51 +00004080 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
4081 if (hw->mac.ops.enable_tx_laser &&
4082 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004083 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004084 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004085 hw->mac.ops.enable_tx_laser(hw);
4086
Auke Kok9a799d72007-09-15 14:07:45 -07004087 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004088 ixgbe_napi_enable_all(adapter);
4089
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004090 if (ixgbe_is_sfp(hw)) {
4091 ixgbe_sfp_link_config(adapter);
4092 } else {
4093 err = ixgbe_non_sfp_link_config(hw);
4094 if (err)
4095 e_err(probe, "link_config FAILED %d\n", err);
4096 }
4097
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004098 /* clear any pending interrupts, may auto mask */
4099 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004100 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004101
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004102 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004103 * If this adapter has a fan, check to see if we had a failure
4104 * before we enabled the interrupt.
4105 */
4106 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4107 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4108 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004109 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004110 }
4111
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004112 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004113 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004114
Auke Kok9a799d72007-09-15 14:07:45 -07004115 /* bring the link up in the watchdog, this could race with our first
4116 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004117 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4118 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004119 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004120
4121 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4122 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4123 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4124 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004125}
4126
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004127void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4128{
4129 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004130 /* put off any impending NetWatchDogTimeout */
4131 adapter->netdev->trans_start = jiffies;
4132
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004133 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004134 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004135 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004136 /*
4137 * If SR-IOV enabled then wait a bit before bringing the adapter
4138 * back up to give the VFs time to respond to the reset. The
4139 * two second wait is based upon the watchdog timer cycle in
4140 * the VF driver.
4141 */
4142 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4143 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004144 ixgbe_up(adapter);
4145 clear_bit(__IXGBE_RESETTING, &adapter->state);
4146}
4147
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004148void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004149{
4150 /* hardware has been reset, we need to reload some things */
4151 ixgbe_configure(adapter);
4152
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004153 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004154}
4155
4156void ixgbe_reset(struct ixgbe_adapter *adapter)
4157{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004158 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004159 int err;
4160
Alexander Duyck70864002011-04-27 09:13:56 +00004161 /* lock SFP init bit to prevent race conditions with the watchdog */
4162 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4163 usleep_range(1000, 2000);
4164
4165 /* clear all SFP and link config related flags while holding SFP_INIT */
4166 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4167 IXGBE_FLAG2_SFP_NEEDS_RESET);
4168 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4169
Don Skidmore8ca783a2009-05-26 20:40:47 -07004170 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004171 switch (err) {
4172 case 0:
4173 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004174 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004175 break;
4176 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004177 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004178 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004179 case IXGBE_ERR_EEPROM_VERSION:
4180 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004181 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004182 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004183 "your hardware. If you are experiencing problems "
4184 "please contact your Intel or hardware "
4185 "representative who provided you with this "
4186 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004187 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004188 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004189 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004190 }
Auke Kok9a799d72007-09-15 14:07:45 -07004191
Alexander Duyck70864002011-04-27 09:13:56 +00004192 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4193
Auke Kok9a799d72007-09-15 14:07:45 -07004194 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004195 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004196
4197 /* update SAN MAC vmdq pool selection */
4198 if (hw->mac.san_mac_rar_index)
4199 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Auke Kok9a799d72007-09-15 14:07:45 -07004200}
4201
Auke Kok9a799d72007-09-15 14:07:45 -07004202/**
4203 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004204 * @rx_ring: ring to free buffers from
4205 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004206static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004207{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004208 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004209 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004210 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004211
Alexander Duyck84418e32010-08-19 13:40:54 +00004212 /* ring already cleared, nothing to do */
4213 if (!rx_ring->rx_buffer_info)
4214 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004215
Alexander Duyck84418e32010-08-19 13:40:54 +00004216 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004217 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004218 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004219
Alexander Duyckf8003262012-03-03 02:35:52 +00004220 rx_buffer = &rx_ring->rx_buffer_info[i];
4221 if (rx_buffer->skb) {
4222 struct sk_buff *skb = rx_buffer->skb;
4223 if (IXGBE_CB(skb)->page_released) {
4224 dma_unmap_page(dev,
4225 IXGBE_CB(skb)->dma,
4226 ixgbe_rx_bufsz(rx_ring),
4227 DMA_FROM_DEVICE);
4228 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004229 }
4230 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004231 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004232 rx_buffer->skb = NULL;
4233 if (rx_buffer->dma)
4234 dma_unmap_page(dev, rx_buffer->dma,
4235 ixgbe_rx_pg_size(rx_ring),
4236 DMA_FROM_DEVICE);
4237 rx_buffer->dma = 0;
4238 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004239 __free_pages(rx_buffer->page,
4240 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004241 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004242 }
4243
4244 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4245 memset(rx_ring->rx_buffer_info, 0, size);
4246
4247 /* Zero out the descriptor ring */
4248 memset(rx_ring->desc, 0, rx_ring->size);
4249
Alexander Duyckf8003262012-03-03 02:35:52 +00004250 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004251 rx_ring->next_to_clean = 0;
4252 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004253}
4254
4255/**
4256 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004257 * @tx_ring: ring to be cleaned
4258 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004259static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004260{
4261 struct ixgbe_tx_buffer *tx_buffer_info;
4262 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004263 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004264
Alexander Duyck84418e32010-08-19 13:40:54 +00004265 /* ring already cleared, nothing to do */
4266 if (!tx_ring->tx_buffer_info)
4267 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004268
Alexander Duyck84418e32010-08-19 13:40:54 +00004269 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004270 for (i = 0; i < tx_ring->count; i++) {
4271 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004272 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004273 }
4274
John Fastabenddad8a3b2012-04-23 12:22:39 +00004275 netdev_tx_reset_queue(txring_txq(tx_ring));
4276
Auke Kok9a799d72007-09-15 14:07:45 -07004277 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4278 memset(tx_ring->tx_buffer_info, 0, size);
4279
4280 /* Zero out the descriptor ring */
4281 memset(tx_ring->desc, 0, tx_ring->size);
4282
4283 tx_ring->next_to_use = 0;
4284 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004285}
4286
4287/**
Auke Kok9a799d72007-09-15 14:07:45 -07004288 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4289 * @adapter: board private structure
4290 **/
4291static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4292{
4293 int i;
4294
4295 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004296 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004297}
4298
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004299/**
4300 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4301 * @adapter: board private structure
4302 **/
4303static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4304{
4305 int i;
4306
4307 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004308 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004309}
4310
Alexander Duycke4911d52011-05-11 07:18:52 +00004311static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4312{
4313 struct hlist_node *node, *node2;
4314 struct ixgbe_fdir_filter *filter;
4315
4316 spin_lock(&adapter->fdir_perfect_lock);
4317
4318 hlist_for_each_entry_safe(filter, node, node2,
4319 &adapter->fdir_filter_list, fdir_node) {
4320 hlist_del(&filter->fdir_node);
4321 kfree(filter);
4322 }
4323 adapter->fdir_filter_count = 0;
4324
4325 spin_unlock(&adapter->fdir_perfect_lock);
4326}
4327
Auke Kok9a799d72007-09-15 14:07:45 -07004328void ixgbe_down(struct ixgbe_adapter *adapter)
4329{
4330 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004331 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004332 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004333 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004334
4335 /* signal that we are down to the interrupt handler */
4336 set_bit(__IXGBE_DOWN, &adapter->state);
4337
4338 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004339 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4340 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004341
Yi Zou2d39d572011-01-06 14:29:56 +00004342 /* disable all enabled rx queues */
4343 for (i = 0; i < adapter->num_rx_queues; i++)
4344 /* this call also flushes the previous write */
4345 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4346
Don Skidmore032b4322011-03-18 09:32:53 +00004347 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004348
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004349 netif_tx_stop_all_queues(netdev);
4350
Alexander Duyck70864002011-04-27 09:13:56 +00004351 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004352 netif_carrier_off(netdev);
4353 netif_tx_disable(netdev);
4354
4355 ixgbe_irq_disable(adapter);
4356
4357 ixgbe_napi_disable_all(adapter);
4358
Alexander Duyckd034acf2011-04-27 09:25:34 +00004359 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4360 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004361 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4362
4363 del_timer_sync(&adapter->service_timer);
4364
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004365 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004366 /* Clear EITR Select mapping */
4367 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4368
4369 /* Mark all the VFs as inactive */
4370 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004371 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004372
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004373 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004374 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004375
Auke Kok9a799d72007-09-15 14:07:45 -07004376 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004377 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004378 }
4379
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004380 /* disable transmits in the hardware now that interrupts are off */
4381 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004382 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004383 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004384 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004385
4386 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004387 switch (hw->mac.type) {
4388 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004389 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004390 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004391 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4392 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004393 break;
4394 default:
4395 break;
4396 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004397
Paul Larson6f4a0e42008-06-24 17:00:56 -07004398 if (!pci_channel_offline(adapter->pdev))
4399 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004400
4401 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4402 if (hw->mac.ops.disable_tx_laser &&
4403 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004404 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004405 (hw->mac.type == ixgbe_mac_82599EB))))
4406 hw->mac.ops.disable_tx_laser(hw);
4407
Auke Kok9a799d72007-09-15 14:07:45 -07004408 ixgbe_clean_all_tx_rings(adapter);
4409 ixgbe_clean_all_rx_rings(adapter);
4410
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004411#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004412 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004413 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004414#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004415}
4416
Auke Kok9a799d72007-09-15 14:07:45 -07004417/**
Auke Kok9a799d72007-09-15 14:07:45 -07004418 * ixgbe_tx_timeout - Respond to a Tx Hang
4419 * @netdev: network interface device structure
4420 **/
4421static void ixgbe_tx_timeout(struct net_device *netdev)
4422{
4423 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4424
4425 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004426 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004427}
4428
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004429/**
Auke Kok9a799d72007-09-15 14:07:45 -07004430 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4431 * @adapter: board private structure to initialize
4432 *
4433 * ixgbe_sw_init initializes the Adapter private data structure.
4434 * Fields are initialized based on PCI device information and
4435 * OS network device settings (MTU size).
4436 **/
4437static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4438{
4439 struct ixgbe_hw *hw = &adapter->hw;
4440 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004441 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004442#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004443 int j;
4444 struct tc_configuration *tc;
4445#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004446
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004447 /* PCI config space info */
4448
4449 hw->vendor_id = pdev->vendor;
4450 hw->device_id = pdev->device;
4451 hw->revision_id = pdev->revision;
4452 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4453 hw->subsystem_device_id = pdev->subsystem_device;
4454
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004455 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004456 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004457 adapter->ring_feature[RING_F_RSS].limit = rss;
Alexander Duyckbd508172010-11-16 19:27:03 -08004458 switch (hw->mac.type) {
4459 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004460 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4461 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004462 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004463 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004464 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004465 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4466 case ixgbe_mac_82599EB:
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004467 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004468 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4469 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004470 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4471 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004472 /* Flow Director hash filters enabled */
Alexander Duyck45b9f502011-01-06 14:29:59 +00004473 adapter->atr_sample_rate = 20;
Alexander Duyckc0876632012-05-10 00:01:46 +00004474 adapter->ring_feature[RING_F_FDIR].limit =
Joe Perchese8e9f692010-09-07 21:34:53 +00004475 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004476 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004477#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004478 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4479 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
Yi Zou61a0f422009-12-03 11:32:22 +00004480#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004481 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004482 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004483#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004484#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004485 break;
4486 default:
4487 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004488 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004489
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004490#ifdef IXGBE_FCOE
4491 /* FCoE support exists, always init the FCoE lock */
4492 spin_lock_init(&adapter->fcoe.lock);
4493
4494#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004495 /* n-tuple support exists, always init our spinlock */
4496 spin_lock_init(&adapter->fdir_perfect_lock);
4497
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004498#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004499 switch (hw->mac.type) {
4500 case ixgbe_mac_X540:
4501 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4502 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4503 break;
4504 default:
4505 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4506 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4507 break;
4508 }
4509
Alexander Duyck2f90b862008-11-20 20:52:10 -08004510 /* Configure DCB traffic classes */
4511 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4512 tc = &adapter->dcb_cfg.tc_config[j];
4513 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4514 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4515 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4516 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4517 tc->dcb_pfc = pfc_disabled;
4518 }
John Fastabend4de2a022011-09-27 03:52:01 +00004519
4520 /* Initialize default user to priority mapping, UPx->TC0 */
4521 tc = &adapter->dcb_cfg.tc_config[0];
4522 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4523 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4524
Alexander Duyck2f90b862008-11-20 20:52:10 -08004525 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4526 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004527 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004528 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004529 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004530 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4531 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004532
4533#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004534
4535 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004536 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004537 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004538 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004539 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4540 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004541 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004542
Alexander Duyck99d74482012-05-09 08:09:25 +00004543#ifdef CONFIG_PCI_IOV
4544 /* assign number of SR-IOV VFs */
4545 if (hw->mac.type != ixgbe_mac_82598EB)
4546 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4547
4548#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004549 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004550 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004551 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004552
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004553 /* set default ring sizes */
4554 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4555 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4556
Alexander Duyckbd198052011-06-11 01:45:08 +00004557 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004558 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004559
Auke Kok9a799d72007-09-15 14:07:45 -07004560 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004561 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004562 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004563 return -EIO;
4564 }
4565
Auke Kok9a799d72007-09-15 14:07:45 -07004566 set_bit(__IXGBE_DOWN, &adapter->state);
4567
4568 return 0;
4569}
4570
4571/**
4572 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004573 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004574 *
4575 * Return 0 on success, negative on failure
4576 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004577int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004578{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004579 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004580 int orig_node = dev_to_node(dev);
4581 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004582 int size;
4583
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004584 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004585
4586 if (tx_ring->q_vector)
4587 numa_node = tx_ring->q_vector->numa_node;
4588
4589 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004590 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004591 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004592 if (!tx_ring->tx_buffer_info)
4593 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004594
4595 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004596 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004597 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004598
Alexander Duyckde88eee2012-02-08 07:49:59 +00004599 set_dev_node(dev, numa_node);
4600 tx_ring->desc = dma_alloc_coherent(dev,
4601 tx_ring->size,
4602 &tx_ring->dma,
4603 GFP_KERNEL);
4604 set_dev_node(dev, orig_node);
4605 if (!tx_ring->desc)
4606 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4607 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004608 if (!tx_ring->desc)
4609 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004610
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004611 tx_ring->next_to_use = 0;
4612 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004613 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004614
4615err:
4616 vfree(tx_ring->tx_buffer_info);
4617 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004618 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004619 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004620}
4621
4622/**
Alexander Duyck69888672008-09-11 20:05:39 -07004623 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4624 * @adapter: board private structure
4625 *
4626 * If this function returns with an error, then it's possible one or
4627 * more of the rings is populated (while the rest are not). It is the
4628 * callers duty to clean those orphaned rings.
4629 *
4630 * Return 0 on success, negative on failure
4631 **/
4632static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4633{
4634 int i, err = 0;
4635
4636 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004637 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004638 if (!err)
4639 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004640
Emil Tantilov396e7992010-07-01 20:05:12 +00004641 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004642 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004643 }
4644
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004645 return 0;
4646err_setup_tx:
4647 /* rewind the index freeing the rings as we go */
4648 while (i--)
4649 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004650 return err;
4651}
4652
4653/**
Auke Kok9a799d72007-09-15 14:07:45 -07004654 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004655 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004656 *
4657 * Returns 0 on success, negative on failure
4658 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004659int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004660{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004661 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004662 int orig_node = dev_to_node(dev);
4663 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004664 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004665
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004666 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004667
4668 if (rx_ring->q_vector)
4669 numa_node = rx_ring->q_vector->numa_node;
4670
4671 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004672 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004673 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004674 if (!rx_ring->rx_buffer_info)
4675 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004676
Auke Kok9a799d72007-09-15 14:07:45 -07004677 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004678 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4679 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004680
Alexander Duyckde88eee2012-02-08 07:49:59 +00004681 set_dev_node(dev, numa_node);
4682 rx_ring->desc = dma_alloc_coherent(dev,
4683 rx_ring->size,
4684 &rx_ring->dma,
4685 GFP_KERNEL);
4686 set_dev_node(dev, orig_node);
4687 if (!rx_ring->desc)
4688 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4689 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004690 if (!rx_ring->desc)
4691 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004692
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004693 rx_ring->next_to_clean = 0;
4694 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004695
4696 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004697err:
4698 vfree(rx_ring->rx_buffer_info);
4699 rx_ring->rx_buffer_info = NULL;
4700 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004701 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004702}
4703
4704/**
Alexander Duyck69888672008-09-11 20:05:39 -07004705 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4706 * @adapter: board private structure
4707 *
4708 * If this function returns with an error, then it's possible one or
4709 * more of the rings is populated (while the rest are not). It is the
4710 * callers duty to clean those orphaned rings.
4711 *
4712 * Return 0 on success, negative on failure
4713 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004714static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4715{
4716 int i, err = 0;
4717
4718 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004719 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004720 if (!err)
4721 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004722
Emil Tantilov396e7992010-07-01 20:05:12 +00004723 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004724 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004725 }
4726
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004727#ifdef IXGBE_FCOE
4728 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4729 if (!err)
4730#endif
4731 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004732err_setup_rx:
4733 /* rewind the index freeing the rings as we go */
4734 while (i--)
4735 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004736 return err;
4737}
4738
4739/**
Auke Kok9a799d72007-09-15 14:07:45 -07004740 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004741 * @tx_ring: Tx descriptor ring for a specific queue
4742 *
4743 * Free all transmit software resources
4744 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004745void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004746{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004747 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004748
4749 vfree(tx_ring->tx_buffer_info);
4750 tx_ring->tx_buffer_info = NULL;
4751
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004752 /* if not set, then don't free */
4753 if (!tx_ring->desc)
4754 return;
4755
4756 dma_free_coherent(tx_ring->dev, tx_ring->size,
4757 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004758
4759 tx_ring->desc = NULL;
4760}
4761
4762/**
4763 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4764 * @adapter: board private structure
4765 *
4766 * Free all transmit software resources
4767 **/
4768static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4769{
4770 int i;
4771
4772 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004773 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004774 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004775}
4776
4777/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004778 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004779 * @rx_ring: ring to clean the resources from
4780 *
4781 * Free all receive software resources
4782 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004783void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004784{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004785 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004786
4787 vfree(rx_ring->rx_buffer_info);
4788 rx_ring->rx_buffer_info = NULL;
4789
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004790 /* if not set, then don't free */
4791 if (!rx_ring->desc)
4792 return;
4793
4794 dma_free_coherent(rx_ring->dev, rx_ring->size,
4795 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004796
4797 rx_ring->desc = NULL;
4798}
4799
4800/**
4801 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4802 * @adapter: board private structure
4803 *
4804 * Free all receive software resources
4805 **/
4806static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4807{
4808 int i;
4809
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004810#ifdef IXGBE_FCOE
4811 ixgbe_free_fcoe_ddp_resources(adapter);
4812
4813#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004814 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004815 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004816 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004817}
4818
4819/**
Auke Kok9a799d72007-09-15 14:07:45 -07004820 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4821 * @netdev: network interface device structure
4822 * @new_mtu: new value for maximum frame size
4823 *
4824 * Returns 0 on success, negative on failure
4825 **/
4826static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4827{
4828 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4829 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4830
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004831 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004832 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4833 return -EINVAL;
4834
4835 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00004836 * For 82599EB we cannot allow legacy VFs to enable their receive
4837 * paths when MTU greater than 1500 is configured. So display a
4838 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00004839 */
4840 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4841 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4842 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Alexander Duyck872844d2012-08-15 02:10:43 +00004843 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004844
Emil Tantilov396e7992010-07-01 20:05:12 +00004845 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004846
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004847 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004848 netdev->mtu = new_mtu;
4849
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004850 if (netif_running(netdev))
4851 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004852
4853 return 0;
4854}
4855
4856/**
4857 * ixgbe_open - Called when a network interface is made active
4858 * @netdev: network interface device structure
4859 *
4860 * Returns 0 on success, negative value on failure
4861 *
4862 * The open entry point is called when a network interface is made
4863 * active by the system (IFF_UP). At this point all resources needed
4864 * for transmit and receive operations are allocated, the interrupt
4865 * handler is registered with the OS, the watchdog timer is started,
4866 * and the stack is notified that the interface is ready.
4867 **/
4868static int ixgbe_open(struct net_device *netdev)
4869{
4870 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4871 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004872
Auke Kok4bebfaa2008-02-11 09:26:01 -08004873 /* disallow open during test */
4874 if (test_bit(__IXGBE_TESTING, &adapter->state))
4875 return -EBUSY;
4876
Jesse Brandeburg54386462009-04-17 20:44:27 +00004877 netif_carrier_off(netdev);
4878
Auke Kok9a799d72007-09-15 14:07:45 -07004879 /* allocate transmit descriptors */
4880 err = ixgbe_setup_all_tx_resources(adapter);
4881 if (err)
4882 goto err_setup_tx;
4883
Auke Kok9a799d72007-09-15 14:07:45 -07004884 /* allocate receive descriptors */
4885 err = ixgbe_setup_all_rx_resources(adapter);
4886 if (err)
4887 goto err_setup_rx;
4888
4889 ixgbe_configure(adapter);
4890
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004891 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004892 if (err)
4893 goto err_req_irq;
4894
Alexander Duyckac802f52012-07-12 05:52:53 +00004895 /* Notify the stack of the actual queue counts. */
4896 err = netif_set_real_num_tx_queues(netdev,
4897 adapter->num_rx_pools > 1 ? 1 :
4898 adapter->num_tx_queues);
4899 if (err)
4900 goto err_set_queues;
4901
4902
4903 err = netif_set_real_num_rx_queues(netdev,
4904 adapter->num_rx_pools > 1 ? 1 :
4905 adapter->num_rx_queues);
4906 if (err)
4907 goto err_set_queues;
4908
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004909 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004910
4911 return 0;
4912
Alexander Duyckac802f52012-07-12 05:52:53 +00004913err_set_queues:
4914 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004915err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004916 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004917err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004918 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004919err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07004920 ixgbe_reset(adapter);
4921
4922 return err;
4923}
4924
4925/**
4926 * ixgbe_close - Disables a network interface
4927 * @netdev: network interface device structure
4928 *
4929 * Returns 0, this is not allowed to fail
4930 *
4931 * The close entry point is called when an interface is de-activated
4932 * by the OS. The hardware is still under the drivers control, but
4933 * needs to be disabled. A global MAC reset is issued to stop the
4934 * hardware, and all transmit and receive resources are freed.
4935 **/
4936static int ixgbe_close(struct net_device *netdev)
4937{
4938 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004939
4940 ixgbe_down(adapter);
4941 ixgbe_free_irq(adapter);
4942
Alexander Duycke4911d52011-05-11 07:18:52 +00004943 ixgbe_fdir_filter_exit(adapter);
4944
Auke Kok9a799d72007-09-15 14:07:45 -07004945 ixgbe_free_all_tx_resources(adapter);
4946 ixgbe_free_all_rx_resources(adapter);
4947
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004948 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004949
4950 return 0;
4951}
4952
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004953#ifdef CONFIG_PM
4954static int ixgbe_resume(struct pci_dev *pdev)
4955{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004956 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4957 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004958 u32 err;
4959
4960 pci_set_power_state(pdev, PCI_D0);
4961 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004962 /*
4963 * pci_restore_state clears dev->state_saved so call
4964 * pci_save_state to restore it.
4965 */
4966 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004967
4968 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004969 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004970 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004971 return err;
4972 }
4973 pci_set_master(pdev);
4974
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004975 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004976
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004977 ixgbe_reset(adapter);
4978
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004979 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4980
Alexander Duyckac802f52012-07-12 05:52:53 +00004981 rtnl_lock();
4982 err = ixgbe_init_interrupt_scheme(adapter);
4983 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004984 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00004985
4986 rtnl_unlock();
4987
4988 if (err)
4989 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004990
4991 netif_device_attach(netdev);
4992
4993 return 0;
4994}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004995#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004996
4997static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004998{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004999 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5000 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005001 struct ixgbe_hw *hw = &adapter->hw;
5002 u32 ctrl, fctrl;
5003 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005004#ifdef CONFIG_PM
5005 int retval = 0;
5006#endif
5007
5008 netif_device_detach(netdev);
5009
5010 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00005011 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005012 ixgbe_down(adapter);
5013 ixgbe_free_irq(adapter);
5014 ixgbe_free_all_tx_resources(adapter);
5015 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00005016 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005017 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005018
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005019 ixgbe_clear_interrupt_scheme(adapter);
5020
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005021#ifdef CONFIG_PM
5022 retval = pci_save_state(pdev);
5023 if (retval)
5024 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005025
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005026#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005027 if (wufc) {
5028 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005029
Don Skidmorec509e752012-04-05 08:12:05 +00005030 /*
5031 * enable the optics for both mult-speed fiber and
5032 * 82599 SFP+ fiber as we can WoL.
5033 */
5034 if (hw->mac.ops.enable_tx_laser &&
5035 (hw->phy.multispeed_fiber ||
5036 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber &&
5037 hw->mac.type == ixgbe_mac_82599EB)))
5038 hw->mac.ops.enable_tx_laser(hw);
5039
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005040 /* turn on all-multi mode if wake on multicast is enabled */
5041 if (wufc & IXGBE_WUFC_MC) {
5042 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5043 fctrl |= IXGBE_FCTRL_MPE;
5044 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5045 }
5046
5047 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5048 ctrl |= IXGBE_CTRL_GIO_DIS;
5049 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5050
5051 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5052 } else {
5053 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5054 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5055 }
5056
Alexander Duyckbd508172010-11-16 19:27:03 -08005057 switch (hw->mac.type) {
5058 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005059 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005060 break;
5061 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005062 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005063 pci_wake_from_d3(pdev, !!wufc);
5064 break;
5065 default:
5066 break;
5067 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005068
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005069 *enable_wake = !!wufc;
5070
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005071 ixgbe_release_hw_control(adapter);
5072
5073 pci_disable_device(pdev);
5074
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005075 return 0;
5076}
5077
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005078#ifdef CONFIG_PM
5079static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5080{
5081 int retval;
5082 bool wake;
5083
5084 retval = __ixgbe_shutdown(pdev, &wake);
5085 if (retval)
5086 return retval;
5087
5088 if (wake) {
5089 pci_prepare_to_sleep(pdev);
5090 } else {
5091 pci_wake_from_d3(pdev, false);
5092 pci_set_power_state(pdev, PCI_D3hot);
5093 }
5094
5095 return 0;
5096}
5097#endif /* CONFIG_PM */
5098
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005099static void ixgbe_shutdown(struct pci_dev *pdev)
5100{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005101 bool wake;
5102
5103 __ixgbe_shutdown(pdev, &wake);
5104
5105 if (system_state == SYSTEM_POWER_OFF) {
5106 pci_wake_from_d3(pdev, wake);
5107 pci_set_power_state(pdev, PCI_D3hot);
5108 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005109}
5110
5111/**
Auke Kok9a799d72007-09-15 14:07:45 -07005112 * ixgbe_update_stats - Update the board statistics counters.
5113 * @adapter: board private structure
5114 **/
5115void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5116{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005117 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005118 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005119 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005120 u64 total_mpc = 0;
5121 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005122 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5123 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005124 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005125
Don Skidmored08935c2010-06-11 13:20:29 +00005126 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5127 test_bit(__IXGBE_RESETTING, &adapter->state))
5128 return;
5129
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005130 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005131 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005132 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005133 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005134 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5135 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005136 }
5137 adapter->rsc_total_count = rsc_count;
5138 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005139 }
5140
Alexander Duyck5b7da512010-11-16 19:26:50 -08005141 for (i = 0; i < adapter->num_rx_queues; i++) {
5142 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5143 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5144 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5145 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005146 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005147 bytes += rx_ring->stats.bytes;
5148 packets += rx_ring->stats.packets;
5149 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005150 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005151 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5152 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005153 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005154 netdev->stats.rx_bytes = bytes;
5155 netdev->stats.rx_packets = packets;
5156
5157 bytes = 0;
5158 packets = 0;
5159 /* gather some stats to the adapter struct that are per queue */
5160 for (i = 0; i < adapter->num_tx_queues; i++) {
5161 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5162 restart_queue += tx_ring->tx_stats.restart_queue;
5163 tx_busy += tx_ring->tx_stats.tx_busy;
5164 bytes += tx_ring->stats.bytes;
5165 packets += tx_ring->stats.packets;
5166 }
5167 adapter->restart_queue = restart_queue;
5168 adapter->tx_busy = tx_busy;
5169 netdev->stats.tx_bytes = bytes;
5170 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005171
Joe Perches7ca647b2010-09-07 21:35:40 +00005172 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005173
5174 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005175 for (i = 0; i < 8; i++) {
5176 /* for packet buffers not used, the register should read 0 */
5177 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5178 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005179 hwstats->mpc[i] += mpc;
5180 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005181 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5182 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005183 switch (hw->mac.type) {
5184 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005185 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5186 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5187 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005188 hwstats->pxonrxc[i] +=
5189 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005190 break;
5191 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005192 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005193 hwstats->pxonrxc[i] +=
5194 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005195 break;
5196 default:
5197 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005198 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005199 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005200
5201 /*16 register reads */
5202 for (i = 0; i < 16; i++) {
5203 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5204 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5205 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5206 (hw->mac.type == ixgbe_mac_X540)) {
5207 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5208 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5209 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5210 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5211 }
5212 }
5213
Joe Perches7ca647b2010-09-07 21:35:40 +00005214 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005215 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005216 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005217
John Fastabendc84d3242010-11-16 19:27:12 -08005218 ixgbe_update_xoff_received(adapter);
5219
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005220 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005221 switch (hw->mac.type) {
5222 case ixgbe_mac_82598EB:
5223 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005224 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5225 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5226 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5227 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005228 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005229 /* OS2BMC stats are X540 only*/
5230 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5231 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5232 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5233 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5234 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005235 for (i = 0; i < 16; i++)
5236 adapter->hw_rx_no_dma_resources +=
5237 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005238 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005239 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005240 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005241 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005242 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005243 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005244 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005245 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5246 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005247#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005248 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5249 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5250 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5251 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5252 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5253 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005254 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005255 if (adapter->fcoe.ddp_pool) {
5256 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5257 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5258 unsigned int cpu;
5259 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005260 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005261 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5262 noddp += ddp_pool->noddp;
5263 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005264 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005265 hwstats->fcoe_noddp = noddp;
5266 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005267 }
Yi Zou6d455222009-05-13 13:12:16 +00005268#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005269 break;
5270 default:
5271 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005272 }
Auke Kok9a799d72007-09-15 14:07:45 -07005273 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005274 hwstats->bprc += bprc;
5275 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005276 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005277 hwstats->mprc -= bprc;
5278 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5279 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5280 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5281 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5282 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5283 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5284 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5285 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005286 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005287 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005288 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005289 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005290 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5291 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005292 /*
5293 * 82598 errata - tx of flow control packets is included in tx counters
5294 */
5295 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005296 hwstats->gptc -= xon_off_tot;
5297 hwstats->mptc -= xon_off_tot;
5298 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5299 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5300 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5301 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5302 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5303 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5304 hwstats->ptc64 -= xon_off_tot;
5305 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5306 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5307 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5308 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5309 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5310 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005311
5312 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005313 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005314
5315 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005316 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005317 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005318 netdev->stats.rx_length_errors = hwstats->rlec;
5319 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005320 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005321}
5322
5323/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005324 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005325 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005326 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005327static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005328{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005329 struct ixgbe_hw *hw = &adapter->hw;
5330 int i;
5331
Alexander Duyckd034acf2011-04-27 09:25:34 +00005332 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5333 return;
5334
5335 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5336
5337 /* if interface is down do nothing */
5338 if (test_bit(__IXGBE_DOWN, &adapter->state))
5339 return;
5340
5341 /* do nothing if we are not using signature filters */
5342 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5343 return;
5344
5345 adapter->fdir_overflow++;
5346
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005347 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5348 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005349 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005350 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005351 /* re-enable flow director interrupts */
5352 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005353 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005354 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005355 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005356 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005357}
5358
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005359/**
5360 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005361 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005362 *
5363 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005364 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005365 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005366 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005367 */
5368static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5369{
Auke Kok9a799d72007-09-15 14:07:45 -07005370 struct ixgbe_hw *hw = &adapter->hw;
5371 u64 eics = 0;
5372 int i;
5373
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005374 /* If we're down or resetting, just bail */
5375 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5376 test_bit(__IXGBE_RESETTING, &adapter->state))
5377 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005378
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005379 /* Force detection of hung controller */
5380 if (netif_carrier_ok(adapter->netdev)) {
5381 for (i = 0; i < adapter->num_tx_queues; i++)
5382 set_check_for_tx_hang(adapter->tx_ring[i]);
5383 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005384
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005385 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005386 /*
5387 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005388 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005389 * would set *both* EIMS and EICS for any bit in EIAM
5390 */
5391 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5392 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005393 } else {
5394 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005395 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005396 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005397 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005398 eics |= ((u64)1 << i);
5399 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005400 }
5401
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005402 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005403 ixgbe_irq_rearm_queues(adapter, eics);
5404
Alexander Duyckfe49f042009-06-04 16:00:09 +00005405}
5406
5407/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005408 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005409 * @adapter: pointer to the device adapter structure
5410 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005411 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005412static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005413{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005414 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005415 u32 link_speed = adapter->link_speed;
5416 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005417 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005418
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005419 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5420 return;
5421
5422 if (hw->mac.ops.check_link) {
5423 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005424 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005425 /* always assume link is up, if no check link function */
5426 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5427 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005428 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005429
5430 if (adapter->ixgbe_ieee_pfc)
5431 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5432
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005433 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005434 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005435 ixgbe_set_rx_drop_en(adapter);
5436 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005437
5438 if (link_up ||
5439 time_after(jiffies, (adapter->link_check_timeout +
5440 IXGBE_TRY_LINK_TIMEOUT))) {
5441 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5442 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5443 IXGBE_WRITE_FLUSH(hw);
5444 }
5445
5446 adapter->link_up = link_up;
5447 adapter->link_speed = link_speed;
5448}
5449
5450/**
5451 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5452 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005453 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005454 **/
5455static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5456{
5457 struct net_device *netdev = adapter->netdev;
5458 struct ixgbe_hw *hw = &adapter->hw;
5459 u32 link_speed = adapter->link_speed;
5460 bool flow_rx, flow_tx;
5461
5462 /* only continue if link was previously down */
5463 if (netif_carrier_ok(netdev))
5464 return;
5465
5466 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5467
5468 switch (hw->mac.type) {
5469 case ixgbe_mac_82598EB: {
5470 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5471 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5472 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5473 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5474 }
5475 break;
5476 case ixgbe_mac_X540:
5477 case ixgbe_mac_82599EB: {
5478 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5479 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5480 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5481 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5482 }
5483 break;
5484 default:
5485 flow_tx = false;
5486 flow_rx = false;
5487 break;
5488 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005489
5490#ifdef CONFIG_IXGBE_PTP
5491 ixgbe_ptp_start_cyclecounter(adapter);
5492#endif
5493
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005494 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5495 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5496 "10 Gbps" :
5497 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5498 "1 Gbps" :
5499 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5500 "100 Mbps" :
5501 "unknown speed"))),
5502 ((flow_rx && flow_tx) ? "RX/TX" :
5503 (flow_rx ? "RX" :
5504 (flow_tx ? "TX" : "None"))));
5505
5506 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005507 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005508
5509 /* ping all the active vfs to let them know link has changed */
5510 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005511}
5512
5513/**
5514 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5515 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005516 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005517 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005518static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005519{
5520 struct net_device *netdev = adapter->netdev;
5521 struct ixgbe_hw *hw = &adapter->hw;
5522
5523 adapter->link_up = false;
5524 adapter->link_speed = 0;
5525
5526 /* only continue if link was up previously */
5527 if (!netif_carrier_ok(netdev))
5528 return;
5529
5530 /* poll for SFP+ cable when link is down */
5531 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5532 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5533
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005534#ifdef CONFIG_IXGBE_PTP
5535 ixgbe_ptp_start_cyclecounter(adapter);
5536#endif
5537
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005538 e_info(drv, "NIC Link is Down\n");
5539 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005540
5541 /* ping all the active vfs to let them know link has changed */
5542 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005543}
5544
5545/**
5546 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005547 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005548 **/
5549static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5550{
5551 int i;
5552 int some_tx_pending = 0;
5553
5554 if (!netif_carrier_ok(adapter->netdev)) {
5555 for (i = 0; i < adapter->num_tx_queues; i++) {
5556 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5557 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5558 some_tx_pending = 1;
5559 break;
5560 }
5561 }
5562
5563 if (some_tx_pending) {
5564 /* We've lost link, so the controller stops DMA,
5565 * but we've got queued Tx work that's never going
5566 * to get done, so reset controller to flush Tx.
5567 * (Do the reset outside of interrupt context).
5568 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005569 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005570 }
5571 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005572}
5573
Greg Rosea985b6c32010-11-18 03:02:52 +00005574static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5575{
5576 u32 ssvpc;
5577
Greg Rose0584d992012-08-08 00:00:58 +00005578 /* Do not perform spoof check for 82598 or if not in IOV mode */
5579 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5580 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005581 return;
5582
5583 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5584
5585 /*
5586 * ssvpc register is cleared on read, if zero then no
5587 * spoofed packets in the last interval.
5588 */
5589 if (!ssvpc)
5590 return;
5591
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005592 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005593}
5594
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005595/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005596 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005597 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005598 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005599static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005600{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005601 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005602 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5603 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005604 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005605
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005606 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005607
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005608 if (adapter->link_up)
5609 ixgbe_watchdog_link_is_up(adapter);
5610 else
5611 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005612
Greg Rosea985b6c32010-11-18 03:02:52 +00005613 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005614 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005615
5616 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005617}
5618
Alexander Duyck70864002011-04-27 09:13:56 +00005619/**
5620 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005621 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005622 **/
5623static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5624{
5625 struct ixgbe_hw *hw = &adapter->hw;
5626 s32 err;
5627
5628 /* not searching for SFP so there is nothing to do here */
5629 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5630 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5631 return;
5632
5633 /* someone else is in init, wait until next service event */
5634 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5635 return;
5636
5637 err = hw->phy.ops.identify_sfp(hw);
5638 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5639 goto sfp_out;
5640
5641 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5642 /* If no cable is present, then we need to reset
5643 * the next time we find a good cable. */
5644 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5645 }
5646
5647 /* exit on error */
5648 if (err)
5649 goto sfp_out;
5650
5651 /* exit if reset not needed */
5652 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5653 goto sfp_out;
5654
5655 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5656
5657 /*
5658 * A module may be identified correctly, but the EEPROM may not have
5659 * support for that module. setup_sfp() will fail in that case, so
5660 * we should not allow that module to load.
5661 */
5662 if (hw->mac.type == ixgbe_mac_82598EB)
5663 err = hw->phy.ops.reset(hw);
5664 else
5665 err = hw->mac.ops.setup_sfp(hw);
5666
5667 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5668 goto sfp_out;
5669
5670 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5671 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5672
5673sfp_out:
5674 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5675
5676 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5677 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5678 e_dev_err("failed to initialize because an unsupported "
5679 "SFP+ module type was detected.\n");
5680 e_dev_err("Reload the driver after installing a "
5681 "supported module.\n");
5682 unregister_netdev(adapter->netdev);
5683 }
5684}
5685
5686/**
5687 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005688 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005689 **/
5690static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5691{
5692 struct ixgbe_hw *hw = &adapter->hw;
5693 u32 autoneg;
5694 bool negotiation;
5695
5696 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5697 return;
5698
5699 /* someone else is in init, wait until next service event */
5700 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5701 return;
5702
5703 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5704
5705 autoneg = hw->phy.autoneg_advertised;
5706 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5707 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005708 if (hw->mac.ops.setup_link)
5709 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5710
5711 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5712 adapter->link_check_timeout = jiffies;
5713 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5714}
5715
Greg Rose83c61fa2011-09-07 05:59:35 +00005716#ifdef CONFIG_PCI_IOV
5717static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5718{
5719 int vf;
5720 struct ixgbe_hw *hw = &adapter->hw;
5721 struct net_device *netdev = adapter->netdev;
5722 u32 gpc;
5723 u32 ciaa, ciad;
5724
5725 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5726 if (gpc) /* If incrementing then no need for the check below */
5727 return;
5728 /*
5729 * Check to see if a bad DMA write target from an errant or
5730 * malicious VF has caused a PCIe error. If so then we can
5731 * issue a VFLR to the offending VF(s) and then resume without
5732 * requesting a full slot reset.
5733 */
5734
5735 for (vf = 0; vf < adapter->num_vfs; vf++) {
5736 ciaa = (vf << 16) | 0x80000000;
5737 /* 32 bit read so align, we really want status at offset 6 */
5738 ciaa |= PCI_COMMAND;
5739 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5740 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5741 ciaa &= 0x7FFFFFFF;
5742 /* disable debug mode asap after reading data */
5743 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5744 /* Get the upper 16 bits which will be the PCI status reg */
5745 ciad >>= 16;
5746 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5747 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5748 /* Issue VFLR */
5749 ciaa = (vf << 16) | 0x80000000;
5750 ciaa |= 0xA8;
5751 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5752 ciad = 0x00008000; /* VFLR */
5753 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5754 ciaa &= 0x7FFFFFFF;
5755 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5756 }
5757 }
5758}
5759
5760#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005761/**
5762 * ixgbe_service_timer - Timer Call-back
5763 * @data: pointer to adapter cast into an unsigned long
5764 **/
5765static void ixgbe_service_timer(unsigned long data)
5766{
5767 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5768 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005769 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005770
5771 /* poll faster when waiting for link */
5772 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5773 next_event_offset = HZ / 10;
5774 else
5775 next_event_offset = HZ * 2;
5776
Greg Rose83c61fa2011-09-07 05:59:35 +00005777#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005778 /*
5779 * don't bother with SR-IOV VF DMA hang check if there are
5780 * no VFs or the link is down
5781 */
5782 if (!adapter->num_vfs ||
5783 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5784 goto normal_timer_service;
5785
5786 /* If we have VFs allocated then we must check for DMA hangs */
5787 ixgbe_check_for_bad_vf(adapter);
5788 next_event_offset = HZ / 50;
5789 adapter->timer_event_accumulator++;
5790
5791 if (adapter->timer_event_accumulator >= 100)
5792 adapter->timer_event_accumulator = 0;
5793 else
5794 ready = false;
5795
5796normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005797#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005798 /* Reset the timer */
5799 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5800
Greg Rose83c61fa2011-09-07 05:59:35 +00005801 if (ready)
5802 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005803}
5804
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005805static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5806{
5807 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5808 return;
5809
5810 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5811
5812 /* If we're already down or resetting, just bail */
5813 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5814 test_bit(__IXGBE_RESETTING, &adapter->state))
5815 return;
5816
5817 ixgbe_dump(adapter);
5818 netdev_err(adapter->netdev, "Reset adapter\n");
5819 adapter->tx_timeout_count++;
5820
5821 ixgbe_reinit_locked(adapter);
5822}
5823
Alexander Duyck70864002011-04-27 09:13:56 +00005824/**
5825 * ixgbe_service_task - manages and runs subtasks
5826 * @work: pointer to work_struct containing our data
5827 **/
5828static void ixgbe_service_task(struct work_struct *work)
5829{
5830 struct ixgbe_adapter *adapter = container_of(work,
5831 struct ixgbe_adapter,
5832 service_task);
5833
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005834 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005835 ixgbe_sfp_detection_subtask(adapter);
5836 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005837 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005838 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005839 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005840 ixgbe_check_hang_subtask(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005841#ifdef CONFIG_IXGBE_PTP
5842 ixgbe_ptp_overflow_check(adapter);
5843#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005844
5845 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005846}
5847
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005848static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5849 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005850 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005851{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005852 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005853 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005854 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005855
Alexander Duyck897ab152011-05-27 05:31:47 +00005856 if (!skb_is_gso(skb))
5857 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005858
Alexander Duyck897ab152011-05-27 05:31:47 +00005859 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005860 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005861 if (err)
5862 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005863 }
5864
Alexander Duyck897ab152011-05-27 05:31:47 +00005865 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5866 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5867
Alexander Duyck244e27a2012-02-08 07:51:11 +00005868 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005869 struct iphdr *iph = ip_hdr(skb);
5870 iph->tot_len = 0;
5871 iph->check = 0;
5872 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5873 iph->daddr, 0,
5874 IPPROTO_TCP,
5875 0);
5876 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005877 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5878 IXGBE_TX_FLAGS_CSUM |
5879 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005880 } else if (skb_is_gso_v6(skb)) {
5881 ipv6_hdr(skb)->payload_len = 0;
5882 tcp_hdr(skb)->check =
5883 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5884 &ipv6_hdr(skb)->daddr,
5885 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005886 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5887 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005888 }
5889
Alexander Duyck091a6242012-02-08 07:51:01 +00005890 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005891 l4len = tcp_hdrlen(skb);
5892 *hdr_len = skb_transport_offset(skb) + l4len;
5893
Alexander Duyck091a6242012-02-08 07:51:01 +00005894 /* update gso size and bytecount with header size */
5895 first->gso_segs = skb_shinfo(skb)->gso_segs;
5896 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5897
Alexander Duyck897ab152011-05-27 05:31:47 +00005898 /* mss_l4len_id: use 1 as index for TSO */
5899 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5900 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5901 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5902
5903 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5904 vlan_macip_lens = skb_network_header_len(skb);
5905 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005906 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005907
5908 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005909 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005910
5911 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005912}
5913
Alexander Duyck244e27a2012-02-08 07:51:11 +00005914static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5915 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005916{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005917 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005918 u32 vlan_macip_lens = 0;
5919 u32 mss_l4len_idx = 0;
5920 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005921
Alexander Duyck897ab152011-05-27 05:31:47 +00005922 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck62748b72012-07-20 08:09:01 +00005923 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) {
5924 if (unlikely(skb->no_fcs))
5925 first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS;
5926 if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5927 return;
5928 }
Alexander Duyck897ab152011-05-27 05:31:47 +00005929 } else {
5930 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005931 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005932 case __constant_htons(ETH_P_IP):
5933 vlan_macip_lens |= skb_network_header_len(skb);
5934 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5935 l4_hdr = ip_hdr(skb)->protocol;
5936 break;
5937 case __constant_htons(ETH_P_IPV6):
5938 vlan_macip_lens |= skb_network_header_len(skb);
5939 l4_hdr = ipv6_hdr(skb)->nexthdr;
5940 break;
5941 default:
5942 if (unlikely(net_ratelimit())) {
5943 dev_warn(tx_ring->dev,
5944 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005945 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005946 }
5947 break;
5948 }
Auke Kok9a799d72007-09-15 14:07:45 -07005949
Alexander Duyck897ab152011-05-27 05:31:47 +00005950 switch (l4_hdr) {
5951 case IPPROTO_TCP:
5952 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5953 mss_l4len_idx = tcp_hdrlen(skb) <<
5954 IXGBE_ADVTXD_L4LEN_SHIFT;
5955 break;
5956 case IPPROTO_SCTP:
5957 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
5958 mss_l4len_idx = sizeof(struct sctphdr) <<
5959 IXGBE_ADVTXD_L4LEN_SHIFT;
5960 break;
5961 case IPPROTO_UDP:
5962 mss_l4len_idx = sizeof(struct udphdr) <<
5963 IXGBE_ADVTXD_L4LEN_SHIFT;
5964 break;
5965 default:
5966 if (unlikely(net_ratelimit())) {
5967 dev_warn(tx_ring->dev,
5968 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005969 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00005970 }
5971 break;
5972 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00005973
5974 /* update TX checksum flag */
5975 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005976 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005977
Alexander Duyck244e27a2012-02-08 07:51:11 +00005978 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00005979 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005980 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005981
5982 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
5983 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07005984}
5985
Alexander Duyckd3d00232011-07-15 02:31:25 +00005986static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
5987{
5988 /* set type for advanced descriptor with frame checksum insertion */
5989 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
Alexander Duyckd3d00232011-07-15 02:31:25 +00005990 IXGBE_ADVTXD_DCMD_DEXT);
5991
5992 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00005993 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00005994 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
5995
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005996#ifdef CONFIG_IXGBE_PTP
5997 if (tx_flags & IXGBE_TX_FLAGS_TSTAMP)
5998 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP);
5999#endif
6000
Alexander Duyckd3d00232011-07-15 02:31:25 +00006001 /* set segmentation enable bits for TSO/FSO */
6002#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006003 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006004#else
6005 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6006#endif
6007 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6008
Alexander Duyck62748b72012-07-20 08:09:01 +00006009 /* insert frame checksum */
6010 if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS))
6011 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS);
6012
Alexander Duyckd3d00232011-07-15 02:31:25 +00006013 return cmd_type;
6014}
6015
Alexander Duyck729739b2012-02-08 07:51:06 +00006016static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6017 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006018{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006019 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006020
6021 /* enable L4 checksum for TSO and TX checksum offload */
6022 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6023 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6024
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006025 /* enble IPv4 checksum for TSO */
6026 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6027 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006028
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006029 /* use index 1 context for TSO/FSO/FCOE */
6030#ifdef IXGBE_FCOE
6031 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6032#else
6033 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006034#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006035 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6036
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006037 /*
6038 * Check Context must be set if Tx switch is enabled, which it
6039 * always is for case where virtual functions are running
6040 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006041#ifdef IXGBE_FCOE
6042 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6043#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006044 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006045#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006046 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6047
Alexander Duyck729739b2012-02-08 07:51:06 +00006048 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006049}
6050
6051#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6052 IXGBE_TXD_CMD_RS)
6053
6054static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006055 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006056 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006057{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006058 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00006059 struct sk_buff *skb = first->skb;
6060 struct ixgbe_tx_buffer *tx_buffer;
6061 union ixgbe_adv_tx_desc *tx_desc;
6062 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006063 unsigned int data_len = skb->data_len;
6064 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00006065 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006066 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00006067 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006068 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006069
Alexander Duyck729739b2012-02-08 07:51:06 +00006070 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6071
6072 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6073 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6074
Alexander Duyckd3d00232011-07-15 02:31:25 +00006075#ifdef IXGBE_FCOE
6076 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006077 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006078 size -= sizeof(struct fcoe_crc_eof) - data_len;
6079 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006080 } else {
6081 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006082 }
Auke Kok9a799d72007-09-15 14:07:45 -07006083 }
6084
Alexander Duyckd3d00232011-07-15 02:31:25 +00006085#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006086 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6087 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006088 goto dma_error;
6089
Alexander Duyck729739b2012-02-08 07:51:06 +00006090 /* record length, and DMA address */
6091 dma_unmap_len_set(first, len, size);
6092 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006093
Alexander Duyck729739b2012-02-08 07:51:06 +00006094 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006095
6096 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006097 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006098 tx_desc->read.cmd_type_len =
6099 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006100
Alexander Duyckd3d00232011-07-15 02:31:25 +00006101 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006102 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006103 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006104 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006105 i = 0;
6106 }
Alexander Duyck729739b2012-02-08 07:51:06 +00006107
6108 dma += IXGBE_MAX_DATA_PER_TXD;
6109 size -= IXGBE_MAX_DATA_PER_TXD;
6110
6111 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6112 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006113 }
6114
Alexander Duyck729739b2012-02-08 07:51:06 +00006115 if (likely(!data_len))
6116 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006117
Alexander Duyckd3d00232011-07-15 02:31:25 +00006118 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006119
Alexander Duyck729739b2012-02-08 07:51:06 +00006120 i++;
6121 tx_desc++;
6122 if (i == tx_ring->count) {
6123 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6124 i = 0;
6125 }
Auke Kok9a799d72007-09-15 14:07:45 -07006126
Alexander Duyckd3d00232011-07-15 02:31:25 +00006127#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006128 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006129#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006130 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006131#endif
6132 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006133
Alexander Duyck729739b2012-02-08 07:51:06 +00006134 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6135 DMA_TO_DEVICE);
6136 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006137 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006138
Alexander Duyck729739b2012-02-08 07:51:06 +00006139 tx_buffer = &tx_ring->tx_buffer_info[i];
6140 dma_unmap_len_set(tx_buffer, len, size);
6141 dma_unmap_addr_set(tx_buffer, dma, dma);
6142
6143 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6144 tx_desc->read.olinfo_status = 0;
6145
6146 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07006147 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006148
Alexander Duyck729739b2012-02-08 07:51:06 +00006149 /* write last descriptor with RS and EOP bits */
6150 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6151 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006152
Alexander Duyck091a6242012-02-08 07:51:01 +00006153 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006154
Alexander Duyckd3d00232011-07-15 02:31:25 +00006155 /* set the timestamp */
6156 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006157
6158 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006159 * Force memory writes to complete before letting h/w know there
6160 * are new descriptors to fetch. (Only applicable for weak-ordered
6161 * memory model archs, such as IA-64).
6162 *
6163 * We also need this memory barrier to make certain all of the
6164 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006165 */
6166 wmb();
6167
Alexander Duyckd3d00232011-07-15 02:31:25 +00006168 /* set next_to_watch value indicating a packet is present */
6169 first->next_to_watch = tx_desc;
6170
Alexander Duyck729739b2012-02-08 07:51:06 +00006171 i++;
6172 if (i == tx_ring->count)
6173 i = 0;
6174
6175 tx_ring->next_to_use = i;
6176
Alexander Duyckd3d00232011-07-15 02:31:25 +00006177 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006178 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006179
6180 return;
6181dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006182 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006183
6184 /* clear dma mappings for failed tx_buffer_info map */
6185 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006186 tx_buffer = &tx_ring->tx_buffer_info[i];
6187 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6188 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006189 break;
6190 if (i == 0)
6191 i = tx_ring->count;
6192 i--;
6193 }
6194
Alexander Duyckd3d00232011-07-15 02:31:25 +00006195 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006196}
6197
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006198static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006199 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006200{
Alexander Duyck69830522011-01-06 14:29:58 +00006201 struct ixgbe_q_vector *q_vector = ring->q_vector;
6202 union ixgbe_atr_hash_dword input = { .dword = 0 };
6203 union ixgbe_atr_hash_dword common = { .dword = 0 };
6204 union {
6205 unsigned char *network;
6206 struct iphdr *ipv4;
6207 struct ipv6hdr *ipv6;
6208 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006209 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006210 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006211
Alexander Duyck69830522011-01-06 14:29:58 +00006212 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6213 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006214 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006215
Alexander Duyck69830522011-01-06 14:29:58 +00006216 /* do nothing if sampling is disabled */
6217 if (!ring->atr_sample_rate)
6218 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006219
Alexander Duyck69830522011-01-06 14:29:58 +00006220 ring->atr_count++;
6221
6222 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006223 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006224
6225 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006226 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006227 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006228 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006229 hdr.ipv4->protocol != IPPROTO_TCP))
6230 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006231
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006232 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006233
Alexander Duyck66f32a82011-06-29 05:43:22 +00006234 /* skip this packet since it is invalid or the socket is closing */
6235 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006236 return;
6237
6238 /* sample on all syn packets or once every atr sample count */
6239 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6240 return;
6241
6242 /* reset sample count */
6243 ring->atr_count = 0;
6244
Alexander Duyck244e27a2012-02-08 07:51:11 +00006245 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006246
6247 /*
6248 * src and dst are inverted, think how the receiver sees them
6249 *
6250 * The input is broken into two sections, a non-compressed section
6251 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6252 * is XORed together and stored in the compressed dword.
6253 */
6254 input.formatted.vlan_id = vlan_id;
6255
6256 /*
6257 * since src port and flex bytes occupy the same word XOR them together
6258 * and write the value to source port portion of compressed dword
6259 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006260 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006261 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6262 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006263 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006264 common.port.dst ^= th->source;
6265
Alexander Duyck244e27a2012-02-08 07:51:11 +00006266 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006267 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6268 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6269 } else {
6270 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6271 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6272 hdr.ipv6->saddr.s6_addr32[1] ^
6273 hdr.ipv6->saddr.s6_addr32[2] ^
6274 hdr.ipv6->saddr.s6_addr32[3] ^
6275 hdr.ipv6->daddr.s6_addr32[0] ^
6276 hdr.ipv6->daddr.s6_addr32[1] ^
6277 hdr.ipv6->daddr.s6_addr32[2] ^
6278 hdr.ipv6->daddr.s6_addr32[3];
6279 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006280
6281 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006282 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6283 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006284}
6285
Alexander Duyck63544e92011-05-27 05:31:42 +00006286static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006287{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006288 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006289 /* Herbert's original patch had:
6290 * smp_mb__after_netif_stop_queue();
6291 * but since that doesn't exist yet, just open code it. */
6292 smp_mb();
6293
6294 /* We need to check again in a case another CPU has just
6295 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006296 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006297 return -EBUSY;
6298
6299 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006300 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006301 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006302 return 0;
6303}
6304
Alexander Duyck82d4e462011-06-11 01:44:58 +00006305static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006306{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006307 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006308 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006309 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006310}
6311
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006312static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6313{
6314 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006315 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6316 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006317#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006318 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006319
John Fastabende5b64632011-03-08 03:44:52 +00006320 if (((protocol == htons(ETH_P_FCOE)) ||
6321 (protocol == htons(ETH_P_FIP))) &&
6322 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckc0876632012-05-10 00:01:46 +00006323 struct ixgbe_ring_feature *f;
6324
6325 f = &adapter->ring_feature[RING_F_FCOE];
6326
6327 while (txq >= f->indices)
6328 txq -= f->indices;
Alexander Duycke4b317e2012-05-05 05:30:53 +00006329 txq += adapter->ring_feature[RING_F_FCOE].offset;
Alexander Duyckc0876632012-05-10 00:01:46 +00006330
John Fastabende5b64632011-03-08 03:44:52 +00006331 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006332 }
6333#endif
6334
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006335 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6336 while (unlikely(txq >= dev->real_num_tx_queues))
6337 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006338 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006339 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006340
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006341 return skb_tx_hash(dev, skb);
6342}
6343
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006344netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006345 struct ixgbe_adapter *adapter,
6346 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006347{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006348 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006349 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006350 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006351#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6352 unsigned short f;
6353#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006354 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006355 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006356 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006357
Alexander Duycka535c302011-05-27 05:31:52 +00006358 /*
6359 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006360 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006361 * + 2 desc gap to keep tail from touching head,
6362 * + 1 desc for context descriptor,
6363 * otherwise try next time
6364 */
6365#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6366 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6367 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6368#else
6369 count += skb_shinfo(skb)->nr_frags;
6370#endif
6371 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6372 tx_ring->tx_stats.tx_busy++;
6373 return NETDEV_TX_BUSY;
6374 }
6375
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006376 /* record the location of the first descriptor for this packet */
6377 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6378 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006379 first->bytecount = skb->len;
6380 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006381
Alexander Duyck66f32a82011-06-29 05:43:22 +00006382 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006383 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006384 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6385 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6386 /* else if it is a SW VLAN check the next protocol and store the tag */
6387 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6388 struct vlan_hdr *vhdr, _vhdr;
6389 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6390 if (!vhdr)
6391 goto out_drop;
6392
6393 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006394 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6395 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006396 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006397 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006398
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006399 skb_tx_timestamp(skb);
6400
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006401#ifdef CONFIG_IXGBE_PTP
6402 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6403 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6404 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
6405 }
6406#endif
6407
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006408#ifdef CONFIG_PCI_IOV
6409 /*
6410 * Use the l2switch_enable flag - would be false if the DMA
6411 * Tx switch had been disabled.
6412 */
6413 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6414 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6415
6416#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006417 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006418 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006419 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6420 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006421 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006422 tx_flags |= (skb->priority & 0x7) <<
6423 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006424 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6425 struct vlan_ethhdr *vhdr;
6426 if (skb_header_cloned(skb) &&
6427 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6428 goto out_drop;
6429 vhdr = (struct vlan_ethhdr *)skb->data;
6430 vhdr->h_vlan_TCI = htons(tx_flags >>
6431 IXGBE_TX_FLAGS_VLAN_SHIFT);
6432 } else {
6433 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6434 }
6435 }
Alexander Duycka535c302011-05-27 05:31:52 +00006436
Alexander Duyck244e27a2012-02-08 07:51:11 +00006437 /* record initial flags and protocol */
6438 first->tx_flags = tx_flags;
6439 first->protocol = protocol;
6440
Yi Zoueacd73f2009-05-13 13:11:06 +00006441#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006442 /* setup tx offload for FCoE */
6443 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006444 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006445 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006446 if (tso < 0)
6447 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006448
Alexander Duyck66f32a82011-06-29 05:43:22 +00006449 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006450 }
Auke Kok9a799d72007-09-15 14:07:45 -07006451
Auke Kok9a799d72007-09-15 14:07:45 -07006452#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006453 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006454 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006455 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006456 else if (!tso)
6457 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006458
6459 /* add the ATR filter if ATR is on */
6460 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006461 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006462
6463#ifdef IXGBE_FCOE
6464xmit_fcoe:
6465#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006466 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006467
6468 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006469
6470 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006471
6472out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006473 dev_kfree_skb_any(first->skb);
6474 first->skb = NULL;
6475
Alexander Duyck897ab152011-05-27 05:31:47 +00006476 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006477}
6478
Alexander Duycka50c29d2012-02-08 07:50:40 +00006479static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6480 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006481{
6482 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006483 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006484
Alexander Duycka50c29d2012-02-08 07:50:40 +00006485 /*
6486 * The minimum packet size for olinfo paylen is 17 so pad the skb
6487 * in order to meet this minimum size requirement.
6488 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006489 if (unlikely(skb->len < 17)) {
6490 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006491 return NETDEV_TX_OK;
6492 skb->len = 17;
6493 }
6494
Auke Kok9a799d72007-09-15 14:07:45 -07006495 tx_ring = adapter->tx_ring[skb->queue_mapping];
6496 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6497}
6498
6499/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006500 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006501 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006502 * @p: pointer to an address structure
6503 *
Auke Kok9a799d72007-09-15 14:07:45 -07006504 * Returns 0 on success, negative on failure
6505 **/
6506static int ixgbe_set_mac(struct net_device *netdev, void *p)
6507{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006508 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6509 struct ixgbe_hw *hw = &adapter->hw;
6510 struct sockaddr *addr = p;
6511
6512 if (!is_valid_ether_addr(addr->sa_data))
6513 return -EADDRNOTAVAIL;
6514
6515 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6516 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6517
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006518 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006519
6520 return 0;
6521}
6522
Ben Hutchings6b73e102009-04-29 08:08:58 +00006523static int
6524ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6525{
6526 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6527 struct ixgbe_hw *hw = &adapter->hw;
6528 u16 value;
6529 int rc;
6530
6531 if (prtad != hw->phy.mdio.prtad)
6532 return -EINVAL;
6533 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6534 if (!rc)
6535 rc = value;
6536 return rc;
6537}
6538
6539static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6540 u16 addr, u16 value)
6541{
6542 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6543 struct ixgbe_hw *hw = &adapter->hw;
6544
6545 if (prtad != hw->phy.mdio.prtad)
6546 return -EINVAL;
6547 return hw->phy.ops.write_reg(hw, addr, devad, value);
6548}
6549
6550static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6551{
6552 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6553
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006554 switch (cmd) {
6555#ifdef CONFIG_IXGBE_PTP
6556 case SIOCSHWTSTAMP:
6557 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
6558#endif
6559 default:
6560 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6561 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006562}
6563
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006564/**
6565 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006566 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006567 * @netdev: network interface device structure
6568 *
6569 * Returns non-zero on failure
6570 **/
6571static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6572{
6573 int err = 0;
6574 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006575 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006576
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006577 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006578 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006579 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006580 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006581
6582 /* update SAN MAC vmdq pool selection */
6583 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006584 }
6585 return err;
6586}
6587
6588/**
6589 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006590 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006591 * @netdev: network interface device structure
6592 *
6593 * Returns non-zero on failure
6594 **/
6595static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6596{
6597 int err = 0;
6598 struct ixgbe_adapter *adapter = netdev_priv(dev);
6599 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6600
6601 if (is_valid_ether_addr(mac->san_addr)) {
6602 rtnl_lock();
6603 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6604 rtnl_unlock();
6605 }
6606 return err;
6607}
6608
Auke Kok9a799d72007-09-15 14:07:45 -07006609#ifdef CONFIG_NET_POLL_CONTROLLER
6610/*
6611 * Polling 'interrupt' - used by things like netconsole to send skbs
6612 * without having to re-enable interrupts. It's not called while
6613 * the interrupt routine is executing.
6614 */
6615static void ixgbe_netpoll(struct net_device *netdev)
6616{
6617 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006618 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006619
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006620 /* if interface is down do nothing */
6621 if (test_bit(__IXGBE_DOWN, &adapter->state))
6622 return;
6623
Auke Kok9a799d72007-09-15 14:07:45 -07006624 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006625 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006626 for (i = 0; i < adapter->num_q_vectors; i++)
6627 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006628 } else {
6629 ixgbe_intr(adapter->pdev->irq, netdev);
6630 }
Auke Kok9a799d72007-09-15 14:07:45 -07006631 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006632}
Auke Kok9a799d72007-09-15 14:07:45 -07006633
Alexander Duyck581330b2012-02-08 07:51:47 +00006634#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006635static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6636 struct rtnl_link_stats64 *stats)
6637{
6638 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6639 int i;
6640
Eric Dumazet1a515022010-11-16 19:26:42 -08006641 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006642 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006643 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006644 u64 bytes, packets;
6645 unsigned int start;
6646
Eric Dumazet1a515022010-11-16 19:26:42 -08006647 if (ring) {
6648 do {
6649 start = u64_stats_fetch_begin_bh(&ring->syncp);
6650 packets = ring->stats.packets;
6651 bytes = ring->stats.bytes;
6652 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6653 stats->rx_packets += packets;
6654 stats->rx_bytes += bytes;
6655 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006656 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006657
6658 for (i = 0; i < adapter->num_tx_queues; i++) {
6659 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6660 u64 bytes, packets;
6661 unsigned int start;
6662
6663 if (ring) {
6664 do {
6665 start = u64_stats_fetch_begin_bh(&ring->syncp);
6666 packets = ring->stats.packets;
6667 bytes = ring->stats.bytes;
6668 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6669 stats->tx_packets += packets;
6670 stats->tx_bytes += bytes;
6671 }
6672 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006673 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006674 /* following stats updated by ixgbe_watchdog_task() */
6675 stats->multicast = netdev->stats.multicast;
6676 stats->rx_errors = netdev->stats.rx_errors;
6677 stats->rx_length_errors = netdev->stats.rx_length_errors;
6678 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6679 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6680 return stats;
6681}
6682
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006683#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006684/**
6685 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6686 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006687 * @tc: number of traffic classes currently enabled
6688 *
6689 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6690 * 802.1Q priority maps to a packet buffer that exists.
6691 */
6692static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6693{
6694 struct ixgbe_hw *hw = &adapter->hw;
6695 u32 reg, rsave;
6696 int i;
6697
6698 /* 82598 have a static priority to TC mapping that can not
6699 * be changed so no validation is needed.
6700 */
6701 if (hw->mac.type == ixgbe_mac_82598EB)
6702 return;
6703
6704 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6705 rsave = reg;
6706
6707 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6708 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6709
6710 /* If up2tc is out of bounds default to zero */
6711 if (up2tc > tc)
6712 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6713 }
6714
6715 if (reg != rsave)
6716 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6717
6718 return;
6719}
6720
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006721/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006722 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6723 * @adapter: Pointer to adapter struct
6724 *
6725 * Populate the netdev user priority to tc map
6726 */
6727static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6728{
6729 struct net_device *dev = adapter->netdev;
6730 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6731 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6732 u8 prio;
6733
6734 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6735 u8 tc = 0;
6736
6737 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6738 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6739 else if (ets)
6740 tc = ets->prio_tc[prio];
6741
6742 netdev_set_prio_tc_map(dev, prio, tc);
6743 }
6744}
6745
6746/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006747 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006748 *
6749 * @netdev: net device to configure
6750 * @tc: number of traffic classes to enable
6751 */
6752int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6753{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006754 struct ixgbe_adapter *adapter = netdev_priv(dev);
6755 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006756
John Fastabend8b1c0b22011-05-03 02:26:48 +00006757 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006758 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006759 (hw->mac.type == ixgbe_mac_82598EB &&
6760 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006761 return -EINVAL;
6762
6763 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006764 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006765 * hardware is not flexible enough to do this dynamically.
6766 */
6767 if (netif_running(dev))
6768 ixgbe_close(dev);
6769 ixgbe_clear_interrupt_scheme(adapter);
6770
John Fastabende7589ea2011-07-18 22:38:36 +00006771 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006772 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006773 ixgbe_set_prio_tc_map(adapter);
6774
John Fastabende7589ea2011-07-18 22:38:36 +00006775 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006776
Alexander Duyck943561d2012-05-09 22:14:44 -07006777 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6778 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006779 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006780 }
John Fastabende7589ea2011-07-18 22:38:36 +00006781 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006782 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006783
Alexander Duyck943561d2012-05-09 22:14:44 -07006784 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6785 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006786
6787 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006788
6789 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6790 adapter->dcb_cfg.pfc_mode_enable = false;
6791 }
6792
John Fastabend8b1c0b22011-05-03 02:26:48 +00006793 ixgbe_init_interrupt_scheme(adapter);
6794 ixgbe_validate_rtr(adapter, tc);
6795 if (netif_running(dev))
6796 ixgbe_open(dev);
6797
6798 return 0;
6799}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006800
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006801#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006802void ixgbe_do_reset(struct net_device *netdev)
6803{
6804 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6805
6806 if (netif_running(netdev))
6807 ixgbe_reinit_locked(adapter);
6808 else
6809 ixgbe_reset(adapter);
6810}
6811
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006812static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006813 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006814{
6815 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6816
Don Skidmore082757a2011-07-21 05:55:00 +00006817 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006818 if (!(features & NETIF_F_RXCSUM))
6819 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006820
Alexander Duyck567d2de2012-02-11 07:18:57 +00006821 /* Turn off LRO if not RSC capable */
6822 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6823 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006824
Alexander Duyck567d2de2012-02-11 07:18:57 +00006825 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006826}
6827
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006828static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006829 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006830{
6831 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006832 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006833 bool need_reset = false;
6834
Don Skidmore082757a2011-07-21 05:55:00 +00006835 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006836 if (!(features & NETIF_F_LRO)) {
6837 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006838 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006839 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6840 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6841 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6842 if (adapter->rx_itr_setting == 1 ||
6843 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6844 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6845 need_reset = true;
6846 } else if ((changed ^ features) & NETIF_F_LRO) {
6847 e_info(probe, "rx-usecs set too low, "
6848 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006849 }
6850 }
6851
6852 /*
6853 * Check if Flow Director n-tuple support was enabled or disabled. If
6854 * the state changed, we need to reset.
6855 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006856 switch (features & NETIF_F_NTUPLE) {
6857 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00006858 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006859 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6860 need_reset = true;
6861
Alexander Duyck567d2de2012-02-11 07:18:57 +00006862 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6863 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00006864 break;
6865 default:
6866 /* turn off perfect filters, enable ATR and reset */
6867 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6868 need_reset = true;
6869
6870 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6871
6872 /* We cannot enable ATR if SR-IOV is enabled */
6873 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6874 break;
6875
6876 /* We cannot enable ATR if we have 2 or more traffic classes */
6877 if (netdev_get_num_tc(netdev) > 1)
6878 break;
6879
6880 /* We cannot enable ATR if RSS is disabled */
6881 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6882 break;
6883
6884 /* A sample rate of 0 indicates ATR disabled */
6885 if (!adapter->atr_sample_rate)
6886 break;
6887
6888 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6889 break;
Don Skidmore082757a2011-07-21 05:55:00 +00006890 }
6891
John Fastabend146d4cc2012-05-15 05:59:26 +00006892 if (features & NETIF_F_HW_VLAN_RX)
6893 ixgbe_vlan_strip_enable(adapter);
6894 else
6895 ixgbe_vlan_strip_disable(adapter);
6896
Ben Greear3f2d1c02012-03-08 08:28:41 +00006897 if (changed & NETIF_F_RXALL)
6898 need_reset = true;
6899
Alexander Duyck567d2de2012-02-11 07:18:57 +00006900 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006901 if (need_reset)
6902 ixgbe_do_reset(netdev);
6903
6904 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006905}
6906
stephen hemmingeredc7d572012-10-01 12:32:33 +00006907static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006908 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006909 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006910 u16 flags)
6911{
6912 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00006913 int err;
6914
6915 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6916 return -EOPNOTSUPP;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006917
6918 if (ndm->ndm_state & NUD_PERMANENT) {
6919 pr_info("%s: FDB only supports static addresses\n",
6920 ixgbe_driver_name);
6921 return -EINVAL;
6922 }
6923
John Fastabend95447462012-05-31 12:42:26 +00006924 if (is_unicast_ether_addr(addr)) {
6925 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6926
6927 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006928 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006929 else
John Fastabend95447462012-05-31 12:42:26 +00006930 err = -ENOMEM;
6931 } else if (is_multicast_ether_addr(addr)) {
6932 err = dev_mc_add_excl(dev, addr);
6933 } else {
6934 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006935 }
6936
6937 /* Only return duplicate errors if NLM_F_EXCL is set */
6938 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6939 err = 0;
6940
6941 return err;
6942}
6943
6944static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6945 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006946 const unsigned char *addr)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006947{
6948 struct ixgbe_adapter *adapter = netdev_priv(dev);
6949 int err = -EOPNOTSUPP;
6950
6951 if (ndm->ndm_state & NUD_PERMANENT) {
6952 pr_info("%s: FDB only supports static addresses\n",
6953 ixgbe_driver_name);
6954 return -EINVAL;
6955 }
6956
6957 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6958 if (is_unicast_ether_addr(addr))
6959 err = dev_uc_del(dev, addr);
6960 else if (is_multicast_ether_addr(addr))
6961 err = dev_mc_del(dev, addr);
6962 else
6963 err = -EINVAL;
6964 }
6965
6966 return err;
6967}
6968
6969static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
6970 struct netlink_callback *cb,
6971 struct net_device *dev,
6972 int idx)
6973{
6974 struct ixgbe_adapter *adapter = netdev_priv(dev);
6975
6976 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6977 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
6978
6979 return idx;
6980}
6981
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006982static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00006983 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006984 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08006985 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006986 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00006987 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006988 .ndo_validate_addr = eth_validate_addr,
6989 .ndo_set_mac_address = ixgbe_set_mac,
6990 .ndo_change_mtu = ixgbe_change_mtu,
6991 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006992 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
6993 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00006994 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00006995 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
6996 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
6997 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00006998 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00006999 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007000 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007001#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007002 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007003#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007004#ifdef CONFIG_NET_POLL_CONTROLLER
7005 .ndo_poll_controller = ixgbe_netpoll,
7006#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007007#ifdef IXGBE_FCOE
7008 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007009 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007010 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007011 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7012 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007013 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007014 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007015#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007016 .ndo_set_features = ixgbe_set_features,
7017 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007018 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7019 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7020 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007021};
7022
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007023/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007024 * ixgbe_wol_supported - Check whether device supports WoL
7025 * @hw: hw specific details
7026 * @device_id: the device ID
7027 * @subdev_id: the subsystem device ID
7028 *
7029 * This function is used by probe and ethtool to determine
7030 * which devices have WoL support
7031 *
7032 **/
7033int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7034 u16 subdevice_id)
7035{
7036 struct ixgbe_hw *hw = &adapter->hw;
7037 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7038 int is_wol_supported = 0;
7039
7040 switch (device_id) {
7041 case IXGBE_DEV_ID_82599_SFP:
7042 /* Only these subdevices could supports WOL */
7043 switch (subdevice_id) {
7044 case IXGBE_SUBDEV_ID_82599_560FLR:
7045 /* only support first port */
7046 if (hw->bus.func != 0)
7047 break;
7048 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007049 case IXGBE_SUBDEV_ID_82599_RNDC:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007050 is_wol_supported = 1;
7051 break;
7052 }
7053 break;
7054 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7055 /* All except this subdevice support WOL */
7056 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7057 is_wol_supported = 1;
7058 break;
7059 case IXGBE_DEV_ID_82599_KX4:
7060 is_wol_supported = 1;
7061 break;
7062 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007063 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007064 /* check eeprom to see if enabled wol */
7065 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7066 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7067 (hw->bus.func == 0))) {
7068 is_wol_supported = 1;
7069 }
7070 break;
7071 }
7072
7073 return is_wol_supported;
7074}
7075
7076/**
Auke Kok9a799d72007-09-15 14:07:45 -07007077 * ixgbe_probe - Device Initialization Routine
7078 * @pdev: PCI device information struct
7079 * @ent: entry in ixgbe_pci_tbl
7080 *
7081 * Returns 0 on success, negative on failure
7082 *
7083 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7084 * The OS initialization, configuring of the adapter private structure,
7085 * and a hardware reset occur.
7086 **/
7087static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007088 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007089{
7090 struct net_device *netdev;
7091 struct ixgbe_adapter *adapter = NULL;
7092 struct ixgbe_hw *hw;
7093 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007094 static int cards_found;
7095 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007096 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007097 unsigned int indices = num_possible_cpus();
John Fastabend3f4a6f02012-06-05 05:58:52 +00007098 unsigned int dcb_max = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00007099#ifdef IXGBE_FCOE
7100 u16 device_caps;
7101#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007102 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007103
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007104 /* Catch broken hardware that put the wrong VF device ID in
7105 * the PCIe SR-IOV capability.
7106 */
7107 if (pdev->is_virtfn) {
7108 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7109 pci_name(pdev), pdev->vendor, pdev->device);
7110 return -EINVAL;
7111 }
7112
gouji-new9ce77662009-05-06 10:44:45 +00007113 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007114 if (err)
7115 return err;
7116
Nick Nunley1b507732010-04-27 13:10:27 +00007117 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7118 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007119 pci_using_dac = 1;
7120 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007121 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007122 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007123 err = dma_set_coherent_mask(&pdev->dev,
7124 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007125 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007126 dev_err(&pdev->dev,
7127 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007128 goto err_dma;
7129 }
7130 }
7131 pci_using_dac = 0;
7132 }
7133
gouji-new9ce77662009-05-06 10:44:45 +00007134 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007135 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007136 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007137 dev_err(&pdev->dev,
7138 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007139 goto err_pci_reg;
7140 }
7141
Frans Pop19d5afd2009-10-02 10:04:12 -07007142 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007143
Auke Kok9a799d72007-09-15 14:07:45 -07007144 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007145 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007146
John Fastabende901acd2011-04-26 07:26:08 +00007147#ifdef CONFIG_IXGBE_DCB
John Fastabend3f4a6f02012-06-05 05:58:52 +00007148 if (ii->mac == ixgbe_mac_82598EB)
7149 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7150 IXGBE_MAX_RSS_INDICES);
7151 else
7152 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7153 IXGBE_MAX_FDIR_INDICES);
John Fastabende901acd2011-04-26 07:26:08 +00007154#endif
7155
John Fastabendc85a2612010-02-25 23:15:21 +00007156 if (ii->mac == ixgbe_mac_82598EB)
7157 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7158 else
7159 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7160
John Fastabende901acd2011-04-26 07:26:08 +00007161#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007162 indices += min_t(unsigned int, num_possible_cpus(),
7163 IXGBE_MAX_FCOE_INDICES);
7164#endif
John Fastabend3f4a6f02012-06-05 05:58:52 +00007165 indices = max_t(unsigned int, dcb_max, indices);
John Fastabendc85a2612010-02-25 23:15:21 +00007166 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007167 if (!netdev) {
7168 err = -ENOMEM;
7169 goto err_alloc_etherdev;
7170 }
7171
Auke Kok9a799d72007-09-15 14:07:45 -07007172 SET_NETDEV_DEV(netdev, &pdev->dev);
7173
Auke Kok9a799d72007-09-15 14:07:45 -07007174 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007175 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007176
7177 adapter->netdev = netdev;
7178 adapter->pdev = pdev;
7179 hw = &adapter->hw;
7180 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007181 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007182
Jeff Kirsher05857982008-09-11 19:57:00 -07007183 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007184 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007185 if (!hw->hw_addr) {
7186 err = -EIO;
7187 goto err_ioremap;
7188 }
7189
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007190 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007191 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007192 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007193 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007194
Auke Kok9a799d72007-09-15 14:07:45 -07007195 adapter->bd_number = cards_found;
7196
Auke Kok9a799d72007-09-15 14:07:45 -07007197 /* Setup hw api */
7198 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007199 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007200
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007201 /* EEPROM */
7202 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7203 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7204 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7205 if (!(eec & (1 << 8)))
7206 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7207
7208 /* PHY */
7209 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007210 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007211 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7212 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7213 hw->phy.mdio.mmds = 0;
7214 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7215 hw->phy.mdio.dev = netdev;
7216 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7217 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007218
Don Skidmore8ca783a2009-05-26 20:40:47 -07007219 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007220
7221 /* setup the private structure */
7222 err = ixgbe_sw_init(adapter);
7223 if (err)
7224 goto err_sw_init;
7225
Don Skidmoree86bff02010-02-11 04:14:08 +00007226 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007227 switch (adapter->hw.mac.type) {
7228 case ixgbe_mac_82599EB:
7229 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007230 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007231 break;
7232 default:
7233 break;
7234 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007235
Don Skidmorebf069c92009-05-07 10:39:54 +00007236 /*
7237 * If there is a fan on this device and it has failed log the
7238 * failure.
7239 */
7240 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7241 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7242 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007243 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007244 }
7245
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007246 if (allow_unsupported_sfp)
7247 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7248
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007249 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007250 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007251 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007252 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007253 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7254 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007255 err = 0;
7256 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007257 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007258 "module type was detected.\n");
7259 e_dev_err("Reload the driver after installing a supported "
7260 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007261 goto err_sw_init;
7262 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007263 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007264 goto err_sw_init;
7265 }
7266
Alexander Duyck99d74482012-05-09 08:09:25 +00007267#ifdef CONFIG_PCI_IOV
7268 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007269
Alexander Duyck99d74482012-05-09 08:09:25 +00007270#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007271 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007272 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007273 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007274 NETIF_F_HW_VLAN_TX |
7275 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007276 NETIF_F_HW_VLAN_FILTER |
7277 NETIF_F_TSO |
7278 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007279 NETIF_F_RXHASH |
7280 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007281
Don Skidmore082757a2011-07-21 05:55:00 +00007282 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007283
Don Skidmore58be7662011-04-12 09:42:11 +00007284 switch (adapter->hw.mac.type) {
7285 case ixgbe_mac_82599EB:
7286 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007287 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007288 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7289 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007290 break;
7291 default:
7292 break;
7293 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007294
Ben Greear3f2d1c02012-03-08 08:28:41 +00007295 netdev->hw_features |= NETIF_F_RXALL;
7296
Jeff Kirsherad31c402008-06-05 04:05:30 -07007297 netdev->vlan_features |= NETIF_F_TSO;
7298 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007299 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007300 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007301 netdev->vlan_features |= NETIF_F_SG;
7302
Jiri Pirko01789342011-08-16 06:29:00 +00007303 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007304 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007305
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007306#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007307 netdev->dcbnl_ops = &dcbnl_ops;
7308#endif
7309
Yi Zoueacd73f2009-05-13 13:11:06 +00007310#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007311 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007312 if (hw->mac.ops.get_device_caps) {
7313 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007314 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7315 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007316 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007317
7318 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7319
Alexander Duycka58915c2012-05-25 06:38:18 +00007320 netdev->features |= NETIF_F_FSO |
7321 NETIF_F_FCOE_CRC;
7322
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007323 netdev->vlan_features |= NETIF_F_FSO |
7324 NETIF_F_FCOE_CRC |
7325 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007326 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007327#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007328 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007329 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007330 netdev->vlan_features |= NETIF_F_HIGHDMA;
7331 }
Auke Kok9a799d72007-09-15 14:07:45 -07007332
Don Skidmore082757a2011-07-21 05:55:00 +00007333 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7334 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007335 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007336 netdev->features |= NETIF_F_LRO;
7337
Auke Kok9a799d72007-09-15 14:07:45 -07007338 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007339 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007340 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007341 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007342 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007343 }
7344
7345 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7346 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7347
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007348 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007349 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007350 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007351 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007352 }
7353
Alexander Duyck70864002011-04-27 09:13:56 +00007354 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007355 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007356
Alexander Duyck70864002011-04-27 09:13:56 +00007357 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7358 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007359
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007360 err = ixgbe_init_interrupt_scheme(adapter);
7361 if (err)
7362 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007363
Jacob Keller8e2813f2012-04-21 06:05:40 +00007364 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007365 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007366 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7367 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007368 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007369
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007370 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7371
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007372#ifdef CONFIG_IXGBE_PTP
7373 ixgbe_ptp_init(adapter);
7374#endif /* CONFIG_IXGBE_PTP*/
7375
Emil Tantilov15e52092011-09-29 05:01:29 +00007376 /* save off EEPROM version number */
7377 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7378 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7379
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007380 /* pick up the PCI bus settings for reporting later */
7381 hw->mac.ops.get_bus_info(hw);
7382
Auke Kok9a799d72007-09-15 14:07:45 -07007383 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007384 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007385 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7386 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007387 "Unknown"),
7388 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7389 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7390 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7391 "Unknown"),
7392 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007393
7394 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7395 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007396 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007397 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007398 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007399 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007400 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007401 else
Don Skidmore289700db2010-12-03 03:32:58 +00007402 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7403 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007404
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007405 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007406 e_dev_warn("PCI-Express bandwidth available for this card is "
7407 "not sufficient for optimal performance.\n");
7408 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7409 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007410 }
7411
Auke Kok9a799d72007-09-15 14:07:45 -07007412 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007413 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007414 if (err == IXGBE_ERR_EEPROM_VERSION) {
7415 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007416 e_dev_warn("This device is a pre-production adapter/LOM. "
7417 "Please be aware there may be issues associated "
7418 "with your hardware. If you are experiencing "
7419 "problems please contact your Intel or hardware "
7420 "representative who provided you with this "
7421 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007422 }
Auke Kok9a799d72007-09-15 14:07:45 -07007423 strcpy(netdev->name, "eth%d");
7424 err = register_netdev(netdev);
7425 if (err)
7426 goto err_register;
7427
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007428 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7429 if (hw->mac.ops.disable_tx_laser &&
7430 ((hw->phy.multispeed_fiber) ||
7431 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7432 (hw->mac.type == ixgbe_mac_82599EB))))
7433 hw->mac.ops.disable_tx_laser(hw);
7434
Jesse Brandeburg54386462009-04-17 20:44:27 +00007435 /* carrier off reporting is important to ethtool even BEFORE open */
7436 netif_carrier_off(netdev);
7437
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007438#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007439 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007440 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007441 ixgbe_setup_dca(adapter);
7442 }
7443#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007444 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007445 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007446 for (i = 0; i < adapter->num_vfs; i++)
7447 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7448 }
7449
Jacob Keller2466dd92011-09-08 03:50:54 +00007450 /* firmware requires driver version to be 0xFFFFFFFF
7451 * since os does not support feature
7452 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007453 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007454 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7455 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007456
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007457 /* add san mac addr to netdev */
7458 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007459
Neerav Parikhea818752012-01-04 20:23:40 +00007460 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007461 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007462
Don Skidmore12109822012-05-04 06:07:08 +00007463#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007464 if (ixgbe_sysfs_init(adapter))
7465 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007466#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007467
Catherine Sullivan00949162012-08-10 01:59:10 +00007468#ifdef CONFIG_DEBUG_FS
7469 ixgbe_dbg_adapter_init(adapter);
7470#endif /* CONFIG_DEBUG_FS */
7471
Auke Kok9a799d72007-09-15 14:07:45 -07007472 return 0;
7473
7474err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007475 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007476 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007477err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007478 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007479 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007480 iounmap(hw->hw_addr);
7481err_ioremap:
7482 free_netdev(netdev);
7483err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007484 pci_release_selected_regions(pdev,
7485 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007486err_pci_reg:
7487err_dma:
7488 pci_disable_device(pdev);
7489 return err;
7490}
7491
7492/**
7493 * ixgbe_remove - Device Removal Routine
7494 * @pdev: PCI device information struct
7495 *
7496 * ixgbe_remove is called by the PCI subsystem to alert the driver
7497 * that it should release a PCI device. The could be caused by a
7498 * Hot-Plug event, or because the driver is going to be removed from
7499 * memory.
7500 **/
7501static void __devexit ixgbe_remove(struct pci_dev *pdev)
7502{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007503 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7504 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007505
Catherine Sullivan00949162012-08-10 01:59:10 +00007506#ifdef CONFIG_DEBUG_FS
7507 ixgbe_dbg_adapter_exit(adapter);
7508#endif /*CONFIG_DEBUG_FS */
7509
Auke Kok9a799d72007-09-15 14:07:45 -07007510 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007511 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007512
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007513#ifdef CONFIG_IXGBE_PTP
7514 ixgbe_ptp_stop(adapter);
7515#endif
7516
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007517#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007518 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7519 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7520 dca_remove_requester(&pdev->dev);
7521 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7522 }
7523
7524#endif
Don Skidmore12109822012-05-04 06:07:08 +00007525#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007526 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007527#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007528
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007529 /* remove the added san mac */
7530 ixgbe_del_sanmac_netdev(netdev);
7531
Donald Skidmorec4900be2008-11-20 21:11:42 -08007532 if (netdev->reg_state == NETREG_REGISTERED)
7533 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007534
Alexander Duyck92971272012-05-23 02:58:40 +00007535 ixgbe_disable_sriov(adapter);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007536
Alexander Duyck7a921c92009-05-06 10:43:28 +00007537 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007538
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007539 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007540
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007541#ifdef CONFIG_DCB
7542 kfree(adapter->ixgbe_ieee_pfc);
7543 kfree(adapter->ixgbe_ieee_ets);
7544
7545#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007546 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007547 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007548 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007549
Emil Tantilov849c4542010-06-03 16:53:41 +00007550 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007551
Auke Kok9a799d72007-09-15 14:07:45 -07007552 free_netdev(netdev);
7553
Frans Pop19d5afd2009-10-02 10:04:12 -07007554 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007555
Auke Kok9a799d72007-09-15 14:07:45 -07007556 pci_disable_device(pdev);
7557}
7558
7559/**
7560 * ixgbe_io_error_detected - called when PCI error is detected
7561 * @pdev: Pointer to PCI device
7562 * @state: The current pci connection state
7563 *
7564 * This function is called after a PCI bus error affecting
7565 * this device has been detected.
7566 */
7567static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007568 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007569{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007570 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7571 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007572
Greg Rose83c61fa2011-09-07 05:59:35 +00007573#ifdef CONFIG_PCI_IOV
7574 struct pci_dev *bdev, *vfdev;
7575 u32 dw0, dw1, dw2, dw3;
7576 int vf, pos;
7577 u16 req_id, pf_func;
7578
7579 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7580 adapter->num_vfs == 0)
7581 goto skip_bad_vf_detection;
7582
7583 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007584 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007585 bdev = bdev->bus->self;
7586
7587 if (!bdev)
7588 goto skip_bad_vf_detection;
7589
7590 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7591 if (!pos)
7592 goto skip_bad_vf_detection;
7593
7594 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7595 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7596 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7597 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7598
7599 req_id = dw1 >> 16;
7600 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7601 if (!(req_id & 0x0080))
7602 goto skip_bad_vf_detection;
7603
7604 pf_func = req_id & 0x01;
7605 if ((pf_func & 1) == (pdev->devfn & 1)) {
7606 unsigned int device_id;
7607
7608 vf = (req_id & 0x7F) >> 1;
7609 e_dev_err("VF %d has caused a PCIe error\n", vf);
7610 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7611 "%8.8x\tdw3: %8.8x\n",
7612 dw0, dw1, dw2, dw3);
7613 switch (adapter->hw.mac.type) {
7614 case ixgbe_mac_82599EB:
7615 device_id = IXGBE_82599_VF_DEVICE_ID;
7616 break;
7617 case ixgbe_mac_X540:
7618 device_id = IXGBE_X540_VF_DEVICE_ID;
7619 break;
7620 default:
7621 device_id = 0;
7622 break;
7623 }
7624
7625 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007626 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007627 while (vfdev) {
7628 if (vfdev->devfn == (req_id & 0xFF))
7629 break;
Jon Mason36e90312012-07-19 21:02:09 +00007630 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007631 device_id, vfdev);
7632 }
7633 /*
7634 * There's a slim chance the VF could have been hot plugged,
7635 * so if it is no longer present we don't need to issue the
7636 * VFLR. Just clean up the AER in that case.
7637 */
7638 if (vfdev) {
7639 e_dev_err("Issuing VFLR to VF %d\n", vf);
7640 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7641 }
7642
7643 pci_cleanup_aer_uncorrect_error_status(pdev);
7644 }
7645
7646 /*
7647 * Even though the error may have occurred on the other port
7648 * we still need to increment the vf error reference count for
7649 * both ports because the I/O resume function will be called
7650 * for both of them.
7651 */
7652 adapter->vferr_refcount++;
7653
7654 return PCI_ERS_RESULT_RECOVERED;
7655
7656skip_bad_vf_detection:
7657#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007658 netif_device_detach(netdev);
7659
Breno Leitao3044b8d2009-05-06 10:44:26 +00007660 if (state == pci_channel_io_perm_failure)
7661 return PCI_ERS_RESULT_DISCONNECT;
7662
Auke Kok9a799d72007-09-15 14:07:45 -07007663 if (netif_running(netdev))
7664 ixgbe_down(adapter);
7665 pci_disable_device(pdev);
7666
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007667 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007668 return PCI_ERS_RESULT_NEED_RESET;
7669}
7670
7671/**
7672 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7673 * @pdev: Pointer to PCI device
7674 *
7675 * Restart the card from scratch, as if from a cold-boot.
7676 */
7677static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7678{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007679 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007680 pci_ers_result_t result;
7681 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007682
gouji-new9ce77662009-05-06 10:44:45 +00007683 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007684 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007685 result = PCI_ERS_RESULT_DISCONNECT;
7686 } else {
7687 pci_set_master(pdev);
7688 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007689 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007690
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007691 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007692
7693 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007694 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007695 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007696 }
Auke Kok9a799d72007-09-15 14:07:45 -07007697
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007698 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7699 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007700 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7701 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007702 /* non-fatal, continue */
7703 }
Auke Kok9a799d72007-09-15 14:07:45 -07007704
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007705 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007706}
7707
7708/**
7709 * ixgbe_io_resume - called when traffic can start flowing again.
7710 * @pdev: Pointer to PCI device
7711 *
7712 * This callback is called when the error recovery driver tells us that
7713 * its OK to resume normal operation.
7714 */
7715static void ixgbe_io_resume(struct pci_dev *pdev)
7716{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007717 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7718 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007719
Greg Rose83c61fa2011-09-07 05:59:35 +00007720#ifdef CONFIG_PCI_IOV
7721 if (adapter->vferr_refcount) {
7722 e_info(drv, "Resuming after VF err\n");
7723 adapter->vferr_refcount--;
7724 return;
7725 }
7726
7727#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007728 if (netif_running(netdev))
7729 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007730
7731 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007732}
7733
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007734static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007735 .error_detected = ixgbe_io_error_detected,
7736 .slot_reset = ixgbe_io_slot_reset,
7737 .resume = ixgbe_io_resume,
7738};
7739
7740static struct pci_driver ixgbe_driver = {
7741 .name = ixgbe_driver_name,
7742 .id_table = ixgbe_pci_tbl,
7743 .probe = ixgbe_probe,
7744 .remove = __devexit_p(ixgbe_remove),
7745#ifdef CONFIG_PM
7746 .suspend = ixgbe_suspend,
7747 .resume = ixgbe_resume,
7748#endif
7749 .shutdown = ixgbe_shutdown,
7750 .err_handler = &ixgbe_err_handler
7751};
7752
7753/**
7754 * ixgbe_init_module - Driver Registration Routine
7755 *
7756 * ixgbe_init_module is the first routine called when the driver is
7757 * loaded. All it does is register with the PCI subsystem.
7758 **/
7759static int __init ixgbe_init_module(void)
7760{
7761 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007762 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007763 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007764
Catherine Sullivan00949162012-08-10 01:59:10 +00007765#ifdef CONFIG_DEBUG_FS
7766 ixgbe_dbg_init();
7767#endif /* CONFIG_DEBUG_FS */
7768
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007769#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007770 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007771#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007772
Auke Kok9a799d72007-09-15 14:07:45 -07007773 ret = pci_register_driver(&ixgbe_driver);
7774 return ret;
7775}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007776
Auke Kok9a799d72007-09-15 14:07:45 -07007777module_init(ixgbe_init_module);
7778
7779/**
7780 * ixgbe_exit_module - Driver Exit Cleanup Routine
7781 *
7782 * ixgbe_exit_module is called just before the driver is removed
7783 * from memory.
7784 **/
7785static void __exit ixgbe_exit_module(void)
7786{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007787#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007788 dca_unregister_notify(&dca_notifier);
7789#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007790 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00007791
7792#ifdef CONFIG_DEBUG_FS
7793 ixgbe_dbg_exit();
7794#endif /* CONFIG_DEBUG_FS */
7795
Eric Dumazet1a515022010-11-16 19:26:42 -08007796 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007797}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007798
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007799#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007800static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007801 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007802{
7803 int ret_val;
7804
7805 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007806 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007807
7808 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7809}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007810
Alexander Duyckb4533682009-03-31 21:32:42 +00007811#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007812
Auke Kok9a799d72007-09-15 14:07:45 -07007813module_exit(ixgbe_exit_module);
7814
7815/* ixgbe_main.c */