blob: cae763c57dc7b8203b4b368561f237741962ac5c [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";
Neerav Parikhea818752012-01-04 20:23:40 +000058char ixgbe_default_device_descr[] =
59 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define MAJ 3
Don Skidmore19d478b2011-10-07 03:53:51 +000061#define MIN 6
62#define BUILD 7
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000063#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000064 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070065const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000066static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000067 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070068
69static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070070 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000071 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
292 struct ixgbe_tx_buffer *tx_buffer_info;
293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
332 tx_buffer_info =
333 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000334 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000335 n, tx_ring->next_to_use, tx_ring->next_to_clean,
336 (u64)tx_buffer_info->dma,
337 tx_buffer_info->length,
338 tx_buffer_info->next_to_watch,
339 (u64)tx_buffer_info->time_stamp);
340 }
341
342 /* Print TX Rings */
343 if (!netif_msg_tx_done(adapter))
344 goto rx_ring_summary;
345
346 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
347
348 /* Transmit Descriptor Formats
349 *
350 * Advanced Transmit Descriptor
351 * +--------------------------------------------------------------+
352 * 0 | Buffer Address [63:0] |
353 * +--------------------------------------------------------------+
354 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
355 * +--------------------------------------------------------------+
356 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
357 */
358
359 for (n = 0; n < adapter->num_tx_queues; n++) {
360 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("------------------------------------\n");
362 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
363 pr_info("------------------------------------\n");
364 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 "[PlPOIdStDDt Ln] [bi->dma ] "
366 "leng ntw timestamp bi->skb\n");
367
368 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000369 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 tx_buffer_info = &tx_ring->tx_buffer_info[i];
371 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000372 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000373 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000374 le64_to_cpu(u0->a),
375 le64_to_cpu(u0->b),
376 (u64)tx_buffer_info->dma,
377 tx_buffer_info->length,
378 tx_buffer_info->next_to_watch,
379 (u64)tx_buffer_info->time_stamp,
380 tx_buffer_info->skb);
381 if (i == tx_ring->next_to_use &&
382 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000383 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000385 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000386 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000387 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 else
Joe Perchesc7689572010-09-07 21:35:17 +0000389 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000390
391 if (netif_msg_pktdata(adapter) &&
392 tx_buffer_info->dma != 0)
393 print_hex_dump(KERN_INFO, "",
394 DUMP_PREFIX_ADDRESS, 16, 1,
395 phys_to_virt(tx_buffer_info->dma),
396 tx_buffer_info->length, true);
397 }
398 }
399
400 /* Print RX Rings Summary */
401rx_ring_summary:
402 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000403 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000404 for (n = 0; n < adapter->num_rx_queues; n++) {
405 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000406 pr_info("%5d %5X %5X\n",
407 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000408 }
409
410 /* Print RX Rings */
411 if (!netif_msg_rx_status(adapter))
412 goto exit;
413
414 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
415
416 /* Advanced Receive Descriptor (Read) Format
417 * 63 1 0
418 * +-----------------------------------------------------+
419 * 0 | Packet Buffer Address [63:1] |A0/NSE|
420 * +----------------------------------------------+------+
421 * 8 | Header Buffer Address [63:1] | DD |
422 * +-----------------------------------------------------+
423 *
424 *
425 * Advanced Receive Descriptor (Write-Back) Format
426 *
427 * 63 48 47 32 31 30 21 20 16 15 4 3 0
428 * +------------------------------------------------------+
429 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
430 * | Checksum Ident | | | | Type | Type |
431 * +------------------------------------------------------+
432 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
433 * +------------------------------------------------------+
434 * 63 48 47 32 31 20 19 0
435 */
436 for (n = 0; n < adapter->num_rx_queues; n++) {
437 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("------------------------------------\n");
439 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
440 pr_info("------------------------------------\n");
441 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
443 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000444 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445 "[vl er S cks ln] ---------------- [bi->skb] "
446 "<-- Adv Rx Write-Back format\n");
447
448 for (i = 0; i < rx_ring->count; i++) {
449 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000450 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000451 u0 = (struct my_u0 *)rx_desc;
452 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
453 if (staterr & IXGBE_RXD_STAT_DD) {
454 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000455 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 "%016llX ---------------- %p", i,
457 le64_to_cpu(u0->a),
458 le64_to_cpu(u0->b),
459 rx_buffer_info->skb);
460 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000461 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462 "%016llX %016llX %p", i,
463 le64_to_cpu(u0->a),
464 le64_to_cpu(u0->b),
465 (u64)rx_buffer_info->dma,
466 rx_buffer_info->skb);
467
468 if (netif_msg_pktdata(adapter)) {
469 print_hex_dump(KERN_INFO, "",
470 DUMP_PREFIX_ADDRESS, 16, 1,
471 phys_to_virt(rx_buffer_info->dma),
472 rx_ring->rx_buf_len, true);
473
474 if (rx_ring->rx_buf_len
Alexander Duyck919e78a2011-08-26 09:52:38 +0000475 < IXGBE_RXBUFFER_2K)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000476 print_hex_dump(KERN_INFO, "",
477 DUMP_PREFIX_ADDRESS, 16, 1,
478 phys_to_virt(
479 rx_buffer_info->page_dma +
480 rx_buffer_info->page_offset
481 ),
482 PAGE_SIZE/2, true);
483 }
484 }
485
486 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000488 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000489 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000490 else
Joe Perchesc7689572010-09-07 21:35:17 +0000491 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000492
493 }
494 }
495
496exit:
497 return;
498}
499
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800500static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
501{
502 u32 ctrl_ext;
503
504 /* Let firmware take over control of h/w */
505 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000507 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800508}
509
510static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
511{
512 u32 ctrl_ext;
513
514 /* Let firmware know the driver has taken over */
515 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
516 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000517 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800518}
Auke Kok9a799d72007-09-15 14:07:45 -0700519
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000520/*
521 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
522 * @adapter: pointer to adapter struct
523 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
524 * @queue: queue to map the corresponding interrupt to
525 * @msix_vector: the vector to map to the corresponding queue
526 *
527 */
528static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000529 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700530{
531 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000532 struct ixgbe_hw *hw = &adapter->hw;
533 switch (hw->mac.type) {
534 case ixgbe_mac_82598EB:
535 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
536 if (direction == -1)
537 direction = 0;
538 index = (((direction * 64) + queue) >> 2) & 0x1F;
539 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
540 ivar &= ~(0xFF << (8 * (queue & 0x3)));
541 ivar |= (msix_vector << (8 * (queue & 0x3)));
542 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
543 break;
544 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800545 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000546 if (direction == -1) {
547 /* other causes */
548 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
549 index = ((queue & 1) * 8);
550 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
551 ivar &= ~(0xFF << index);
552 ivar |= (msix_vector << index);
553 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
554 break;
555 } else {
556 /* tx or rx causes */
557 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
558 index = ((16 * (queue & 1)) + (8 * direction));
559 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
560 ivar &= ~(0xFF << index);
561 ivar |= (msix_vector << index);
562 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
563 break;
564 }
565 default:
566 break;
567 }
Auke Kok9a799d72007-09-15 14:07:45 -0700568}
569
Alexander Duyckfe49f042009-06-04 16:00:09 +0000570static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572{
573 u32 mask;
574
Alexander Duyckbd508172010-11-16 19:27:03 -0800575 switch (adapter->hw.mac.type) {
576 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000577 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
578 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800579 break;
580 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800581 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000582 mask = (qmask & 0xFFFFFFFF);
583 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
584 mask = (qmask >> 32);
585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800586 break;
587 default:
588 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000589 }
590}
591
Alexander Duyckd3d00232011-07-15 02:31:25 +0000592static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
593 struct ixgbe_tx_buffer *tx_buffer)
594{
595 if (tx_buffer->dma) {
596 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
597 dma_unmap_page(ring->dev,
598 tx_buffer->dma,
599 tx_buffer->length,
600 DMA_TO_DEVICE);
601 else
602 dma_unmap_single(ring->dev,
603 tx_buffer->dma,
604 tx_buffer->length,
605 DMA_TO_DEVICE);
606 }
607 tx_buffer->dma = 0;
608}
609
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800610void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
611 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700612{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000613 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
614 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700615 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000616 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700617 /* tx_buffer_info must be completely set up in the transmit path */
618}
619
John Fastabendc84d3242010-11-16 19:27:12 -0800620static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700621{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700622 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800623 struct ixgbe_hw_stats *hwstats = &adapter->stats;
624 u32 data = 0;
625 u32 xoff[8] = {0};
626 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700627
John Fastabendc84d3242010-11-16 19:27:12 -0800628 if ((hw->fc.current_mode == ixgbe_fc_full) ||
629 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
630 switch (hw->mac.type) {
631 case ixgbe_mac_82598EB:
632 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
633 break;
634 default:
635 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
636 }
637 hwstats->lxoffrxc += data;
638
639 /* refill credits (no tx hang) if we received xoff */
640 if (!data)
641 return;
642
643 for (i = 0; i < adapter->num_tx_queues; i++)
644 clear_bit(__IXGBE_HANG_CHECK_ARMED,
645 &adapter->tx_ring[i]->state);
646 return;
647 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
648 return;
649
650 /* update stats for each tc, only valid with PFC enabled */
651 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
652 switch (hw->mac.type) {
653 case ixgbe_mac_82598EB:
654 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
655 break;
656 default:
657 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
658 }
659 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700660 }
661
John Fastabendc84d3242010-11-16 19:27:12 -0800662 /* disarm tx queues that have received xoff frames */
663 for (i = 0; i < adapter->num_tx_queues; i++) {
664 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000665 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800666
667 if (xoff[tc])
668 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
669 }
670}
671
672static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
673{
674 return ring->tx_stats.completed;
675}
676
677static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
678{
679 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
680 struct ixgbe_hw *hw = &adapter->hw;
681
682 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
683 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
684
685 if (head != tail)
686 return (head < tail) ?
687 tail - head : (tail + ring->count - head);
688
689 return 0;
690}
691
692static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
693{
694 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
695 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
696 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
697 bool ret = false;
698
699 clear_check_for_tx_hang(tx_ring);
700
701 /*
702 * Check for a hung queue, but be thorough. This verifies
703 * that a transmit has been completed since the previous
704 * check AND there is at least one packet pending. The
705 * ARMED bit is set to indicate a potential hang. The
706 * bit is cleared if a pause frame is received to remove
707 * false hang detection due to PFC or 802.3x frames. By
708 * requiring this to fail twice we avoid races with
709 * pfc clearing the ARMED bit and conditions where we
710 * run the check_tx_hang logic with a transmit completion
711 * pending but without time to complete it yet.
712 */
713 if ((tx_done_old == tx_done) && tx_pending) {
714 /* make sure it is true for two checks in a row */
715 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
716 &tx_ring->state);
717 } else {
718 /* update completed stats and continue */
719 tx_ring->tx_stats.tx_done_old = tx_done;
720 /* reset the countdown */
721 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
722 }
723
724 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700725}
726
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000727/**
728 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
729 * @adapter: driver private struct
730 **/
731static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
732{
733
734 /* Do the reset outside of interrupt context */
735 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
736 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
737 ixgbe_service_event_schedule(adapter);
738 }
739}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700740
Auke Kok9a799d72007-09-15 14:07:45 -0700741/**
742 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000743 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700744 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700745 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000746static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000747 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700748{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000749 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000750 struct ixgbe_tx_buffer *tx_buffer;
751 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700752 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000753 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000754 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700755
Alexander Duyckd3d00232011-07-15 02:31:25 +0000756 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000757 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800758
Alexander Duyck30065e62011-07-15 03:05:14 +0000759 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000760 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700761
Alexander Duyckd3d00232011-07-15 02:31:25 +0000762 /* if next_to_watch is not set then there is no work pending */
763 if (!eop_desc)
764 break;
765
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000766 /* prevent any other reads prior to eop_desc */
767 rmb();
768
Alexander Duyckd3d00232011-07-15 02:31:25 +0000769 /* if DD is not set pending work has not been completed */
770 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
771 break;
772
773 /* count the packet as being completed */
774 tx_ring->tx_stats.completed++;
775
776 /* clear next_to_watch to prevent false hangs */
777 tx_buffer->next_to_watch = NULL;
778
Alexander Duyckd3d00232011-07-15 02:31:25 +0000779 do {
780 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000781 if (likely(tx_desc == eop_desc)) {
782 eop_desc = NULL;
783 dev_kfree_skb_any(tx_buffer->skb);
784 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800785
Alexander Duyckd3d00232011-07-15 02:31:25 +0000786 total_bytes += tx_buffer->bytecount;
787 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800788 }
789
Alexander Duyckd3d00232011-07-15 02:31:25 +0000790 tx_buffer++;
791 tx_desc++;
792 i++;
793 if (unlikely(i == tx_ring->count)) {
794 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700795
Alexander Duyckd3d00232011-07-15 02:31:25 +0000796 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000797 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000798 }
799
800 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800801 }
802
Auke Kok9a799d72007-09-15 14:07:45 -0700803 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000804 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800805 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000806 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000807 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000808 q_vector->tx.total_bytes += total_bytes;
809 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800810
John Fastabendc84d3242010-11-16 19:27:12 -0800811 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800812 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800813 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycke4f74022012-01-31 02:59:44 +0000814 tx_desc = IXGBE_TX_DESC(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800815 e_err(drv, "Detected Tx Unit Hang\n"
816 " Tx Queue <%d>\n"
817 " TDH, TDT <%x>, <%x>\n"
818 " next_to_use <%x>\n"
819 " next_to_clean <%x>\n"
820 "tx_buffer_info[next_to_clean]\n"
821 " time_stamp <%lx>\n"
822 " jiffies <%lx>\n",
823 tx_ring->queue_index,
824 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
825 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000826 tx_ring->next_to_use, i,
827 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800828
829 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
830
831 e_info(probe,
832 "tx hang %d detected on queue %d, resetting adapter\n",
833 adapter->tx_timeout_count + 1, tx_ring->queue_index);
834
835 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000836 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800837
838 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000839 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800840 }
Auke Kok9a799d72007-09-15 14:07:45 -0700841
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000842 netdev_tx_completed_queue(txring_txq(tx_ring),
843 total_packets, total_bytes);
844
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800845#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000846 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000847 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800848 /* Make sure that anybody stopping the queue after this
849 * sees the new next_to_clean.
850 */
851 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800852 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800853 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800854 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800855 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800856 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800857 }
Auke Kok9a799d72007-09-15 14:07:45 -0700858
Alexander Duyck59224552011-08-31 00:01:06 +0000859 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700860}
861
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400862#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800863static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800864 struct ixgbe_ring *tx_ring,
865 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800866{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000867 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000868 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
869 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800870
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800871 switch (hw->mac.type) {
872 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000873 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800874 break;
875 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800876 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000877 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
878 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
879 break;
880 default:
881 /* for unknown hardware do not write register */
882 return;
883 }
884
885 /*
886 * We can enable relaxed ordering for reads, but not writes when
887 * DCA is enabled. This is due to a known issue in some chipsets
888 * which will cause the DCA tag to be cleared.
889 */
890 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
891 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
892 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
893
894 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
895}
896
897static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
898 struct ixgbe_ring *rx_ring,
899 int cpu)
900{
901 struct ixgbe_hw *hw = &adapter->hw;
902 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
903 u8 reg_idx = rx_ring->reg_idx;
904
905
906 switch (hw->mac.type) {
907 case ixgbe_mac_82599EB:
908 case ixgbe_mac_X540:
909 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800910 break;
911 default:
912 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800913 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000914
915 /*
916 * We can enable relaxed ordering for reads, but not writes when
917 * DCA is enabled. This is due to a known issue in some chipsets
918 * which will cause the DCA tag to be cleared.
919 */
920 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
921 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
922 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
923
924 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925}
926
927static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
928{
929 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000930 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800932
933 if (q_vector->cpu == cpu)
934 goto out_no_update;
935
Alexander Duycka5579282012-02-08 07:50:04 +0000936 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000937 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800938
Alexander Duycka5579282012-02-08 07:50:04 +0000939 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000940 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800941
942 q_vector->cpu = cpu;
943out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800944 put_cpu();
945}
946
947static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
948{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800949 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800950 int i;
951
952 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
953 return;
954
Alexander Duycke35ec122009-05-21 13:07:12 +0000955 /* always use CB2 mode, difference is masked in the CB driver */
956 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
957
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
959 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
960 else
961 num_q_vectors = 1;
962
963 for (i = 0; i < num_q_vectors; i++) {
964 adapter->q_vector[i]->cpu = -1;
965 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800966 }
967}
968
969static int __ixgbe_notify_dca(struct device *dev, void *data)
970{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800971 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800972 unsigned long event = *(unsigned long *)data;
973
Don Skidmore2a72c312011-07-20 02:27:05 +0000974 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800975 return 0;
976
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800977 switch (event) {
978 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700979 /* if we're already enabled, don't do it again */
980 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
981 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300982 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700983 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800984 ixgbe_setup_dca(adapter);
985 break;
986 }
987 /* Fall Through since DCA is disabled. */
988 case DCA_PROVIDER_REMOVE:
989 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
990 dca_remove_requester(dev);
991 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
992 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
993 }
994 break;
995 }
996
Denis V. Lunev652f0932008-03-27 14:39:17 +0300997 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800998}
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000999
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001000#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001001static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1002 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001003 struct sk_buff *skb)
1004{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001005 if (ring->netdev->features & NETIF_F_RXHASH)
1006 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001007}
1008
Auke Kok9a799d72007-09-15 14:07:45 -07001009/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001010 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1011 * @adapter: address of board private structure
1012 * @rx_desc: advanced rx descriptor
1013 *
1014 * Returns : true if it is FCoE pkt
1015 */
1016static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1017 union ixgbe_adv_rx_desc *rx_desc)
1018{
1019 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1020
1021 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1022 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1023 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1024 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1025}
1026
1027/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001028 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001029 * @ring: structure containing ring specific data
1030 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001031 * @skb: skb currently being received and modified
1032 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001033static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001034 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001035 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001036{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001037 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001038
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001039 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001040 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001041 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001042
1043 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001044 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1045 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001046 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001047 return;
1048 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001049
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001050 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001051 return;
1052
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001053 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001054 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1055
1056 /*
1057 * 82599 errata, UDP frames with a 0 checksum can be marked as
1058 * checksum errors.
1059 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001060 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1061 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001062 return;
1063
Alexander Duyck8a0da212012-01-31 02:59:49 +00001064 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001065 return;
1066 }
1067
Auke Kok9a799d72007-09-15 14:07:45 -07001068 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001069 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001070}
1071
Alexander Duyck84ea2592010-11-16 19:26:49 -08001072static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001073{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001074 rx_ring->next_to_use = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001075 /*
1076 * Force memory writes to complete before letting h/w
1077 * know there are new descriptors to fetch. (Only
1078 * applicable for weak-ordered memory model archs,
1079 * such as IA-64).
1080 */
1081 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001082 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001083}
1084
Alexander Duyckf990b792012-01-31 02:59:34 +00001085static bool ixgbe_alloc_mapped_skb(struct ixgbe_ring *rx_ring,
1086 struct ixgbe_rx_buffer *bi)
1087{
1088 struct sk_buff *skb = bi->skb;
1089 dma_addr_t dma = bi->dma;
1090
1091 if (dma)
1092 return true;
1093
1094 if (likely(!skb)) {
1095 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1096 rx_ring->rx_buf_len);
1097 bi->skb = skb;
1098 if (!skb) {
1099 rx_ring->rx_stats.alloc_rx_buff_failed++;
1100 return false;
1101 }
Alexander Duyckf990b792012-01-31 02:59:34 +00001102 }
1103
1104 dma = dma_map_single(rx_ring->dev, skb->data,
1105 rx_ring->rx_buf_len, DMA_FROM_DEVICE);
1106
1107 if (dma_mapping_error(rx_ring->dev, dma)) {
1108 rx_ring->rx_stats.alloc_rx_buff_failed++;
1109 return false;
1110 }
1111
1112 bi->dma = dma;
1113 return true;
1114}
1115
1116static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1117 struct ixgbe_rx_buffer *bi)
1118{
1119 struct page *page = bi->page;
1120 dma_addr_t page_dma = bi->page_dma;
1121 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
1122
1123 if (page_dma)
1124 return true;
1125
1126 if (!page) {
1127 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1128 bi->page = page;
1129 if (unlikely(!page)) {
1130 rx_ring->rx_stats.alloc_rx_page_failed++;
1131 return false;
1132 }
1133 }
1134
1135 page_dma = dma_map_page(rx_ring->dev, page,
1136 page_offset, PAGE_SIZE / 2,
1137 DMA_FROM_DEVICE);
1138
1139 if (dma_mapping_error(rx_ring->dev, page_dma)) {
1140 rx_ring->rx_stats.alloc_rx_page_failed++;
1141 return false;
1142 }
1143
1144 bi->page_dma = page_dma;
1145 bi->page_offset = page_offset;
1146 return true;
1147}
1148
Auke Kok9a799d72007-09-15 14:07:45 -07001149/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001150 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001151 * @rx_ring: ring to place buffers on
1152 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001153 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001154void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001155{
Auke Kok9a799d72007-09-15 14:07:45 -07001156 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001157 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001158 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001159
Alexander Duyckf990b792012-01-31 02:59:34 +00001160 /* nothing to do or no valid netdev defined */
1161 if (!cleaned_count || !rx_ring->netdev)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001162 return;
1163
Alexander Duycke4f74022012-01-31 02:59:44 +00001164 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001165 bi = &rx_ring->rx_buffer_info[i];
1166 i -= rx_ring->count;
1167
Auke Kok9a799d72007-09-15 14:07:45 -07001168 while (cleaned_count--) {
Alexander Duyckf990b792012-01-31 02:59:34 +00001169 if (!ixgbe_alloc_mapped_skb(rx_ring, bi))
1170 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001171
Alexander Duyckf990b792012-01-31 02:59:34 +00001172 /* Refresh the desc even if buffer_addrs didn't change
1173 * because each write-back erases this info. */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001174 if (ring_is_ps_enabled(rx_ring)) {
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001175 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Alexander Duyckf990b792012-01-31 02:59:34 +00001176
1177 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1178 break;
1179
1180 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001181 } else {
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001182 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001183 }
1184
Alexander Duyckf990b792012-01-31 02:59:34 +00001185 rx_desc++;
1186 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001187 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001188 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001189 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001190 bi = rx_ring->rx_buffer_info;
1191 i -= rx_ring->count;
1192 }
1193
1194 /* clear the hdr_addr for the next_to_use descriptor */
1195 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001196 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001197
Alexander Duyckf990b792012-01-31 02:59:34 +00001198 i += rx_ring->count;
1199
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001200 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001201 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001202}
1203
Alexander Duyckc267fc12010-11-16 19:27:00 -08001204static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001205{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001206 /* HW will not DMA in data larger than the given buffer, even if it
1207 * parses the (NFS, of course) header to be larger. In that case, it
1208 * fills the header buffer and spills the rest into the page.
1209 */
1210 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1211 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1212 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1213 if (hlen > IXGBE_RX_HDR_SIZE)
1214 hlen = IXGBE_RX_HDR_SIZE;
1215 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001216}
1217
Alexander Duyckf8212f92009-04-27 22:42:37 +00001218/**
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001219 * ixgbe_merge_active_tail - merge active tail into lro skb
1220 * @tail: pointer to active tail in frag_list
Alexander Duyckf8212f92009-04-27 22:42:37 +00001221 *
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001222 * This function merges the length and data of an active tail into the
1223 * skb containing the frag_list. It resets the tail's pointer to the head,
1224 * but it leaves the heads pointer to tail intact.
Alexander Duyckf8212f92009-04-27 22:42:37 +00001225 **/
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001226static inline struct sk_buff *ixgbe_merge_active_tail(struct sk_buff *tail)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001227{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001228 struct sk_buff *head = IXGBE_CB(tail)->head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001229
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001230 if (!head)
1231 return tail;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001232
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001233 head->len += tail->len;
1234 head->data_len += tail->len;
1235 head->truesize += tail->len;
Alexander Duyckaa801752010-11-16 19:27:02 -08001236
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001237 IXGBE_CB(tail)->head = NULL;
1238
1239 return head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001240}
1241
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001242/**
1243 * ixgbe_add_active_tail - adds an active tail into the skb frag_list
1244 * @head: pointer to the start of the skb
1245 * @tail: pointer to active tail to add to frag_list
1246 *
1247 * This function adds an active tail to the end of the frag list. This tail
1248 * will still be receiving data so we cannot yet ad it's stats to the main
1249 * skb. That is done via ixgbe_merge_active_tail.
1250 **/
1251static inline void ixgbe_add_active_tail(struct sk_buff *head,
1252 struct sk_buff *tail)
Alexander Duyckaa801752010-11-16 19:27:02 -08001253{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001254 struct sk_buff *old_tail = IXGBE_CB(head)->tail;
1255
1256 if (old_tail) {
1257 ixgbe_merge_active_tail(old_tail);
1258 old_tail->next = tail;
1259 } else {
1260 skb_shinfo(head)->frag_list = tail;
1261 }
1262
1263 IXGBE_CB(tail)->head = head;
1264 IXGBE_CB(head)->tail = tail;
1265}
1266
1267/**
1268 * ixgbe_close_active_frag_list - cleanup pointers on a frag_list skb
1269 * @head: pointer to head of an active frag list
1270 *
1271 * This function will clear the frag_tail_tracker pointer on an active
1272 * frag_list and returns true if the pointer was actually set
1273 **/
1274static inline bool ixgbe_close_active_frag_list(struct sk_buff *head)
1275{
1276 struct sk_buff *tail = IXGBE_CB(head)->tail;
1277
1278 if (!tail)
1279 return false;
1280
1281 ixgbe_merge_active_tail(tail);
1282
1283 IXGBE_CB(head)->tail = NULL;
1284
1285 return true;
1286}
1287
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001288/**
1289 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1290 * @data: pointer to the start of the headers
1291 * @max_len: total length of section to find headers in
1292 *
1293 * This function is meant to determine the length of headers that will
1294 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1295 * motivation of doing this is to only perform one pull for IPv4 TCP
1296 * packets so that we can do basic things like calculating the gso_size
1297 * based on the average data per packet.
1298 **/
1299static unsigned int ixgbe_get_headlen(unsigned char *data,
1300 unsigned int max_len)
1301{
1302 union {
1303 unsigned char *network;
1304 /* l2 headers */
1305 struct ethhdr *eth;
1306 struct vlan_hdr *vlan;
1307 /* l3 headers */
1308 struct iphdr *ipv4;
1309 } hdr;
1310 __be16 protocol;
1311 u8 nexthdr = 0; /* default to not TCP */
1312 u8 hlen;
1313
1314 /* this should never happen, but better safe than sorry */
1315 if (max_len < ETH_HLEN)
1316 return max_len;
1317
1318 /* initialize network frame pointer */
1319 hdr.network = data;
1320
1321 /* set first protocol and move network header forward */
1322 protocol = hdr.eth->h_proto;
1323 hdr.network += ETH_HLEN;
1324
1325 /* handle any vlan tag if present */
1326 if (protocol == __constant_htons(ETH_P_8021Q)) {
1327 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1328 return max_len;
1329
1330 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1331 hdr.network += VLAN_HLEN;
1332 }
1333
1334 /* handle L3 protocols */
1335 if (protocol == __constant_htons(ETH_P_IP)) {
1336 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1337 return max_len;
1338
1339 /* access ihl as a u8 to avoid unaligned access on ia64 */
1340 hlen = (hdr.network[0] & 0x0F) << 2;
1341
1342 /* verify hlen meets minimum size requirements */
1343 if (hlen < sizeof(struct iphdr))
1344 return hdr.network - data;
1345
1346 /* record next protocol */
1347 nexthdr = hdr.ipv4->protocol;
1348 hdr.network += hlen;
1349#ifdef CONFIG_FCOE
1350 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1351 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1352 return max_len;
1353 hdr.network += FCOE_HEADER_LEN;
1354#endif
1355 } else {
1356 return hdr.network - data;
1357 }
1358
1359 /* finally sort out TCP */
1360 if (nexthdr == IPPROTO_TCP) {
1361 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1362 return max_len;
1363
1364 /* access doff as a u8 to avoid unaligned access on ia64 */
1365 hlen = (hdr.network[12] & 0xF0) >> 2;
1366
1367 /* verify hlen meets minimum size requirements */
1368 if (hlen < sizeof(struct tcphdr))
1369 return hdr.network - data;
1370
1371 hdr.network += hlen;
1372 }
1373
1374 /*
1375 * If everything has gone correctly hdr.network should be the
1376 * data section of the packet and will be the end of the header.
1377 * If not then it probably represents the end of the last recognized
1378 * header.
1379 */
1380 if ((hdr.network - data) < max_len)
1381 return hdr.network - data;
1382 else
1383 return max_len;
1384}
1385
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001386static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1387 union ixgbe_adv_rx_desc *rx_desc,
1388 struct sk_buff *skb)
1389{
1390 __le32 rsc_enabled;
1391 u32 rsc_cnt;
1392
1393 if (!ring_is_rsc_enabled(rx_ring))
1394 return;
1395
1396 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1397 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1398
1399 /* If this is an RSC frame rsc_cnt should be non-zero */
1400 if (!rsc_enabled)
1401 return;
1402
1403 rsc_cnt = le32_to_cpu(rsc_enabled);
1404 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1405
1406 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001407}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001408
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001409static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1410 struct sk_buff *skb)
1411{
1412 u16 hdr_len = ixgbe_get_headlen(skb->data, skb_headlen(skb));
1413
1414 /* set gso_size to avoid messing up TCP MSS */
1415 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1416 IXGBE_CB(skb)->append_cnt);
1417}
1418
1419static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1420 struct sk_buff *skb)
1421{
1422 /* if append_cnt is 0 then frame is not RSC */
1423 if (!IXGBE_CB(skb)->append_cnt)
1424 return;
1425
1426 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1427 rx_ring->rx_stats.rsc_flush++;
1428
1429 ixgbe_set_rsc_gso_size(rx_ring, skb);
1430
1431 /* gso_size is computed using append_cnt so always clear it last */
1432 IXGBE_CB(skb)->append_cnt = 0;
1433}
1434
Alexander Duyck8a0da212012-01-31 02:59:49 +00001435/**
1436 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1437 * @rx_ring: rx descriptor ring packet is being transacted on
1438 * @rx_desc: pointer to the EOP Rx descriptor
1439 * @skb: pointer to current skb being populated
1440 *
1441 * This function checks the ring, descriptor, and packet information in
1442 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1443 * other fields within the skb.
1444 **/
1445static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1446 union ixgbe_adv_rx_desc *rx_desc,
1447 struct sk_buff *skb)
1448{
1449 ixgbe_update_rsc_stats(rx_ring, skb);
1450
1451 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1452
1453 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1454
1455 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1456 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1457 __vlan_hwaccel_put_tag(skb, vid);
1458 }
1459
1460 skb_record_rx_queue(skb, rx_ring->queue_index);
1461
1462 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1463}
1464
1465static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1466 struct sk_buff *skb)
1467{
1468 struct ixgbe_adapter *adapter = q_vector->adapter;
1469
1470 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1471 napi_gro_receive(&q_vector->napi, skb);
1472 else
1473 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001474}
1475
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001476static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001477 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001478 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001479{
Auke Kok9a799d72007-09-15 14:07:45 -07001480 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001481 struct ixgbe_rx_buffer *rx_buffer_info;
Auke Kok9a799d72007-09-15 14:07:45 -07001482 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001483 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001484 const int current_node = numa_node_id();
Alexander Duyck8a0da212012-01-31 02:59:49 +00001485 struct ixgbe_adapter *adapter = q_vector->adapter;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001486#ifdef IXGBE_FCOE
Yi Zou3d8fd382009-06-08 14:38:44 +00001487 int ddp_bytes = 0;
1488#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001489 u16 i;
1490 u16 cleaned_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001491
1492 i = rx_ring->next_to_clean;
Alexander Duycke4f74022012-01-31 02:59:44 +00001493 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001495 while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001496 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001497
Milton Miller3c945e52010-02-19 17:44:42 +00001498 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001499
Alexander Duyckc267fc12010-11-16 19:27:00 -08001500 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1501
Auke Kok9a799d72007-09-15 14:07:45 -07001502 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001503 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001504 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001505
David S. Miller8decf862011-09-22 03:23:13 -04001506 /* linear means we are building an skb from multiple pages */
1507 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001508 u16 hlen;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001509 if (ring_is_ps_enabled(rx_ring)) {
1510 hlen = ixgbe_get_hlen(rx_desc);
1511 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1512 } else {
1513 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1514 }
1515
1516 skb_put(skb, hlen);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001517
1518 /*
1519 * Delay unmapping of the first packet. It carries the
1520 * header information, HW may still access the header
1521 * after writeback. Only unmap it when EOP is reached
1522 */
1523 if (!IXGBE_CB(skb)->head) {
1524 IXGBE_CB(skb)->delay_unmap = true;
1525 IXGBE_CB(skb)->dma = rx_buffer_info->dma;
1526 } else {
1527 skb = ixgbe_merge_active_tail(skb);
1528 dma_unmap_single(rx_ring->dev,
1529 rx_buffer_info->dma,
1530 rx_ring->rx_buf_len,
1531 DMA_FROM_DEVICE);
1532 }
1533 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001534 } else {
1535 /* assume packet split since header is unmapped */
1536 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001537 }
1538
1539 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001540 dma_unmap_page(rx_ring->dev,
1541 rx_buffer_info->page_dma,
1542 PAGE_SIZE / 2,
1543 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001544 rx_buffer_info->page_dma = 0;
1545 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001546 rx_buffer_info->page,
1547 rx_buffer_info->page_offset,
1548 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001549
Alexander Duyckc267fc12010-11-16 19:27:00 -08001550 if ((page_count(rx_buffer_info->page) == 1) &&
1551 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001552 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001553 else
1554 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001555
1556 skb->len += upper_len;
1557 skb->data_len += upper_len;
Eric Dumazet98130642011-10-13 07:59:41 +00001558 skb->truesize += PAGE_SIZE / 2;
Auke Kok9a799d72007-09-15 14:07:45 -07001559 }
1560
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001561 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1562
Auke Kok9a799d72007-09-15 14:07:45 -07001563 i++;
1564 if (i == rx_ring->count)
1565 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001566
Alexander Duycke4f74022012-01-31 02:59:44 +00001567 next_rxd = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001568 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001569 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001570
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001571 if ((!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001572 struct ixgbe_rx_buffer *next_buffer;
1573 u32 nextp;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001574
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001575 if (IXGBE_CB(skb)->append_cnt) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001576 nextp = le32_to_cpu(
1577 rx_desc->wb.upper.status_error);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001578 nextp >>= IXGBE_RXDADV_NEXTP_SHIFT;
1579 } else {
1580 nextp = i;
1581 }
1582
1583 next_buffer = &rx_ring->rx_buffer_info[nextp];
1584
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001585 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001586 rx_buffer_info->skb = next_buffer->skb;
1587 rx_buffer_info->dma = next_buffer->dma;
1588 next_buffer->skb = skb;
1589 next_buffer->dma = 0;
1590 } else {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001591 struct sk_buff *next_skb = next_buffer->skb;
1592 ixgbe_add_active_tail(skb, next_skb);
1593 IXGBE_CB(next_skb)->head = skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001594 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001595 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001596 goto next_desc;
1597 }
1598
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001599 dma_unmap_single(rx_ring->dev,
1600 IXGBE_CB(skb)->dma,
1601 rx_ring->rx_buf_len,
1602 DMA_FROM_DEVICE);
1603 IXGBE_CB(skb)->dma = 0;
1604 IXGBE_CB(skb)->delay_unmap = false;
1605
1606 if (ixgbe_close_active_frag_list(skb) &&
1607 !IXGBE_CB(skb)->append_cnt) {
Alexander Duyckaa801752010-11-16 19:27:02 -08001608 /* if we got here without RSC the packet is invalid */
Alexander Duyckff886df2011-06-11 01:45:13 +00001609 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001610 goto next_desc;
1611 }
1612
Auke Kok9a799d72007-09-15 14:07:45 -07001613 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001614 if (unlikely(ixgbe_test_staterr(rx_desc,
Ben Greear3f2d1c02012-03-08 08:28:41 +00001615 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1616 !(adapter->netdev->features & NETIF_F_RXALL))) {
Auke Kok9a799d72007-09-15 14:07:45 -07001617 dev_kfree_skb_any(skb);
1618 goto next_desc;
1619 }
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001620
1621 /* probably a little skewed due to removing CRC */
1622 total_rx_bytes += skb->len;
1623 total_rx_packets++;
1624
Alexander Duyck8a0da212012-01-31 02:59:49 +00001625 /* populate checksum, timestamp, VLAN, and protocol */
1626 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1627
Yi Zou332d4a72009-05-13 13:11:53 +00001628#ifdef IXGBE_FCOE
1629 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001630 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001631 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001632 if (!ddp_bytes) {
1633 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001634 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001635 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001636 }
Yi Zou332d4a72009-05-13 13:11:53 +00001637#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001638 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001639
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001640 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001641next_desc:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001642 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001643 break;
1644
Auke Kok9a799d72007-09-15 14:07:45 -07001645 /* return some buffers to hardware, one at a time is too slow */
1646 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001647 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001648 cleaned_count = 0;
1649 }
1650
1651 /* use prefetched values */
1652 rx_desc = next_rxd;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001653 }
1654
Auke Kok9a799d72007-09-15 14:07:45 -07001655 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001656 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001657
1658 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001659 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001660
Yi Zou3d8fd382009-06-08 14:38:44 +00001661#ifdef IXGBE_FCOE
1662 /* include DDPed FCoE data */
1663 if (ddp_bytes > 0) {
1664 unsigned int mss;
1665
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001666 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001667 sizeof(struct fc_frame_header) -
1668 sizeof(struct fcoe_crc_eof);
1669 if (mss > 512)
1670 mss &= ~511;
1671 total_rx_bytes += ddp_bytes;
1672 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1673 }
1674#endif /* IXGBE_FCOE */
1675
Alexander Duyckc267fc12010-11-16 19:27:00 -08001676 u64_stats_update_begin(&rx_ring->syncp);
1677 rx_ring->stats.packets += total_rx_packets;
1678 rx_ring->stats.bytes += total_rx_bytes;
1679 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001680 q_vector->rx.total_packets += total_rx_packets;
1681 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001682
1683 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001684}
1685
Auke Kok9a799d72007-09-15 14:07:45 -07001686/**
1687 * ixgbe_configure_msix - Configure MSI-X hardware
1688 * @adapter: board private structure
1689 *
1690 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1691 * interrupts.
1692 **/
1693static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1694{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001695 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001696 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001697 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001698
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001699 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1700
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001701 /* Populate MSIX to EITR Select */
1702 if (adapter->num_vfs > 32) {
1703 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1704 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1705 }
1706
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001707 /*
1708 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001709 * corresponding register.
1710 */
1711 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001712 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001713 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001714
Alexander Duycka5579282012-02-08 07:50:04 +00001715 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001716 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001717
Alexander Duycka5579282012-02-08 07:50:04 +00001718 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001719 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001720
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001721 if (q_vector->tx.ring && !q_vector->rx.ring) {
1722 /* tx only vector */
1723 if (adapter->tx_itr_setting == 1)
1724 q_vector->itr = IXGBE_10K_ITR;
1725 else
1726 q_vector->itr = adapter->tx_itr_setting;
1727 } else {
1728 /* rx or rx/tx vector */
1729 if (adapter->rx_itr_setting == 1)
1730 q_vector->itr = IXGBE_20K_ITR;
1731 else
1732 q_vector->itr = adapter->rx_itr_setting;
1733 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001734
Alexander Duyckfe49f042009-06-04 16:00:09 +00001735 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001736 }
1737
Alexander Duyckbd508172010-11-16 19:27:03 -08001738 switch (adapter->hw.mac.type) {
1739 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001740 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001741 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001742 break;
1743 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001744 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001745 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001746 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001747 default:
1748 break;
1749 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001750 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001751
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001752 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001753 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001754 mask &= ~(IXGBE_EIMS_OTHER |
1755 IXGBE_EIMS_MAILBOX |
1756 IXGBE_EIMS_LSC);
1757
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001758 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001759}
1760
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001761enum latency_range {
1762 lowest_latency = 0,
1763 low_latency = 1,
1764 bulk_latency = 2,
1765 latency_invalid = 255
1766};
1767
1768/**
1769 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001770 * @q_vector: structure containing interrupt and ring information
1771 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001772 *
1773 * Stores a new ITR value based on packets and byte
1774 * counts during the last interrupt. The advantage of per interrupt
1775 * computation is faster updates and more accurate ITR for the current
1776 * traffic pattern. Constants in this function were computed
1777 * based on theoretical maximum wire speed and thresholds were set based
1778 * on testing data as well as attempting to minimize response time
1779 * while increasing bulk throughput.
1780 * this functionality is controlled by the InterruptThrottleRate module
1781 * parameter (see ixgbe_param.c)
1782 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001783static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1784 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001785{
Alexander Duyckbd198052011-06-11 01:45:08 +00001786 int bytes = ring_container->total_bytes;
1787 int packets = ring_container->total_packets;
1788 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001789 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001790 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001791
1792 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001793 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001794
1795 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001796 * 0-10MB/s lowest (100000 ints/s)
1797 * 10-20MB/s low (20000 ints/s)
1798 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001799 */
1800 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001801 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001802 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1803
1804 switch (itr_setting) {
1805 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001806 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001807 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001808 break;
1809 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001810 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001811 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001812 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001813 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001814 break;
1815 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001816 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001817 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001818 break;
1819 }
1820
Alexander Duyckbd198052011-06-11 01:45:08 +00001821 /* clear work counters since we have the values we need */
1822 ring_container->total_bytes = 0;
1823 ring_container->total_packets = 0;
1824
1825 /* write updated itr to ring container */
1826 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001827}
1828
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001829/**
1830 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001831 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001832 *
1833 * This function is made to be called by ethtool and by the driver
1834 * when it needs to update EITR registers at runtime. Hardware
1835 * specific quirks/differences are taken care of here.
1836 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001837void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001838{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001839 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001840 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001841 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001842 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001843
Alexander Duyckbd508172010-11-16 19:27:03 -08001844 switch (adapter->hw.mac.type) {
1845 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001846 /* must write high and low 16 bits to reset counter */
1847 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001848 break;
1849 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001850 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001851 /*
1852 * set the WDIS bit to not clear the timer bits and cause an
1853 * immediate assertion of the interrupt
1854 */
1855 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001856 break;
1857 default:
1858 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001859 }
1860 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1861}
1862
Alexander Duyckbd198052011-06-11 01:45:08 +00001863static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001864{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001865 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001866 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001867
Alexander Duyckbd198052011-06-11 01:45:08 +00001868 ixgbe_update_itr(q_vector, &q_vector->tx);
1869 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001870
Alexander Duyck08c88332011-06-11 01:45:03 +00001871 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001872
1873 switch (current_itr) {
1874 /* counts and packets in update_itr are dependent on these numbers */
1875 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001876 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001877 break;
1878 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001879 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001880 break;
1881 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001882 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001883 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001884 default:
1885 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001886 }
1887
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001888 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001889 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001890 new_itr = (10 * new_itr * q_vector->itr) /
1891 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001892
Alexander Duyckbd198052011-06-11 01:45:08 +00001893 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001894 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001895
1896 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001897 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001898}
1899
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001900/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00001901 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00001902 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001903 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001904static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001905{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001906 struct ixgbe_hw *hw = &adapter->hw;
1907 u32 eicr = adapter->interrupt_event;
1908
Alexander Duyckf0f97782011-04-22 04:08:09 +00001909 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001910 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001911
Alexander Duyckf0f97782011-04-22 04:08:09 +00001912 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1913 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1914 return;
1915
1916 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1917
Joe Perches7ca647b2010-09-07 21:35:40 +00001918 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001919 case IXGBE_DEV_ID_82599_T3_LOM:
1920 /*
1921 * Since the warning interrupt is for both ports
1922 * we don't have to check if:
1923 * - This interrupt wasn't for our port.
1924 * - We may have missed the interrupt so always have to
1925 * check if we got a LSC
1926 */
1927 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1928 !(eicr & IXGBE_EICR_LSC))
1929 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001930
Alexander Duyckf0f97782011-04-22 04:08:09 +00001931 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1932 u32 autoneg;
1933 bool link_up = false;
1934
Joe Perches7ca647b2010-09-07 21:35:40 +00001935 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1936
Alexander Duyckf0f97782011-04-22 04:08:09 +00001937 if (link_up)
1938 return;
1939 }
1940
1941 /* Check if this is not due to overtemp */
1942 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1943 return;
1944
1945 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001946 default:
1947 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1948 return;
1949 break;
1950 }
1951 e_crit(drv,
1952 "Network adapter has been stopped because it has over heated. "
1953 "Restart the computer. If the problem persists, "
1954 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001955
1956 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001957}
1958
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001959static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1960{
1961 struct ixgbe_hw *hw = &adapter->hw;
1962
1963 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1964 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001965 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001966 /* write to clear the interrupt */
1967 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1968 }
1969}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001970
Jacob Keller4f51bf72011-08-20 04:49:45 +00001971static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1972{
1973 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1974 return;
1975
1976 switch (adapter->hw.mac.type) {
1977 case ixgbe_mac_82599EB:
1978 /*
1979 * Need to check link state so complete overtemp check
1980 * on service task
1981 */
1982 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1983 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1984 adapter->interrupt_event = eicr;
1985 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1986 ixgbe_service_event_schedule(adapter);
1987 return;
1988 }
1989 return;
1990 case ixgbe_mac_X540:
1991 if (!(eicr & IXGBE_EICR_TS))
1992 return;
1993 break;
1994 default:
1995 return;
1996 }
1997
1998 e_crit(drv,
1999 "Network adapter has been stopped because it has over heated. "
2000 "Restart the computer. If the problem persists, "
2001 "power off the system and replace the adapter\n");
2002}
2003
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002004static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2005{
2006 struct ixgbe_hw *hw = &adapter->hw;
2007
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002008 if (eicr & IXGBE_EICR_GPI_SDP2) {
2009 /* Clear the interrupt */
2010 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002011 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2012 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2013 ixgbe_service_event_schedule(adapter);
2014 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002015 }
2016
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002017 if (eicr & IXGBE_EICR_GPI_SDP1) {
2018 /* Clear the interrupt */
2019 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002020 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2021 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2022 ixgbe_service_event_schedule(adapter);
2023 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002024 }
2025}
2026
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002027static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2028{
2029 struct ixgbe_hw *hw = &adapter->hw;
2030
2031 adapter->lsc_int++;
2032 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2033 adapter->link_check_timeout = jiffies;
2034 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2035 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002036 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002037 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002038 }
2039}
2040
Alexander Duyckfe49f042009-06-04 16:00:09 +00002041static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2042 u64 qmask)
2043{
2044 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002045 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002046
Alexander Duyckbd508172010-11-16 19:27:03 -08002047 switch (hw->mac.type) {
2048 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002049 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002050 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2051 break;
2052 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002053 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002054 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002055 if (mask)
2056 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002057 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002058 if (mask)
2059 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2060 break;
2061 default:
2062 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002063 }
2064 /* skip the flush */
2065}
2066
2067static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002068 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002069{
2070 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002071 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002072
Alexander Duyckbd508172010-11-16 19:27:03 -08002073 switch (hw->mac.type) {
2074 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002075 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002076 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2077 break;
2078 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002079 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002080 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002081 if (mask)
2082 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002083 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002084 if (mask)
2085 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2086 break;
2087 default:
2088 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002089 }
2090 /* skip the flush */
2091}
2092
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002093/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002094 * ixgbe_irq_enable - Enable default interrupt generation settings
2095 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002096 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002097static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2098 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002099{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002100 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002101
Alexander Duyck2c4af692011-07-15 07:29:55 +00002102 /* don't reenable LSC while waiting for link */
2103 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2104 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002105
Alexander Duyck2c4af692011-07-15 07:29:55 +00002106 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002107 switch (adapter->hw.mac.type) {
2108 case ixgbe_mac_82599EB:
2109 mask |= IXGBE_EIMS_GPI_SDP0;
2110 break;
2111 case ixgbe_mac_X540:
2112 mask |= IXGBE_EIMS_TS;
2113 break;
2114 default:
2115 break;
2116 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002117 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2118 mask |= IXGBE_EIMS_GPI_SDP1;
2119 switch (adapter->hw.mac.type) {
2120 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002121 mask |= IXGBE_EIMS_GPI_SDP1;
2122 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002123 case ixgbe_mac_X540:
2124 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002125 mask |= IXGBE_EIMS_MAILBOX;
2126 break;
2127 default:
2128 break;
2129 }
2130 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2131 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2132 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002133
Alexander Duyck2c4af692011-07-15 07:29:55 +00002134 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2135 if (queues)
2136 ixgbe_irq_enable_queues(adapter, ~0);
2137 if (flush)
2138 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002139}
2140
Alexander Duyck2c4af692011-07-15 07:29:55 +00002141static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002142{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002143 struct ixgbe_adapter *adapter = data;
2144 struct ixgbe_hw *hw = &adapter->hw;
2145 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002146
Alexander Duyck2c4af692011-07-15 07:29:55 +00002147 /*
2148 * Workaround for Silicon errata. Use clear-by-write instead
2149 * of clear-by-read. Reading with EICS will return the
2150 * interrupt causes without clearing, which later be done
2151 * with the write to EICR.
2152 */
2153 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2154 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002155
Alexander Duyck2c4af692011-07-15 07:29:55 +00002156 if (eicr & IXGBE_EICR_LSC)
2157 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002158
Alexander Duyck2c4af692011-07-15 07:29:55 +00002159 if (eicr & IXGBE_EICR_MAILBOX)
2160 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002161
Alexander Duyck2c4af692011-07-15 07:29:55 +00002162 switch (hw->mac.type) {
2163 case ixgbe_mac_82599EB:
2164 case ixgbe_mac_X540:
2165 if (eicr & IXGBE_EICR_ECC)
2166 e_info(link, "Received unrecoverable ECC Err, please "
2167 "reboot\n");
2168 /* Handle Flow Director Full threshold interrupt */
2169 if (eicr & IXGBE_EICR_FLOW_DIR) {
2170 int reinit_count = 0;
2171 int i;
2172 for (i = 0; i < adapter->num_tx_queues; i++) {
2173 struct ixgbe_ring *ring = adapter->tx_ring[i];
2174 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2175 &ring->state))
2176 reinit_count++;
2177 }
2178 if (reinit_count) {
2179 /* no more flow director interrupts until after init */
2180 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2181 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2182 ixgbe_service_event_schedule(adapter);
2183 }
2184 }
2185 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002186 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002187 break;
2188 default:
2189 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002190 }
2191
Alexander Duyck2c4af692011-07-15 07:29:55 +00002192 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002193
Alexander Duyck2c4af692011-07-15 07:29:55 +00002194 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002195 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002196 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002197
Alexander Duyck2c4af692011-07-15 07:29:55 +00002198 return IRQ_HANDLED;
2199}
2200
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002201static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002202{
2203 struct ixgbe_q_vector *q_vector = data;
2204
Auke Kok9a799d72007-09-15 14:07:45 -07002205 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002206
2207 if (q_vector->rx.ring || q_vector->tx.ring)
2208 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002209
2210 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002211}
2212
Auke Kok9a799d72007-09-15 14:07:45 -07002213/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002214 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2215 * @adapter: board private structure
2216 *
2217 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2218 * interrupts from the kernel.
2219 **/
2220static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2221{
2222 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002223 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2224 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002225 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002227 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002228 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002229 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002230
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002231 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002232 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002233 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002234 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002235 } else if (q_vector->rx.ring) {
2236 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2237 "%s-%s-%d", netdev->name, "rx", ri++);
2238 } else if (q_vector->tx.ring) {
2239 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2240 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002241 } else {
2242 /* skip this unused q_vector */
2243 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002244 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002245 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2246 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002248 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002249 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002250 goto free_queue_irqs;
2251 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002252 /* If Flow Director is enabled, set interrupt affinity */
2253 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2254 /* assign the mask for this irq */
2255 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002256 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002257 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002258 }
2259
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002260 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002261 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002262 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002263 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002264 goto free_queue_irqs;
2265 }
2266
2267 return 0;
2268
2269free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002270 while (vector) {
2271 vector--;
2272 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2273 NULL);
2274 free_irq(adapter->msix_entries[vector].vector,
2275 adapter->q_vector[vector]);
2276 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002277 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2278 pci_disable_msix(adapter->pdev);
2279 kfree(adapter->msix_entries);
2280 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002281 return err;
2282}
2283
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002284/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002285 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002286 * @irq: interrupt number
2287 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002288 **/
2289static irqreturn_t ixgbe_intr(int irq, void *data)
2290{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002291 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002292 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002293 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002294 u32 eicr;
2295
Don Skidmore54037502009-02-21 15:42:56 -08002296 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002297 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002298 * before the read of EICR.
2299 */
2300 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2301
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002302 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002303 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002304 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002305 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002306 /*
2307 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002308 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002309 * have disabled interrupts due to EIAM
2310 * finish the workaround of silicon errata on 82598. Unmask
2311 * the interrupt that we masked before the EICR read.
2312 */
2313 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2314 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002315 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002316 }
Auke Kok9a799d72007-09-15 14:07:45 -07002317
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002318 if (eicr & IXGBE_EICR_LSC)
2319 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002320
Alexander Duyckbd508172010-11-16 19:27:03 -08002321 switch (hw->mac.type) {
2322 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002323 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002324 /* Fall through */
2325 case ixgbe_mac_X540:
2326 if (eicr & IXGBE_EICR_ECC)
2327 e_info(link, "Received unrecoverable ECC err, please "
2328 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002329 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002330 break;
2331 default:
2332 break;
2333 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002334
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002335 ixgbe_check_fan_failure(adapter, eicr);
2336
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002337 /* would disable interrupts here but EIAM disabled it */
2338 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002339
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002340 /*
2341 * re-enable link(maybe) and non-queue interrupts, no flush.
2342 * ixgbe_poll will re-enable the queue interrupts
2343 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002344 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2345 ixgbe_irq_enable(adapter, false, false);
2346
Auke Kok9a799d72007-09-15 14:07:45 -07002347 return IRQ_HANDLED;
2348}
2349
2350/**
2351 * ixgbe_request_irq - initialize interrupts
2352 * @adapter: board private structure
2353 *
2354 * Attempts to configure interrupts using the best available
2355 * capabilities of the hardware and kernel.
2356 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002357static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002358{
2359 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002360 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002361
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002362 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002363 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002364 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002365 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002366 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002367 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002368 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002369 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002370
Alexander Duyckde88eee2012-02-08 07:49:59 +00002371 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002372 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002373
Auke Kok9a799d72007-09-15 14:07:45 -07002374 return err;
2375}
2376
2377static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2378{
Auke Kok9a799d72007-09-15 14:07:45 -07002379 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002380 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002381
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002382 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002383 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002384 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002385 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002386
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002387 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002388 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002389 if (!adapter->q_vector[i]->rx.ring &&
2390 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002391 continue;
2392
Alexander Duyck207867f2011-07-15 03:05:37 +00002393 /* clear the affinity_mask in the IRQ descriptor */
2394 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2395 NULL);
2396
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002397 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002398 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002399 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002400 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002401 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002402 }
2403}
2404
2405/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002406 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2407 * @adapter: board private structure
2408 **/
2409static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2410{
Alexander Duyckbd508172010-11-16 19:27:03 -08002411 switch (adapter->hw.mac.type) {
2412 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002413 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002414 break;
2415 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002416 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002417 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2418 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002419 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002420 break;
2421 default:
2422 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002423 }
2424 IXGBE_WRITE_FLUSH(&adapter->hw);
2425 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2426 int i;
2427 for (i = 0; i < adapter->num_msix_vectors; i++)
2428 synchronize_irq(adapter->msix_entries[i].vector);
2429 } else {
2430 synchronize_irq(adapter->pdev->irq);
2431 }
2432}
2433
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002434/**
Auke Kok9a799d72007-09-15 14:07:45 -07002435 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2436 *
2437 **/
2438static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2439{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002440 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002441
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002442 /* rx/tx vector */
2443 if (adapter->rx_itr_setting == 1)
2444 q_vector->itr = IXGBE_20K_ITR;
2445 else
2446 q_vector->itr = adapter->rx_itr_setting;
2447
2448 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002449
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002450 ixgbe_set_ivar(adapter, 0, 0, 0);
2451 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452
Emil Tantilov396e7992010-07-01 20:05:12 +00002453 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002454}
2455
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002456/**
2457 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2458 * @adapter: board private structure
2459 * @ring: structure containing ring specific data
2460 *
2461 * Configure the Tx descriptor ring after a reset.
2462 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002463void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2464 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002465{
2466 struct ixgbe_hw *hw = &adapter->hw;
2467 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002468 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002469 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002470 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002471
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002472 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002473 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002474 IXGBE_WRITE_FLUSH(hw);
2475
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002476 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002477 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002478 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2479 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2480 ring->count * sizeof(union ixgbe_adv_tx_desc));
2481 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2482 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002483 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002484
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002485 /*
2486 * set WTHRESH to encourage burst writeback, it should not be set
2487 * higher than 1 when ITR is 0 as it could cause false TX hangs
2488 *
2489 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2490 * to or less than the number of on chip descriptors, which is
2491 * currently 40.
2492 */
Alexander Duycke954b372012-02-08 07:49:38 +00002493 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002494 txdctl |= (1 << 16); /* WTHRESH = 1 */
2495 else
2496 txdctl |= (8 << 16); /* WTHRESH = 8 */
2497
Alexander Duycke954b372012-02-08 07:49:38 +00002498 /*
2499 * Setting PTHRESH to 32 both improves performance
2500 * and avoids a TX hang with DFP enabled
2501 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002502 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2503 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002504
2505 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002506 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2507 adapter->atr_sample_rate) {
2508 ring->atr_sample_rate = adapter->atr_sample_rate;
2509 ring->atr_count = 0;
2510 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2511 } else {
2512 ring->atr_sample_rate = 0;
2513 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002514
John Fastabendc84d3242010-11-16 19:27:12 -08002515 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2516
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002517 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002518 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2519
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002520 netdev_tx_reset_queue(txring_txq(ring));
2521
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002522 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2523 if (hw->mac.type == ixgbe_mac_82598EB &&
2524 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2525 return;
2526
2527 /* poll to verify queue is enabled */
2528 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002529 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002530 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2531 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2532 if (!wait_loop)
2533 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002534}
2535
Alexander Duyck120ff942010-08-19 13:34:50 +00002536static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2537{
2538 struct ixgbe_hw *hw = &adapter->hw;
2539 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002540 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002541 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002542
2543 if (hw->mac.type == ixgbe_mac_82598EB)
2544 return;
2545
2546 /* disable the arbiter while setting MTQC */
2547 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2548 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2549 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2550
2551 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002552 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002553 case (IXGBE_FLAG_SRIOV_ENABLED):
2554 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2555 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2556 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002557 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002558 if (!tcs)
2559 reg = IXGBE_MTQC_64Q_1PB;
2560 else if (tcs <= 4)
2561 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2562 else
2563 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2564
2565 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2566
2567 /* Enable Security TX Buffer IFG for multiple pb */
2568 if (tcs) {
2569 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2570 reg |= IXGBE_SECTX_DCB;
2571 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2572 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002573 break;
2574 }
2575
2576 /* re-enable the arbiter */
2577 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2578 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2579}
2580
Auke Kok9a799d72007-09-15 14:07:45 -07002581/**
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07002582 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002583 * @adapter: board private structure
2584 *
2585 * Configure the Tx unit of the MAC after a reset.
2586 **/
2587static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2588{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002589 struct ixgbe_hw *hw = &adapter->hw;
2590 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002591 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002592
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002593 ixgbe_setup_mtqc(adapter);
2594
2595 if (hw->mac.type != ixgbe_mac_82598EB) {
2596 /* DMATXCTL.EN must be before Tx queues are enabled */
2597 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2598 dmatxctl |= IXGBE_DMATXCTL_TE;
2599 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2600 }
2601
Auke Kok9a799d72007-09-15 14:07:45 -07002602 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002603 for (i = 0; i < adapter->num_tx_queues; i++)
2604 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002605}
2606
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002607#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002608
Yi Zoua6616b42009-08-06 13:05:23 +00002609static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002610 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002611{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002612 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002613 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002614
Alexander Duyckbd508172010-11-16 19:27:03 -08002615 switch (adapter->hw.mac.type) {
2616 case ixgbe_mac_82598EB: {
2617 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2618 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002619 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002620 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002621 break;
2622 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002623 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002624 default:
2625 break;
2626 }
2627
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002628 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002629
2630 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2631 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002632 if (adapter->num_vfs)
2633 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002634
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002635 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2636 IXGBE_SRRCTL_BSIZEHDR_MASK;
2637
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002638 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002639#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2640 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2641#else
2642 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2643#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002644 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002645 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002646 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2647 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002648 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002649 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002650
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002651 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002652}
2653
Alexander Duyck05abb122010-08-19 13:35:41 +00002654static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002655{
Alexander Duyck05abb122010-08-19 13:35:41 +00002656 struct ixgbe_hw *hw = &adapter->hw;
2657 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002658 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2659 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002660 u32 mrqc = 0, reta = 0;
2661 u32 rxcsum;
2662 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002663 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002664 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2665
2666 if (tcs)
2667 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002668
Alexander Duyck05abb122010-08-19 13:35:41 +00002669 /* Fill out hash function seeds */
2670 for (i = 0; i < 10; i++)
2671 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002672
Alexander Duyck05abb122010-08-19 13:35:41 +00002673 /* Fill out redirection table */
2674 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002675 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002676 j = 0;
2677 /* reta = 4-byte sliding window of
2678 * 0x00..(indices-1)(indices-1)00..etc. */
2679 reta = (reta << 8) | (j * 0x11);
2680 if ((i & 3) == 3)
2681 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2682 }
2683
2684 /* Disable indicating checksum in descriptor, enables RSS hash */
2685 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2686 rxcsum |= IXGBE_RXCSUM_PCSD;
2687 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2688
John Fastabend8b1c0b22011-05-03 02:26:48 +00002689 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2690 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002691 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002692 } else {
2693 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2694 | IXGBE_FLAG_SRIOV_ENABLED);
2695
2696 switch (mask) {
2697 case (IXGBE_FLAG_RSS_ENABLED):
2698 if (!tcs)
2699 mrqc = IXGBE_MRQC_RSSEN;
2700 else if (tcs <= 4)
2701 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2702 else
2703 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2704 break;
2705 case (IXGBE_FLAG_SRIOV_ENABLED):
2706 mrqc = IXGBE_MRQC_VMDQEN;
2707 break;
2708 default:
2709 break;
2710 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002711 }
2712
Alexander Duyck05abb122010-08-19 13:35:41 +00002713 /* Perform hash on these packet types */
2714 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2715 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2716 | IXGBE_MRQC_RSS_FIELD_IPV6
2717 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2718
2719 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002720}
2721
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002722/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002723 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2724 * @adapter: address of board private structure
2725 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002726 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002727static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002728 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002729{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002730 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002731 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002732 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002733 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002734
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002735 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002736 return;
2737
2738 rx_buf_len = ring->rx_buf_len;
2739 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002740 rscctrl |= IXGBE_RSCCTL_RSCEN;
2741 /*
2742 * we must limit the number of descriptors so that the
2743 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002744 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002745 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002746 if (ring_is_ps_enabled(ring)) {
Alexander Duyck642c6802011-11-10 09:09:17 +00002747#if (PAGE_SIZE < 8192)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002748 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002749#elif (PAGE_SIZE < 16384)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002750 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duyck642c6802011-11-10 09:09:17 +00002751#elif (PAGE_SIZE < 32768)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002752 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2753#else
2754 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2755#endif
2756 } else {
Alexander Duyck642c6802011-11-10 09:09:17 +00002757 if (rx_buf_len <= IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002758 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002759 else if (rx_buf_len <= IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002760 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2761 else
2762 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2763 }
Alexander Duyck73670962010-08-19 13:38:34 +00002764 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002765}
2766
Alexander Duyck9e10e042010-08-19 13:40:06 +00002767/**
2768 * ixgbe_set_uta - Set unicast filter table address
2769 * @adapter: board private structure
2770 *
2771 * The unicast table address is a register array of 32-bit registers.
2772 * The table is meant to be used in a way similar to how the MTA is used
2773 * however due to certain limitations in the hardware it is necessary to
2774 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2775 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2776 **/
2777static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2778{
2779 struct ixgbe_hw *hw = &adapter->hw;
2780 int i;
2781
2782 /* The UTA table only exists on 82599 hardware and newer */
2783 if (hw->mac.type < ixgbe_mac_82599EB)
2784 return;
2785
2786 /* we only need to do this if VMDq is enabled */
2787 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2788 return;
2789
2790 for (i = 0; i < 128; i++)
2791 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2792}
2793
2794#define IXGBE_MAX_RX_DESC_POLL 10
2795static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2796 struct ixgbe_ring *ring)
2797{
2798 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002799 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2800 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002801 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002802
2803 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2804 if (hw->mac.type == ixgbe_mac_82598EB &&
2805 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2806 return;
2807
2808 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002809 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002810 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2811 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2812
2813 if (!wait_loop) {
2814 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2815 "the polling period\n", reg_idx);
2816 }
2817}
2818
Yi Zou2d39d572011-01-06 14:29:56 +00002819void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2820 struct ixgbe_ring *ring)
2821{
2822 struct ixgbe_hw *hw = &adapter->hw;
2823 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2824 u32 rxdctl;
2825 u8 reg_idx = ring->reg_idx;
2826
2827 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2828 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2829
2830 /* write value back with RXDCTL.ENABLE bit cleared */
2831 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2832
2833 if (hw->mac.type == ixgbe_mac_82598EB &&
2834 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2835 return;
2836
2837 /* the hardware may take up to 100us to really disable the rx queue */
2838 do {
2839 udelay(10);
2840 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2841 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2842
2843 if (!wait_loop) {
2844 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2845 "the polling period\n", reg_idx);
2846 }
2847}
2848
Alexander Duyck84418e32010-08-19 13:40:54 +00002849void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2850 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002851{
2852 struct ixgbe_hw *hw = &adapter->hw;
2853 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002854 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002855 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002856
Alexander Duyck9e10e042010-08-19 13:40:06 +00002857 /* disable queue to avoid issues while updating state */
2858 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002859 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002860
Alexander Duyckacd37172010-08-19 13:36:05 +00002861 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2862 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2863 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2864 ring->count * sizeof(union ixgbe_adv_rx_desc));
2865 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2866 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002867 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002868
2869 ixgbe_configure_srrctl(adapter, ring);
2870 ixgbe_configure_rscctl(adapter, ring);
2871
Greg Rosee9f98072011-01-26 01:06:07 +00002872 /* If operating in IOV mode set RLPML for X540 */
2873 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2874 hw->mac.type == ixgbe_mac_X540) {
2875 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2876 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2877 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2878 }
2879
Alexander Duyck9e10e042010-08-19 13:40:06 +00002880 if (hw->mac.type == ixgbe_mac_82598EB) {
2881 /*
2882 * enable cache line friendly hardware writes:
2883 * PTHRESH=32 descriptors (half the internal cache),
2884 * this also removes ugly rx_no_buffer_count increment
2885 * HTHRESH=4 descriptors (to minimize latency on fetch)
2886 * WTHRESH=8 burst writeback up to two cache lines
2887 */
2888 rxdctl &= ~0x3FFFFF;
2889 rxdctl |= 0x080420;
2890 }
2891
2892 /* enable receive descriptor ring */
2893 rxdctl |= IXGBE_RXDCTL_ENABLE;
2894 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2895
2896 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002897 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002898}
2899
Alexander Duyck48654522010-08-19 13:36:27 +00002900static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2901{
2902 struct ixgbe_hw *hw = &adapter->hw;
2903 int p;
2904
2905 /* PSRTYPE must be initialized in non 82598 adapters */
2906 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002907 IXGBE_PSRTYPE_UDPHDR |
2908 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002909 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002910 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002911
2912 if (hw->mac.type == ixgbe_mac_82598EB)
2913 return;
2914
2915 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2916 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2917
2918 for (p = 0; p < adapter->num_rx_pools; p++)
2919 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2920 psrtype);
2921}
2922
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002923static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2924{
2925 struct ixgbe_hw *hw = &adapter->hw;
2926 u32 gcr_ext;
2927 u32 vt_reg_bits;
2928 u32 reg_offset, vf_shift;
2929 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00002930 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002931
2932 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2933 return;
2934
2935 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2936 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2937 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2938 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2939
2940 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00002941 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002942
2943 /* Enable only the PF's pool for Tx/Rx */
2944 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2945 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2946 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2947 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2948 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2949
2950 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2951 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
2952
2953 /*
2954 * Set up VF register offsets for selected VT Mode,
2955 * i.e. 32 or 64 VFs for SR-IOV
2956 */
2957 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
2958 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
2959 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
2960 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
2961
2962 /* enable Tx loopback for VF/PF communication */
2963 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00002964 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00002965 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00002966 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00002967 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00002968 /* For VFs that have spoof checking turned off */
2969 for (i = 0; i < adapter->num_vfs; i++) {
2970 if (!adapter->vfinfo[i].spoofchk_enabled)
2971 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
2972 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002973}
2974
Alexander Duyck477de6e2010-08-19 13:38:11 +00002975static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002976{
Auke Kok9a799d72007-09-15 14:07:45 -07002977 struct ixgbe_hw *hw = &adapter->hw;
2978 struct net_device *netdev = adapter->netdev;
2979 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002980 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00002981 struct ixgbe_ring *rx_ring;
2982 int i;
2983 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00002984
Auke Kok9a799d72007-09-15 14:07:45 -07002985 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00002986 /* On by default */
2987 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
2988
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002989 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00002990 if (adapter->num_vfs)
2991 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2992
2993 /* Disable packet split due to 82599 erratum #45 */
2994 if (hw->mac.type == ixgbe_mac_82599EB)
2995 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002996
Alexander Duyck477de6e2010-08-19 13:38:11 +00002997#ifdef IXGBE_FCOE
2998 /* adjust max frame to be able to do baby jumbo for FCoE */
2999 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3000 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3001 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3002
3003#endif /* IXGBE_FCOE */
3004 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3005 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3006 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3007 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3008
3009 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003010 }
3011
Alexander Duyck919e78a2011-08-26 09:52:38 +00003012 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3013 max_frame += VLAN_HLEN;
3014
3015 /* Set the RX buffer length according to the mode */
3016 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3017 rx_buf_len = IXGBE_RX_HDR_SIZE;
3018 } else {
3019 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3020 (netdev->mtu <= ETH_DATA_LEN))
3021 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3022 /*
3023 * Make best use of allocation by using all but 1K of a
3024 * power of 2 allocation that will be used for skb->head.
3025 */
3026 else if (max_frame <= IXGBE_RXBUFFER_3K)
3027 rx_buf_len = IXGBE_RXBUFFER_3K;
3028 else if (max_frame <= IXGBE_RXBUFFER_7K)
3029 rx_buf_len = IXGBE_RXBUFFER_7K;
3030 else if (max_frame <= IXGBE_RXBUFFER_15K)
3031 rx_buf_len = IXGBE_RXBUFFER_15K;
3032 else
3033 rx_buf_len = IXGBE_MAX_RXBUFFER;
3034 }
3035
Auke Kok9a799d72007-09-15 14:07:45 -07003036 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003037 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3038 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003039 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3040
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003041 /*
3042 * Setup the HW Rx Head and Tail Descriptor Pointers and
3043 * the Base and Length of the Rx Descriptor Ring
3044 */
Auke Kok9a799d72007-09-15 14:07:45 -07003045 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003046 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003047 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003048
Yi Zou6e455b892009-08-06 13:05:44 +00003049 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003050 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003051 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003052 clear_ring_ps_enabled(rx_ring);
3053
3054 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3055 set_ring_rsc_enabled(rx_ring);
3056 else
3057 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003058
Yi Zou63f39bd2009-05-17 12:34:35 +00003059#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003060 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003061 struct ixgbe_ring_feature *f;
3062 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003063 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003064 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003065 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3066 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003067 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003068 } else if (!ring_is_rsc_enabled(rx_ring) &&
3069 !ring_is_ps_enabled(rx_ring)) {
3070 rx_ring->rx_buf_len =
3071 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003072 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003073 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003074#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003075 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003076}
3077
Alexander Duyck73670962010-08-19 13:38:34 +00003078static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3079{
3080 struct ixgbe_hw *hw = &adapter->hw;
3081 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3082
3083 switch (hw->mac.type) {
3084 case ixgbe_mac_82598EB:
3085 /*
3086 * For VMDq support of different descriptor types or
3087 * buffer sizes through the use of multiple SRRCTL
3088 * registers, RDRXCTL.MVMEN must be set to 1
3089 *
3090 * also, the manual doesn't mention it clearly but DCA hints
3091 * will only use queue 0's tags unless this bit is set. Side
3092 * effects of setting this bit are only that SRRCTL must be
3093 * fully programmed [0..15]
3094 */
3095 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3096 break;
3097 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003098 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003099 /* Disable RSC for ACK packets */
3100 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3101 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3102 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3103 /* hardware requires some bits to be set by default */
3104 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3105 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3106 break;
3107 default:
3108 /* We should do nothing since we don't know this hardware */
3109 return;
3110 }
3111
3112 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3113}
3114
Alexander Duyck477de6e2010-08-19 13:38:11 +00003115/**
3116 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3117 * @adapter: board private structure
3118 *
3119 * Configure the Rx unit of the MAC after a reset.
3120 **/
3121static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3122{
3123 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003124 int i;
3125 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003126
3127 /* disable receives while setting up the descriptors */
3128 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3129 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3130
3131 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003132 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003133
Alexander Duyck9e10e042010-08-19 13:40:06 +00003134 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003135 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003136
Alexander Duyck9e10e042010-08-19 13:40:06 +00003137 ixgbe_set_uta(adapter);
3138
Alexander Duyck477de6e2010-08-19 13:38:11 +00003139 /* set_rx_buffer_len must be called before ring initialization */
3140 ixgbe_set_rx_buffer_len(adapter);
3141
3142 /*
3143 * Setup the HW Rx Head and Tail Descriptor Pointers and
3144 * the Base and Length of the Rx Descriptor Ring
3145 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003146 for (i = 0; i < adapter->num_rx_queues; i++)
3147 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003148
Alexander Duyck9e10e042010-08-19 13:40:06 +00003149 /* disable drop enable for 82598 parts */
3150 if (hw->mac.type == ixgbe_mac_82598EB)
3151 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3152
3153 /* enable all receives */
3154 rxctrl |= IXGBE_RXCTRL_RXEN;
3155 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003156}
3157
Jiri Pirko8e586132011-12-08 19:52:37 -05003158static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003159{
3160 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003161 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003162 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003163
3164 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003165 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003166 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003167
3168 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003169}
3170
Jiri Pirko8e586132011-12-08 19:52:37 -05003171static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003172{
3173 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003174 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003175 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003176
Auke Kok9a799d72007-09-15 14:07:45 -07003177 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003178 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003179 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003180
3181 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003182}
3183
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003184/**
3185 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3186 * @adapter: driver data
3187 */
3188static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3189{
3190 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003191 u32 vlnctrl;
3192
3193 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3194 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3195 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3196}
3197
3198/**
3199 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3200 * @adapter: driver data
3201 */
3202static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3203{
3204 struct ixgbe_hw *hw = &adapter->hw;
3205 u32 vlnctrl;
3206
3207 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3208 vlnctrl |= IXGBE_VLNCTRL_VFE;
3209 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3210 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3211}
3212
3213/**
3214 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3215 * @adapter: driver data
3216 */
3217static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3218{
3219 struct ixgbe_hw *hw = &adapter->hw;
3220 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003221 int i, j;
3222
3223 switch (hw->mac.type) {
3224 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003225 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3226 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003227 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3228 break;
3229 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003230 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003231 for (i = 0; i < adapter->num_rx_queues; i++) {
3232 j = adapter->rx_ring[i]->reg_idx;
3233 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3234 vlnctrl &= ~IXGBE_RXDCTL_VME;
3235 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3236 }
3237 break;
3238 default:
3239 break;
3240 }
3241}
3242
3243/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003244 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003245 * @adapter: driver data
3246 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003247static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003248{
3249 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003250 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003251 int i, j;
3252
3253 switch (hw->mac.type) {
3254 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003255 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3256 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003257 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3258 break;
3259 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003260 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003261 for (i = 0; i < adapter->num_rx_queues; i++) {
3262 j = adapter->rx_ring[i]->reg_idx;
3263 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3264 vlnctrl |= IXGBE_RXDCTL_VME;
3265 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3266 }
3267 break;
3268 default:
3269 break;
3270 }
3271}
3272
Auke Kok9a799d72007-09-15 14:07:45 -07003273static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3274{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003275 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003276
Jesse Grossf62bbb52010-10-20 13:56:10 +00003277 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3278
3279 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3280 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003281}
3282
3283/**
Alexander Duyck28500622010-06-15 09:25:48 +00003284 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3285 * @netdev: network interface device structure
3286 *
3287 * Writes unicast address list to the RAR table.
3288 * Returns: -ENOMEM on failure/insufficient address space
3289 * 0 on no addresses written
3290 * X on writing X addresses to the RAR table
3291 **/
3292static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3293{
3294 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3295 struct ixgbe_hw *hw = &adapter->hw;
3296 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003297 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003298 int count = 0;
3299
3300 /* return ENOMEM indicating insufficient memory for addresses */
3301 if (netdev_uc_count(netdev) > rar_entries)
3302 return -ENOMEM;
3303
3304 if (!netdev_uc_empty(netdev) && rar_entries) {
3305 struct netdev_hw_addr *ha;
3306 /* return error if we do not support writing to RAR table */
3307 if (!hw->mac.ops.set_rar)
3308 return -ENOMEM;
3309
3310 netdev_for_each_uc_addr(ha, netdev) {
3311 if (!rar_entries)
3312 break;
3313 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3314 vfn, IXGBE_RAH_AV);
3315 count++;
3316 }
3317 }
3318 /* write the addresses in reverse order to avoid write combining */
3319 for (; rar_entries > 0 ; rar_entries--)
3320 hw->mac.ops.clear_rar(hw, rar_entries);
3321
3322 return count;
3323}
3324
3325/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003326 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003327 * @netdev: network interface device structure
3328 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003329 * The set_rx_method entry point is called whenever the unicast/multicast
3330 * address list or the network interface flags are updated. This routine is
3331 * responsible for configuring the hardware for proper unicast, multicast and
3332 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003333 **/
Greg Rose7f870472010-01-09 02:25:29 +00003334void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003335{
3336 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3337 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003338 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3339 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003340
3341 /* Check for Promiscuous and All Multicast modes */
3342
3343 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3344
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003345 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003346 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003347 fctrl |= IXGBE_FCTRL_BAM;
3348 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3349 fctrl |= IXGBE_FCTRL_PMCF;
3350
Alexander Duyck28500622010-06-15 09:25:48 +00003351 /* clear the bits we are changing the status of */
3352 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3353
Auke Kok9a799d72007-09-15 14:07:45 -07003354 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003355 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003356 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003357 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003358 /* don't hardware filter vlans in promisc mode */
3359 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003360 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003361 if (netdev->flags & IFF_ALLMULTI) {
3362 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003363 vmolr |= IXGBE_VMOLR_MPE;
3364 } else {
3365 /*
3366 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003367 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003368 * that we can at least receive multicast traffic
3369 */
3370 hw->mac.ops.update_mc_addr_list(hw, netdev);
3371 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003372 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003373 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003374 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003375 /*
3376 * Write addresses to available RAR registers, if there is not
3377 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003378 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003379 */
3380 count = ixgbe_write_uc_addr_list(netdev);
3381 if (count < 0) {
3382 fctrl |= IXGBE_FCTRL_UPE;
3383 vmolr |= IXGBE_VMOLR_ROPE;
3384 }
3385 }
3386
3387 if (adapter->num_vfs) {
3388 ixgbe_restore_vf_multicasts(adapter);
3389 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3390 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3391 IXGBE_VMOLR_ROPE);
3392 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003393 }
3394
Ben Greear3f2d1c02012-03-08 08:28:41 +00003395 /* This is useful for sniffing bad packets. */
3396 if (adapter->netdev->features & NETIF_F_RXALL) {
3397 /* UPE and MPE will be handled by normal PROMISC logic
3398 * in e1000e_set_rx_mode */
3399 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3400 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3401 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3402
3403 fctrl &= ~(IXGBE_FCTRL_DPF);
3404 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3405 }
3406
Auke Kok9a799d72007-09-15 14:07:45 -07003407 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003408
3409 if (netdev->features & NETIF_F_HW_VLAN_RX)
3410 ixgbe_vlan_strip_enable(adapter);
3411 else
3412 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003413}
3414
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003415static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3416{
3417 int q_idx;
3418 struct ixgbe_q_vector *q_vector;
3419 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3420
3421 /* legacy and MSI only use one vector */
3422 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3423 q_vectors = 1;
3424
3425 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003426 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003427 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003428 }
3429}
3430
3431static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3432{
3433 int q_idx;
3434 struct ixgbe_q_vector *q_vector;
3435 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3436
3437 /* legacy and MSI only use one vector */
3438 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3439 q_vectors = 1;
3440
3441 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003442 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003443 napi_disable(&q_vector->napi);
3444 }
3445}
3446
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003447#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003448/*
3449 * ixgbe_configure_dcb - Configure DCB hardware
3450 * @adapter: ixgbe adapter struct
3451 *
3452 * This is called by the driver on open to configure the DCB hardware.
3453 * This is also called by the gennetlink interface when reconfiguring
3454 * the DCB state.
3455 */
3456static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3457{
3458 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003459 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003460
Alexander Duyck67ebd792010-08-19 13:34:04 +00003461 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3462 if (hw->mac.type == ixgbe_mac_82598EB)
3463 netif_set_gso_max_size(adapter->netdev, 65536);
3464 return;
3465 }
3466
3467 if (hw->mac.type == ixgbe_mac_82598EB)
3468 netif_set_gso_max_size(adapter->netdev, 32768);
3469
Alexander Duyck2f90b862008-11-20 20:52:10 -08003470
Alexander Duyck2f90b862008-11-20 20:52:10 -08003471 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003472 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003473
Alexander Duyck2f90b862008-11-20 20:52:10 -08003474 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003475
John Fastabendb1208182011-10-15 05:00:10 +00003476#ifdef IXGBE_FCOE
3477 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3478 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3479#endif
3480
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003481 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003482 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003483 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3484 DCB_TX_CONFIG);
3485 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3486 DCB_RX_CONFIG);
3487 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003488 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3489 ixgbe_dcb_hw_ets(&adapter->hw,
3490 adapter->ixgbe_ieee_ets,
3491 max_frame);
3492 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3493 adapter->ixgbe_ieee_pfc->pfc_en,
3494 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003495 }
John Fastabend8187cd42011-02-23 05:58:08 +00003496
3497 /* Enable RSS Hash per TC */
3498 if (hw->mac.type != ixgbe_mac_82598EB) {
3499 int i;
3500 u32 reg = 0;
3501
3502 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3503 u8 msb = 0;
3504 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3505
3506 while (cnt >>= 1)
3507 msb++;
3508
3509 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3510 }
3511 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3512 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003513}
John Fastabend9da712d2011-08-23 03:14:22 +00003514#endif
3515
3516/* Additional bittime to account for IXGBE framing */
3517#define IXGBE_ETH_FRAMING 20
3518
3519/*
3520 * ixgbe_hpbthresh - calculate high water mark for flow control
3521 *
3522 * @adapter: board private structure to calculate for
3523 * @pb - packet buffer to calculate
3524 */
3525static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3526{
3527 struct ixgbe_hw *hw = &adapter->hw;
3528 struct net_device *dev = adapter->netdev;
3529 int link, tc, kb, marker;
3530 u32 dv_id, rx_pba;
3531
3532 /* Calculate max LAN frame size */
3533 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3534
3535#ifdef IXGBE_FCOE
3536 /* FCoE traffic class uses FCOE jumbo frames */
3537 if (dev->features & NETIF_F_FCOE_MTU) {
3538 int fcoe_pb = 0;
3539
3540#ifdef CONFIG_IXGBE_DCB
3541 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003542
3543#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003544 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3545 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3546 }
3547#endif
3548
3549 /* Calculate delay value for device */
3550 switch (hw->mac.type) {
3551 case ixgbe_mac_X540:
3552 dv_id = IXGBE_DV_X540(link, tc);
3553 break;
3554 default:
3555 dv_id = IXGBE_DV(link, tc);
3556 break;
3557 }
3558
3559 /* Loopback switch introduces additional latency */
3560 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3561 dv_id += IXGBE_B2BT(tc);
3562
3563 /* Delay value is calculated in bit times convert to KB */
3564 kb = IXGBE_BT2KB(dv_id);
3565 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3566
3567 marker = rx_pba - kb;
3568
3569 /* It is possible that the packet buffer is not large enough
3570 * to provide required headroom. In this case throw an error
3571 * to user and a do the best we can.
3572 */
3573 if (marker < 0) {
3574 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3575 "headroom to support flow control."
3576 "Decrease MTU or number of traffic classes\n", pb);
3577 marker = tc + 1;
3578 }
3579
3580 return marker;
3581}
3582
3583/*
3584 * ixgbe_lpbthresh - calculate low water mark for for flow control
3585 *
3586 * @adapter: board private structure to calculate for
3587 * @pb - packet buffer to calculate
3588 */
3589static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3590{
3591 struct ixgbe_hw *hw = &adapter->hw;
3592 struct net_device *dev = adapter->netdev;
3593 int tc;
3594 u32 dv_id;
3595
3596 /* Calculate max LAN frame size */
3597 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3598
3599 /* Calculate delay value for device */
3600 switch (hw->mac.type) {
3601 case ixgbe_mac_X540:
3602 dv_id = IXGBE_LOW_DV_X540(tc);
3603 break;
3604 default:
3605 dv_id = IXGBE_LOW_DV(tc);
3606 break;
3607 }
3608
3609 /* Delay value is calculated in bit times convert to KB */
3610 return IXGBE_BT2KB(dv_id);
3611}
3612
3613/*
3614 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3615 */
3616static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3617{
3618 struct ixgbe_hw *hw = &adapter->hw;
3619 int num_tc = netdev_get_num_tc(adapter->netdev);
3620 int i;
3621
3622 if (!num_tc)
3623 num_tc = 1;
3624
3625 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3626
3627 for (i = 0; i < num_tc; i++) {
3628 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3629
3630 /* Low water marks must not be larger than high water marks */
3631 if (hw->fc.low_water > hw->fc.high_water[i])
3632 hw->fc.low_water = 0;
3633 }
3634}
John Fastabend80605c652011-05-02 12:34:10 +00003635
3636static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3637{
John Fastabend80605c652011-05-02 12:34:10 +00003638 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003639 int hdrm;
3640 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003641
3642 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3643 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003644 hdrm = 32 << adapter->fdir_pballoc;
3645 else
3646 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003647
Alexander Duyckf7e10272011-07-21 00:40:35 +00003648 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003649 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003650}
3651
Alexander Duycke4911d52011-05-11 07:18:52 +00003652static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3653{
3654 struct ixgbe_hw *hw = &adapter->hw;
3655 struct hlist_node *node, *node2;
3656 struct ixgbe_fdir_filter *filter;
3657
3658 spin_lock(&adapter->fdir_perfect_lock);
3659
3660 if (!hlist_empty(&adapter->fdir_filter_list))
3661 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3662
3663 hlist_for_each_entry_safe(filter, node, node2,
3664 &adapter->fdir_filter_list, fdir_node) {
3665 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003666 &filter->filter,
3667 filter->sw_idx,
3668 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3669 IXGBE_FDIR_DROP_QUEUE :
3670 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003671 }
3672
3673 spin_unlock(&adapter->fdir_perfect_lock);
3674}
3675
Auke Kok9a799d72007-09-15 14:07:45 -07003676static void ixgbe_configure(struct ixgbe_adapter *adapter)
3677{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003678 struct ixgbe_hw *hw = &adapter->hw;
3679
John Fastabend80605c652011-05-02 12:34:10 +00003680 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003681#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003682 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003683#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003684
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003685 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003686 ixgbe_restore_vlan(adapter);
3687
Yi Zoueacd73f2009-05-13 13:11:06 +00003688#ifdef IXGBE_FCOE
3689 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3690 ixgbe_configure_fcoe(adapter);
3691
3692#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003693
3694 switch (hw->mac.type) {
3695 case ixgbe_mac_82599EB:
3696 case ixgbe_mac_X540:
3697 hw->mac.ops.disable_rx_buff(hw);
3698 break;
3699 default:
3700 break;
3701 }
3702
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003703 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003704 ixgbe_init_fdir_signature_82599(&adapter->hw,
3705 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003706 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3707 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3708 adapter->fdir_pballoc);
3709 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003710 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003711
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003712 switch (hw->mac.type) {
3713 case ixgbe_mac_82599EB:
3714 case ixgbe_mac_X540:
3715 hw->mac.ops.enable_rx_buff(hw);
3716 break;
3717 default:
3718 break;
3719 }
3720
Alexander Duyck933d41f2010-09-07 21:34:29 +00003721 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003722
Auke Kok9a799d72007-09-15 14:07:45 -07003723 ixgbe_configure_tx(adapter);
3724 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003725}
3726
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003727static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3728{
3729 switch (hw->phy.type) {
3730 case ixgbe_phy_sfp_avago:
3731 case ixgbe_phy_sfp_ftl:
3732 case ixgbe_phy_sfp_intel:
3733 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003734 case ixgbe_phy_sfp_passive_tyco:
3735 case ixgbe_phy_sfp_passive_unknown:
3736 case ixgbe_phy_sfp_active_unknown:
3737 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003738 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003739 case ixgbe_phy_nl:
3740 if (hw->mac.type == ixgbe_mac_82598EB)
3741 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003742 default:
3743 return false;
3744 }
3745}
3746
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003747/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003748 * ixgbe_sfp_link_config - set up SFP+ link
3749 * @adapter: pointer to private adapter struct
3750 **/
3751static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3752{
Alexander Duyck70864002011-04-27 09:13:56 +00003753 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003754 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003755 * is that an SFP was inserted/removed after the reset
3756 * but before SFP detection was enabled. As such the best
3757 * solution is to just start searching as soon as we start
3758 */
3759 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3760 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003761
Alexander Duyck70864002011-04-27 09:13:56 +00003762 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003763}
3764
3765/**
3766 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003767 * @hw: pointer to private hardware struct
3768 *
3769 * Returns 0 on success, negative on failure
3770 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003771static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003772{
3773 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003774 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003775 u32 ret = IXGBE_ERR_LINK_SETUP;
3776
3777 if (hw->mac.ops.check_link)
3778 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3779
3780 if (ret)
3781 goto link_cfg_out;
3782
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003783 autoneg = hw->phy.autoneg_advertised;
3784 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003785 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3786 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003787 if (ret)
3788 goto link_cfg_out;
3789
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003790 if (hw->mac.ops.setup_link)
3791 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003792link_cfg_out:
3793 return ret;
3794}
3795
Alexander Duycka34bcff2010-08-19 13:39:20 +00003796static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003797{
Auke Kok9a799d72007-09-15 14:07:45 -07003798 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003799 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003800
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003801 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003802 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3803 IXGBE_GPIE_OCD;
3804 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003805 /*
3806 * use EIAM to auto-mask when MSI-X interrupt is asserted
3807 * this saves a register write for every interrupt
3808 */
3809 switch (hw->mac.type) {
3810 case ixgbe_mac_82598EB:
3811 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3812 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003813 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003814 case ixgbe_mac_X540:
3815 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003816 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3817 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3818 break;
3819 }
3820 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003821 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3822 * specifically only auto mask tx and rx interrupts */
3823 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003824 }
3825
Alexander Duycka34bcff2010-08-19 13:39:20 +00003826 /* XXX: to interrupt immediately for EICS writes, enable this */
3827 /* gpie |= IXGBE_GPIE_EIMEN; */
3828
3829 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3830 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3831 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003832 }
3833
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003834 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003835 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3836 switch (adapter->hw.mac.type) {
3837 case ixgbe_mac_82599EB:
3838 gpie |= IXGBE_SDP0_GPIEN;
3839 break;
3840 case ixgbe_mac_X540:
3841 gpie |= IXGBE_EIMS_TS;
3842 break;
3843 default:
3844 break;
3845 }
3846 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003847
Alexander Duycka34bcff2010-08-19 13:39:20 +00003848 /* Enable fan failure interrupt */
3849 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003850 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003851
Don Skidmore2698b202011-04-13 07:01:52 +00003852 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003853 gpie |= IXGBE_SDP1_GPIEN;
3854 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003855 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003856
3857 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3858}
3859
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003860static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003861{
3862 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003863 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003864 u32 ctrl_ext;
3865
3866 ixgbe_get_hw_control(adapter);
3867 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003868
Auke Kok9a799d72007-09-15 14:07:45 -07003869 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3870 ixgbe_configure_msix(adapter);
3871 else
3872 ixgbe_configure_msi_and_legacy(adapter);
3873
Don Skidmorec6ecf392010-12-03 03:31:51 +00003874 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3875 if (hw->mac.ops.enable_tx_laser &&
3876 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003877 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003878 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003879 hw->mac.ops.enable_tx_laser(hw);
3880
Auke Kok9a799d72007-09-15 14:07:45 -07003881 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003882 ixgbe_napi_enable_all(adapter);
3883
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003884 if (ixgbe_is_sfp(hw)) {
3885 ixgbe_sfp_link_config(adapter);
3886 } else {
3887 err = ixgbe_non_sfp_link_config(hw);
3888 if (err)
3889 e_err(probe, "link_config FAILED %d\n", err);
3890 }
3891
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003892 /* clear any pending interrupts, may auto mask */
3893 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003894 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003895
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003896 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003897 * If this adapter has a fan, check to see if we had a failure
3898 * before we enabled the interrupt.
3899 */
3900 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3901 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3902 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003903 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003904 }
3905
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003906 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003907 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003908
Auke Kok9a799d72007-09-15 14:07:45 -07003909 /* bring the link up in the watchdog, this could race with our first
3910 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003911 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3912 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003913 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003914
3915 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3916 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3917 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3918 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003919}
3920
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003921void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3922{
3923 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003924 /* put off any impending NetWatchDogTimeout */
3925 adapter->netdev->trans_start = jiffies;
3926
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003927 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003928 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003929 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003930 /*
3931 * If SR-IOV enabled then wait a bit before bringing the adapter
3932 * back up to give the VFs time to respond to the reset. The
3933 * two second wait is based upon the watchdog timer cycle in
3934 * the VF driver.
3935 */
3936 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3937 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003938 ixgbe_up(adapter);
3939 clear_bit(__IXGBE_RESETTING, &adapter->state);
3940}
3941
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003942void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003943{
3944 /* hardware has been reset, we need to reload some things */
3945 ixgbe_configure(adapter);
3946
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003947 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003948}
3949
3950void ixgbe_reset(struct ixgbe_adapter *adapter)
3951{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003952 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003953 int err;
3954
Alexander Duyck70864002011-04-27 09:13:56 +00003955 /* lock SFP init bit to prevent race conditions with the watchdog */
3956 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3957 usleep_range(1000, 2000);
3958
3959 /* clear all SFP and link config related flags while holding SFP_INIT */
3960 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3961 IXGBE_FLAG2_SFP_NEEDS_RESET);
3962 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3963
Don Skidmore8ca783a2009-05-26 20:40:47 -07003964 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003965 switch (err) {
3966 case 0:
3967 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003968 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003969 break;
3970 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003971 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003972 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003973 case IXGBE_ERR_EEPROM_VERSION:
3974 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003975 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003976 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00003977 "your hardware. If you are experiencing problems "
3978 "please contact your Intel or hardware "
3979 "representative who provided you with this "
3980 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003981 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003982 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003983 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003984 }
Auke Kok9a799d72007-09-15 14:07:45 -07003985
Alexander Duyck70864002011-04-27 09:13:56 +00003986 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3987
Auke Kok9a799d72007-09-15 14:07:45 -07003988 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003989 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3990 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003991}
3992
Auke Kok9a799d72007-09-15 14:07:45 -07003993/**
3994 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003995 * @rx_ring: ring to free buffers from
3996 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003997static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003998{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003999 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004000 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004001 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004002
Alexander Duyck84418e32010-08-19 13:40:54 +00004003 /* ring already cleared, nothing to do */
4004 if (!rx_ring->rx_buffer_info)
4005 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004006
Alexander Duyck84418e32010-08-19 13:40:54 +00004007 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004008 for (i = 0; i < rx_ring->count; i++) {
4009 struct ixgbe_rx_buffer *rx_buffer_info;
4010
4011 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4012 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004013 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004014 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004015 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004016 rx_buffer_info->dma = 0;
4017 }
4018 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004019 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004020 rx_buffer_info->skb = NULL;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004021 /* We need to clean up RSC frag lists */
4022 skb = ixgbe_merge_active_tail(skb);
4023 ixgbe_close_active_frag_list(skb);
4024 if (IXGBE_CB(skb)->delay_unmap) {
4025 dma_unmap_single(dev,
4026 IXGBE_CB(skb)->dma,
4027 rx_ring->rx_buf_len,
4028 DMA_FROM_DEVICE);
4029 IXGBE_CB(skb)->dma = 0;
4030 IXGBE_CB(skb)->delay_unmap = false;
4031 }
4032 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004033 }
4034 if (!rx_buffer_info->page)
4035 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004036 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004037 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004038 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004039 rx_buffer_info->page_dma = 0;
4040 }
Auke Kok9a799d72007-09-15 14:07:45 -07004041 put_page(rx_buffer_info->page);
4042 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004043 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004044 }
4045
4046 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4047 memset(rx_ring->rx_buffer_info, 0, size);
4048
4049 /* Zero out the descriptor ring */
4050 memset(rx_ring->desc, 0, rx_ring->size);
4051
4052 rx_ring->next_to_clean = 0;
4053 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004054}
4055
4056/**
4057 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004058 * @tx_ring: ring to be cleaned
4059 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004060static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004061{
4062 struct ixgbe_tx_buffer *tx_buffer_info;
4063 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004064 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004065
Alexander Duyck84418e32010-08-19 13:40:54 +00004066 /* ring already cleared, nothing to do */
4067 if (!tx_ring->tx_buffer_info)
4068 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004069
Alexander Duyck84418e32010-08-19 13:40:54 +00004070 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004071 for (i = 0; i < tx_ring->count; i++) {
4072 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004073 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004074 }
4075
4076 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4077 memset(tx_ring->tx_buffer_info, 0, size);
4078
4079 /* Zero out the descriptor ring */
4080 memset(tx_ring->desc, 0, tx_ring->size);
4081
4082 tx_ring->next_to_use = 0;
4083 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004084}
4085
4086/**
Auke Kok9a799d72007-09-15 14:07:45 -07004087 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4088 * @adapter: board private structure
4089 **/
4090static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4091{
4092 int i;
4093
4094 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004095 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004096}
4097
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004098/**
4099 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4100 * @adapter: board private structure
4101 **/
4102static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4103{
4104 int i;
4105
4106 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004107 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004108}
4109
Alexander Duycke4911d52011-05-11 07:18:52 +00004110static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4111{
4112 struct hlist_node *node, *node2;
4113 struct ixgbe_fdir_filter *filter;
4114
4115 spin_lock(&adapter->fdir_perfect_lock);
4116
4117 hlist_for_each_entry_safe(filter, node, node2,
4118 &adapter->fdir_filter_list, fdir_node) {
4119 hlist_del(&filter->fdir_node);
4120 kfree(filter);
4121 }
4122 adapter->fdir_filter_count = 0;
4123
4124 spin_unlock(&adapter->fdir_perfect_lock);
4125}
4126
Auke Kok9a799d72007-09-15 14:07:45 -07004127void ixgbe_down(struct ixgbe_adapter *adapter)
4128{
4129 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004130 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004131 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004132 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004133
4134 /* signal that we are down to the interrupt handler */
4135 set_bit(__IXGBE_DOWN, &adapter->state);
4136
4137 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004138 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4139 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004140
Yi Zou2d39d572011-01-06 14:29:56 +00004141 /* disable all enabled rx queues */
4142 for (i = 0; i < adapter->num_rx_queues; i++)
4143 /* this call also flushes the previous write */
4144 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4145
Don Skidmore032b4322011-03-18 09:32:53 +00004146 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004147
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004148 netif_tx_stop_all_queues(netdev);
4149
Alexander Duyck70864002011-04-27 09:13:56 +00004150 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004151 netif_carrier_off(netdev);
4152 netif_tx_disable(netdev);
4153
4154 ixgbe_irq_disable(adapter);
4155
4156 ixgbe_napi_disable_all(adapter);
4157
Alexander Duyckd034acf2011-04-27 09:25:34 +00004158 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4159 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004160 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4161
4162 del_timer_sync(&adapter->service_timer);
4163
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004164 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004165 /* Clear EITR Select mapping */
4166 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4167
4168 /* Mark all the VFs as inactive */
4169 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004170 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004171
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004172 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004173 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004174
Auke Kok9a799d72007-09-15 14:07:45 -07004175 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004176 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004177 }
4178
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004179 /* disable transmits in the hardware now that interrupts are off */
4180 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004181 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004182 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004183 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004184
4185 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004186 switch (hw->mac.type) {
4187 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004188 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004189 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004190 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4191 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004192 break;
4193 default:
4194 break;
4195 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004196
Paul Larson6f4a0e42008-06-24 17:00:56 -07004197 if (!pci_channel_offline(adapter->pdev))
4198 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004199
4200 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4201 if (hw->mac.ops.disable_tx_laser &&
4202 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004203 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004204 (hw->mac.type == ixgbe_mac_82599EB))))
4205 hw->mac.ops.disable_tx_laser(hw);
4206
Auke Kok9a799d72007-09-15 14:07:45 -07004207 ixgbe_clean_all_tx_rings(adapter);
4208 ixgbe_clean_all_rx_rings(adapter);
4209
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004210#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004211 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004212 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004213#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004214}
4215
Auke Kok9a799d72007-09-15 14:07:45 -07004216/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004217 * ixgbe_poll - NAPI Rx polling callback
4218 * @napi: structure for representing this polling device
4219 * @budget: how many packets driver is allowed to clean
4220 *
4221 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004222 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004223static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004224{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004225 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004226 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004227 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004228 struct ixgbe_ring *ring;
4229 int per_ring_budget;
4230 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004231
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004232#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004233 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4234 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004235#endif
4236
Alexander Duycka5579282012-02-08 07:50:04 +00004237 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004238 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004239
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004240 /* attempt to distribute budget to each queue fairly, but don't allow
4241 * the budget to go below 1 because we'll exit polling */
4242 if (q_vector->rx.count > 1)
4243 per_ring_budget = max(budget/q_vector->rx.count, 1);
4244 else
4245 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004246
Alexander Duycka5579282012-02-08 07:50:04 +00004247 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004248 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4249 per_ring_budget);
4250
4251 /* If all work not completed, return budget and keep polling */
4252 if (!clean_complete)
4253 return budget;
4254
4255 /* all work done, exit the polling mode */
4256 napi_complete(napi);
4257 if (adapter->rx_itr_setting & 1)
4258 ixgbe_set_itr(q_vector);
4259 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4260 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4261
4262 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004263}
4264
4265/**
4266 * ixgbe_tx_timeout - Respond to a Tx Hang
4267 * @netdev: network interface device structure
4268 **/
4269static void ixgbe_tx_timeout(struct net_device *netdev)
4270{
4271 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4272
4273 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004274 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004275}
4276
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004277/**
4278 * ixgbe_set_rss_queues: Allocate queues for RSS
4279 * @adapter: board private structure to initialize
4280 *
4281 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4282 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4283 *
4284 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004285static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4286{
4287 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004288 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004289
4290 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004291 f->mask = 0xF;
4292 adapter->num_rx_queues = f->indices;
4293 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004294 ret = true;
4295 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004296 ret = false;
4297 }
4298
4299 return ret;
4300}
4301
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004302/**
4303 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4304 * @adapter: board private structure to initialize
4305 *
4306 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4307 * to the original CPU that initiated the Tx session. This runs in addition
4308 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4309 * Rx load across CPUs using RSS.
4310 *
4311 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004312static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004313{
4314 bool ret = false;
4315 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4316
4317 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4318 f_fdir->mask = 0;
4319
Alexander Duyck24ddd962012-02-10 02:08:32 +00004320 /*
4321 * Use RSS in addition to Flow Director to ensure the best
4322 * distribution of flows across cores, even when an FDIR flow
4323 * isn't matched.
4324 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004325 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4326 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004327 adapter->num_tx_queues = f_fdir->indices;
4328 adapter->num_rx_queues = f_fdir->indices;
4329 ret = true;
4330 } else {
4331 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004332 }
4333 return ret;
4334}
4335
Yi Zou0331a832009-05-17 12:33:52 +00004336#ifdef IXGBE_FCOE
4337/**
4338 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4339 * @adapter: board private structure to initialize
4340 *
4341 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4342 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4343 * rx queues out of the max number of rx queues, instead, it is used as the
4344 * index of the first rx queue used by FCoE.
4345 *
4346 **/
4347static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4348{
Yi Zou0331a832009-05-17 12:33:52 +00004349 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4350
John Fastabende5b64632011-03-08 03:44:52 +00004351 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4352 return false;
4353
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004354 f->indices = min_t(int, num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004355
John Fastabende901acd2011-04-26 07:26:08 +00004356 adapter->num_rx_queues = 1;
4357 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004358
John Fastabende901acd2011-04-26 07:26:08 +00004359 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4360 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004361 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004362 ixgbe_set_fdir_queues(adapter);
4363 else
4364 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004365 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004366
John Fastabende901acd2011-04-26 07:26:08 +00004367 /* adding FCoE rx rings to the end */
4368 f->mask = adapter->num_rx_queues;
4369 adapter->num_rx_queues += f->indices;
4370 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004371
John Fastabende5b64632011-03-08 03:44:52 +00004372 return true;
4373}
4374#endif /* IXGBE_FCOE */
4375
John Fastabende901acd2011-04-26 07:26:08 +00004376/* Artificial max queue cap per traffic class in DCB mode */
4377#define DCB_QUEUE_CAP 8
4378
John Fastabende5b64632011-03-08 03:44:52 +00004379#ifdef CONFIG_IXGBE_DCB
4380static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4381{
John Fastabende901acd2011-04-26 07:26:08 +00004382 int per_tc_q, q, i, offset = 0;
4383 struct net_device *dev = adapter->netdev;
4384 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004385
John Fastabende901acd2011-04-26 07:26:08 +00004386 if (!tcs)
4387 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004388
John Fastabende901acd2011-04-26 07:26:08 +00004389 /* Map queue offset and counts onto allocated tx queues */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004390 per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP);
4391 q = min_t(int, num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004392
John Fastabend8b1c0b22011-05-03 02:26:48 +00004393 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004394 netdev_set_tc_queue(dev, i, q, offset);
4395 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004396 }
4397
John Fastabende901acd2011-04-26 07:26:08 +00004398 adapter->num_tx_queues = q * tcs;
4399 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004400
4401#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004402 /* FCoE enabled queues require special configuration indexed
4403 * by feature specific indices and mask. Here we map FCoE
4404 * indices onto the DCB queue pairs allowing FCoE to own
4405 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004406 */
John Fastabende901acd2011-04-26 07:26:08 +00004407 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
John Fastabendcdf485b2012-02-11 06:26:00 +00004408 u8 prio_tc[MAX_USER_PRIORITY] = {0};
John Fastabende901acd2011-04-26 07:26:08 +00004409 int tc;
4410 struct ixgbe_ring_feature *f =
4411 &adapter->ring_feature[RING_F_FCOE];
4412
John Fastabendcdf485b2012-02-11 06:26:00 +00004413 ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc);
4414 tc = prio_tc[adapter->fcoe.up];
John Fastabende901acd2011-04-26 07:26:08 +00004415 f->indices = dev->tc_to_txq[tc].count;
4416 f->mask = dev->tc_to_txq[tc].offset;
4417 }
John Fastabende5b64632011-03-08 03:44:52 +00004418#endif
4419
John Fastabende901acd2011-04-26 07:26:08 +00004420 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004421}
John Fastabende5b64632011-03-08 03:44:52 +00004422#endif
Yi Zou0331a832009-05-17 12:33:52 +00004423
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004424/**
4425 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4426 * @adapter: board private structure to initialize
4427 *
4428 * IOV doesn't actually use anything, so just NAK the
4429 * request for now and let the other queue routines
4430 * figure out what to do.
4431 */
4432static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4433{
4434 return false;
4435}
4436
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004437/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004438 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004439 * @adapter: board private structure to initialize
4440 *
4441 * This is the top level queue allocation routine. The order here is very
4442 * important, starting with the "most" number of features turned on at once,
4443 * and ending with the smallest set of features. This way large combinations
4444 * can be allocated if they're turned on, and smaller combinations are the
4445 * fallthrough conditions.
4446 *
4447 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004448static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004449{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004450 /* Start with base case */
4451 adapter->num_rx_queues = 1;
4452 adapter->num_tx_queues = 1;
4453 adapter->num_rx_pools = adapter->num_rx_queues;
4454 adapter->num_rx_queues_per_pool = 1;
4455
4456 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004457 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004458
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004459#ifdef CONFIG_IXGBE_DCB
4460 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004461 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004462
4463#endif
John Fastabende5b64632011-03-08 03:44:52 +00004464#ifdef IXGBE_FCOE
4465 if (ixgbe_set_fcoe_queues(adapter))
4466 goto done;
4467
4468#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004469 if (ixgbe_set_fdir_queues(adapter))
4470 goto done;
4471
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004472 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004473 goto done;
4474
4475 /* fallback to base case */
4476 adapter->num_rx_queues = 1;
4477 adapter->num_tx_queues = 1;
4478
4479done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004480 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4481 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4482 return 0;
4483
Ben Hutchings847f53f2010-09-27 08:28:56 +00004484 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004485 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004486 return netif_set_real_num_rx_queues(adapter->netdev,
4487 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004488}
4489
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004490static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004491 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004492{
4493 int err, vector_threshold;
4494
Alexander Duyck8f154862012-02-10 02:08:37 +00004495 /* We'll want at least 2 (vector_threshold):
4496 * 1) TxQ[0] + RxQ[0] handler
4497 * 2) Other (Link Status Change, etc.)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004498 */
4499 vector_threshold = MIN_MSIX_COUNT;
4500
Alexander Duyck24ddd962012-02-10 02:08:32 +00004501 /*
4502 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004503 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4504 * Right now, we simply care about how many we'll get; we'll
4505 * set them up later while requesting irq's.
4506 */
4507 while (vectors >= vector_threshold) {
4508 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004509 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004510 if (!err) /* Success in acquiring all requested vectors. */
4511 break;
4512 else if (err < 0)
4513 vectors = 0; /* Nasty failure, quit now */
4514 else /* err == number of vectors we should try again with */
4515 vectors = err;
4516 }
4517
4518 if (vectors < vector_threshold) {
4519 /* Can't allocate enough MSI-X interrupts? Oh well.
4520 * This just means we'll go with either a single MSI
4521 * vector or fall back to legacy interrupts.
4522 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004523 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4524 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004525 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4526 kfree(adapter->msix_entries);
4527 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004528 } else {
4529 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004530 /*
4531 * Adjust for only the vectors we'll use, which is minimum
4532 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4533 * vectors we were allocated.
4534 */
4535 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004536 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004537 }
4538}
4539
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004540/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004541 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004542 * @adapter: board private structure to initialize
4543 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004544 * Cache the descriptor ring offsets for RSS to the assigned rings.
4545 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004546 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004547static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004548{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004549 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004550
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004551 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4552 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004553
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004554 for (i = 0; i < adapter->num_rx_queues; i++)
4555 adapter->rx_ring[i]->reg_idx = i;
4556 for (i = 0; i < adapter->num_tx_queues; i++)
4557 adapter->tx_ring[i]->reg_idx = i;
4558
4559 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004560}
4561
4562#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004563
4564/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004565static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4566 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004567{
4568 struct net_device *dev = adapter->netdev;
4569 struct ixgbe_hw *hw = &adapter->hw;
4570 u8 num_tcs = netdev_get_num_tc(dev);
4571
4572 *tx = 0;
4573 *rx = 0;
4574
4575 switch (hw->mac.type) {
4576 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004577 *tx = tc << 2;
4578 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004579 break;
4580 case ixgbe_mac_82599EB:
4581 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004582 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004583 if (tc < 3) {
4584 *tx = tc << 5;
4585 *rx = tc << 4;
4586 } else if (tc < 5) {
4587 *tx = ((tc + 2) << 4);
4588 *rx = tc << 4;
4589 } else if (tc < num_tcs) {
4590 *tx = ((tc + 8) << 3);
4591 *rx = tc << 4;
4592 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004593 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004594 *rx = tc << 5;
4595 switch (tc) {
4596 case 0:
4597 *tx = 0;
4598 break;
4599 case 1:
4600 *tx = 64;
4601 break;
4602 case 2:
4603 *tx = 96;
4604 break;
4605 case 3:
4606 *tx = 112;
4607 break;
4608 default:
4609 break;
4610 }
4611 }
4612 break;
4613 default:
4614 break;
4615 }
4616}
4617
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004618/**
4619 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4620 * @adapter: board private structure to initialize
4621 *
4622 * Cache the descriptor ring offsets for DCB to the assigned rings.
4623 *
4624 **/
4625static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4626{
John Fastabende5b64632011-03-08 03:44:52 +00004627 struct net_device *dev = adapter->netdev;
4628 int i, j, k;
4629 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004630
John Fastabend8b1c0b22011-05-03 02:26:48 +00004631 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004632 return false;
4633
John Fastabende5b64632011-03-08 03:44:52 +00004634 for (i = 0, k = 0; i < num_tcs; i++) {
4635 unsigned int tx_s, rx_s;
4636 u16 count = dev->tc_to_txq[i].count;
4637
4638 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4639 for (j = 0; j < count; j++, k++) {
4640 adapter->tx_ring[k]->reg_idx = tx_s + j;
4641 adapter->rx_ring[k]->reg_idx = rx_s + j;
4642 adapter->tx_ring[k]->dcb_tc = i;
4643 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004644 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004645 }
John Fastabende5b64632011-03-08 03:44:52 +00004646
4647 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004648}
4649#endif
4650
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004651/**
4652 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4653 * @adapter: board private structure to initialize
4654 *
4655 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4656 *
4657 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004658static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004659{
4660 int i;
4661 bool ret = false;
4662
Alexander Duyck03ecf912011-05-20 07:36:17 +00004663 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4664 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004665 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004666 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004667 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004668 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004669 ret = true;
4670 }
4671
4672 return ret;
4673}
4674
Yi Zou0331a832009-05-17 12:33:52 +00004675#ifdef IXGBE_FCOE
4676/**
4677 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4678 * @adapter: board private structure to initialize
4679 *
4680 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4681 *
4682 */
4683static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4684{
Yi Zou0331a832009-05-17 12:33:52 +00004685 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004686 int i;
4687 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004688
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004689 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4690 return false;
4691
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004692 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004693 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004694 ixgbe_cache_ring_fdir(adapter);
4695 else
4696 ixgbe_cache_ring_rss(adapter);
4697
4698 fcoe_rx_i = f->mask;
4699 fcoe_tx_i = f->mask;
4700 }
4701 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4702 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4703 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4704 }
4705 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004706}
4707
4708#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004709/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004710 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4711 * @adapter: board private structure to initialize
4712 *
4713 * SR-IOV doesn't use any descriptor rings but changes the default if
4714 * no other mapping is used.
4715 *
4716 */
4717static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4718{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004719 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4720 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004721 if (adapter->num_vfs)
4722 return true;
4723 else
4724 return false;
4725}
4726
4727/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004728 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4729 * @adapter: board private structure to initialize
4730 *
4731 * Once we know the feature-set enabled for the device, we'll cache
4732 * the register offset the descriptor ring is assigned to.
4733 *
4734 * Note, the order the various feature calls is important. It must start with
4735 * the "most" features enabled at the same time, then trickle down to the
4736 * least amount of features turned on at once.
4737 **/
4738static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4739{
4740 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004741 adapter->rx_ring[0]->reg_idx = 0;
4742 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004743
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004744 if (ixgbe_cache_ring_sriov(adapter))
4745 return;
4746
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004747#ifdef CONFIG_IXGBE_DCB
4748 if (ixgbe_cache_ring_dcb(adapter))
4749 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004750#endif
John Fastabende5b64632011-03-08 03:44:52 +00004751
4752#ifdef IXGBE_FCOE
4753 if (ixgbe_cache_ring_fcoe(adapter))
4754 return;
4755#endif /* IXGBE_FCOE */
4756
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004757 if (ixgbe_cache_ring_fdir(adapter))
4758 return;
4759
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004760 if (ixgbe_cache_ring_rss(adapter))
4761 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004762}
4763
Auke Kok9a799d72007-09-15 14:07:45 -07004764/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004765 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4766 * @adapter: board private structure to initialize
4767 *
4768 * Attempt to configure the interrupts using the best available
4769 * capabilities of the hardware and the kernel.
4770 **/
Al Virofeea6a52008-11-27 15:34:07 -08004771static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004772{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004773 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004774 int err = 0;
4775 int vector, v_budget;
4776
4777 /*
4778 * It's easy to be greedy for MSI-X vectors, but it really
4779 * doesn't do us much good if we have a lot more vectors
4780 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004781 * (roughly) the same number of vectors as there are CPU's.
Alexander Duyck8f154862012-02-10 02:08:37 +00004782 * The default is to use pairs of vectors.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004783 */
Alexander Duyck8f154862012-02-10 02:08:37 +00004784 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
4785 v_budget = min_t(int, v_budget, num_online_cpus());
4786 v_budget += NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004787
4788 /*
4789 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004790 * hw.mac->max_msix_vectors vectors. With features
4791 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4792 * descriptor queues supported by our device. Thus, we cap it off in
4793 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004794 */
Alexander Duyckde88eee2012-02-08 07:49:59 +00004795 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004796
4797 /* A failure in MSI-X entry allocation isn't fatal, but it does
4798 * mean we disable MSI-X capabilities of the adapter. */
4799 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004800 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004801 if (adapter->msix_entries) {
4802 for (vector = 0; vector < v_budget; vector++)
4803 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004804
Alexander Duyck7a921c92009-05-06 10:43:28 +00004805 ixgbe_acquire_msix_vectors(adapter, v_budget);
4806
4807 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4808 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004809 }
David S. Miller26d27842010-05-03 15:18:22 -07004810
Alexander Duyck7a921c92009-05-06 10:43:28 +00004811 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4812 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004813 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004814 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004815 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004816 "queues are disabled. Disabling Flow Director\n");
4817 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004818 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004819 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004820 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4821 ixgbe_disable_sriov(adapter);
4822
Ben Hutchings847f53f2010-09-27 08:28:56 +00004823 err = ixgbe_set_num_queues(adapter);
4824 if (err)
4825 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004826
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004827 err = pci_enable_msi(adapter->pdev);
4828 if (!err) {
4829 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4830 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004831 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4832 "Unable to allocate MSI interrupt, "
4833 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004834 /* reset err */
4835 err = 0;
4836 }
4837
4838out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839 return err;
4840}
4841
Alexander Duyckde88eee2012-02-08 07:49:59 +00004842static void ixgbe_add_ring(struct ixgbe_ring *ring,
4843 struct ixgbe_ring_container *head)
4844{
4845 ring->next = head->ring;
4846 head->ring = ring;
4847 head->count++;
4848}
4849
4850/**
4851 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
4852 * @adapter: board private structure to initialize
4853 * @v_idx: index of vector in adapter struct
4854 *
4855 * We allocate one q_vector. If allocation fails we return -ENOMEM.
4856 **/
4857static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
4858 int txr_count, int txr_idx,
4859 int rxr_count, int rxr_idx)
4860{
4861 struct ixgbe_q_vector *q_vector;
4862 struct ixgbe_ring *ring;
4863 int node = -1;
4864 int cpu = -1;
4865 int ring_count, size;
4866
4867 ring_count = txr_count + rxr_count;
4868 size = sizeof(struct ixgbe_q_vector) +
4869 (sizeof(struct ixgbe_ring) * ring_count);
4870
4871 /* customize cpu for Flow Director mapping */
4872 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4873 if (cpu_online(v_idx)) {
4874 cpu = v_idx;
4875 node = cpu_to_node(cpu);
4876 }
4877 }
4878
4879 /* allocate q_vector and rings */
4880 q_vector = kzalloc_node(size, GFP_KERNEL, node);
4881 if (!q_vector)
4882 q_vector = kzalloc(size, GFP_KERNEL);
4883 if (!q_vector)
4884 return -ENOMEM;
4885
4886 /* setup affinity mask and node */
4887 if (cpu != -1)
4888 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
4889 else
4890 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
4891 q_vector->numa_node = node;
4892
4893 /* initialize NAPI */
4894 netif_napi_add(adapter->netdev, &q_vector->napi,
4895 ixgbe_poll, 64);
4896
4897 /* tie q_vector and adapter together */
4898 adapter->q_vector[v_idx] = q_vector;
4899 q_vector->adapter = adapter;
4900 q_vector->v_idx = v_idx;
4901
4902 /* initialize work limits */
4903 q_vector->tx.work_limit = adapter->tx_work_limit;
4904
4905 /* initialize pointer to rings */
4906 ring = q_vector->ring;
4907
4908 while (txr_count) {
4909 /* assign generic ring traits */
4910 ring->dev = &adapter->pdev->dev;
4911 ring->netdev = adapter->netdev;
4912
4913 /* configure backlink on ring */
4914 ring->q_vector = q_vector;
4915
4916 /* update q_vector Tx values */
4917 ixgbe_add_ring(ring, &q_vector->tx);
4918
4919 /* apply Tx specific ring traits */
4920 ring->count = adapter->tx_ring_count;
4921 ring->queue_index = txr_idx;
4922
4923 /* assign ring to adapter */
4924 adapter->tx_ring[txr_idx] = ring;
4925
4926 /* update count and index */
4927 txr_count--;
4928 txr_idx++;
4929
4930 /* push pointer to next ring */
4931 ring++;
4932 }
4933
4934 while (rxr_count) {
4935 /* assign generic ring traits */
4936 ring->dev = &adapter->pdev->dev;
4937 ring->netdev = adapter->netdev;
4938
4939 /* configure backlink on ring */
4940 ring->q_vector = q_vector;
4941
4942 /* update q_vector Rx values */
4943 ixgbe_add_ring(ring, &q_vector->rx);
4944
4945 /*
4946 * 82599 errata, UDP frames with a 0 checksum
4947 * can be marked as checksum errors.
4948 */
4949 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4950 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4951
4952 /* apply Rx specific ring traits */
4953 ring->count = adapter->rx_ring_count;
4954 ring->queue_index = rxr_idx;
4955
4956 /* assign ring to adapter */
4957 adapter->rx_ring[rxr_idx] = ring;
4958
4959 /* update count and index */
4960 rxr_count--;
4961 rxr_idx++;
4962
4963 /* push pointer to next ring */
4964 ring++;
4965 }
4966
4967 return 0;
4968}
4969
4970/**
4971 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
4972 * @adapter: board private structure to initialize
4973 * @v_idx: Index of vector to be freed
4974 *
4975 * This function frees the memory allocated to the q_vector. In addition if
4976 * NAPI is enabled it will delete any references to the NAPI struct prior
4977 * to freeing the q_vector.
4978 **/
4979static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
4980{
4981 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4982 struct ixgbe_ring *ring;
4983
Alexander Duycka5579282012-02-08 07:50:04 +00004984 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004985 adapter->tx_ring[ring->queue_index] = NULL;
4986
Alexander Duycka5579282012-02-08 07:50:04 +00004987 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004988 adapter->rx_ring[ring->queue_index] = NULL;
4989
4990 adapter->q_vector[v_idx] = NULL;
4991 netif_napi_del(&q_vector->napi);
4992
4993 /*
4994 * ixgbe_get_stats64() might access the rings on this vector,
4995 * we must wait a grace period before freeing it.
4996 */
4997 kfree_rcu(q_vector, rcu);
4998}
4999
Alexander Duyck7a921c92009-05-06 10:43:28 +00005000/**
5001 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
5002 * @adapter: board private structure to initialize
5003 *
5004 * We allocate one q_vector per queue interrupt. If allocation fails we
5005 * return -ENOMEM.
5006 **/
5007static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5008{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005009 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5010 int rxr_remaining = adapter->num_rx_queues;
5011 int txr_remaining = adapter->num_tx_queues;
5012 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
5013 int err;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005014
Alexander Duyckde88eee2012-02-08 07:49:59 +00005015 /* only one q_vector if MSI-X is disabled. */
5016 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
5017 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005018
Alexander Duyckde88eee2012-02-08 07:49:59 +00005019 if (q_vectors >= (rxr_remaining + txr_remaining)) {
5020 for (; rxr_remaining; v_idx++, q_vectors--) {
5021 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5022 err = ixgbe_alloc_q_vector(adapter, v_idx,
5023 0, 0, rqpv, rxr_idx);
5024
5025 if (err)
5026 goto err_out;
5027
5028 /* update counts and index */
5029 rxr_remaining -= rqpv;
5030 rxr_idx += rqpv;
5031 }
5032 }
5033
5034 for (; q_vectors; v_idx++, q_vectors--) {
5035 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5036 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors);
5037 err = ixgbe_alloc_q_vector(adapter, v_idx,
5038 tqpv, txr_idx,
5039 rqpv, rxr_idx);
5040
5041 if (err)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005042 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005043
Alexander Duyckde88eee2012-02-08 07:49:59 +00005044 /* update counts and index */
5045 rxr_remaining -= rqpv;
5046 rxr_idx += rqpv;
5047 txr_remaining -= tqpv;
5048 txr_idx += tqpv;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005049 }
5050
5051 return 0;
5052
5053err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005054 while (v_idx) {
5055 v_idx--;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005056 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005057 }
Alexander Duyckde88eee2012-02-08 07:49:59 +00005058
Alexander Duyck7a921c92009-05-06 10:43:28 +00005059 return -ENOMEM;
5060}
5061
5062/**
5063 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5064 * @adapter: board private structure to initialize
5065 *
5066 * This function frees the memory allocated to the q_vectors. In addition if
5067 * NAPI is enabled it will delete any references to the NAPI struct prior
5068 * to freeing the q_vector.
5069 **/
5070static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5071{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005072 int v_idx, q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005073
Alexander Duyck91281fd2009-06-04 16:00:27 +00005074 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005075 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005076 else
Alexander Duyckde88eee2012-02-08 07:49:59 +00005077 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005078
Alexander Duyckde88eee2012-02-08 07:49:59 +00005079 for (v_idx = 0; v_idx < q_vectors; v_idx++)
5080 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005081}
5082
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005083static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005084{
5085 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5086 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5087 pci_disable_msix(adapter->pdev);
5088 kfree(adapter->msix_entries);
5089 adapter->msix_entries = NULL;
5090 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5091 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5092 pci_disable_msi(adapter->pdev);
5093 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005094}
5095
5096/**
5097 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5098 * @adapter: board private structure to initialize
5099 *
5100 * We determine which interrupt scheme to use based on...
5101 * - Kernel support (MSI, MSI-X)
5102 * - which can be user-defined (via MODULE_PARAM)
5103 * - Hardware queue count (num_*_queues)
5104 * - defined by miscellaneous hardware support/features (RSS, etc.)
5105 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005106int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005107{
5108 int err;
5109
5110 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005111 err = ixgbe_set_num_queues(adapter);
5112 if (err)
5113 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005114
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005115 err = ixgbe_set_interrupt_capability(adapter);
5116 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005117 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005118 goto err_set_interrupt;
5119 }
5120
Alexander Duyck7a921c92009-05-06 10:43:28 +00005121 err = ixgbe_alloc_q_vectors(adapter);
5122 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005123 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005124 goto err_alloc_q_vectors;
5125 }
5126
Alexander Duyckde88eee2012-02-08 07:49:59 +00005127 ixgbe_cache_ring_register(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005128
Emil Tantilov849c4542010-06-03 16:53:41 +00005129 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005130 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5131 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005132
5133 set_bit(__IXGBE_DOWN, &adapter->state);
5134
5135 return 0;
5136
Alexander Duyck7a921c92009-05-06 10:43:28 +00005137err_alloc_q_vectors:
5138 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005139err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005140 return err;
5141}
5142
5143/**
5144 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5145 * @adapter: board private structure to clear interrupt scheme on
5146 *
5147 * We go through and clear interrupt specific resources and reset the structure
5148 * to pre-load conditions
5149 **/
5150void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5151{
Don Skidmoreb8eb3a102010-12-01 20:54:53 +00005152 adapter->num_tx_queues = 0;
5153 adapter->num_rx_queues = 0;
5154
Alexander Duyck7a921c92009-05-06 10:43:28 +00005155 ixgbe_free_q_vectors(adapter);
5156 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005157}
5158
5159/**
5160 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5161 * @adapter: board private structure to initialize
5162 *
5163 * ixgbe_sw_init initializes the Adapter private data structure.
5164 * Fields are initialized based on PCI device information and
5165 * OS network device settings (MTU size).
5166 **/
5167static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5168{
5169 struct ixgbe_hw *hw = &adapter->hw;
5170 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005171 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005172#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005173 int j;
5174 struct tc_configuration *tc;
5175#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005176
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005177 /* PCI config space info */
5178
5179 hw->vendor_id = pdev->vendor;
5180 hw->device_id = pdev->device;
5181 hw->revision_id = pdev->revision;
5182 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5183 hw->subsystem_device_id = pdev->subsystem_device;
5184
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005185 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005186 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005187 adapter->ring_feature[RING_F_RSS].indices = rss;
5188 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005189 switch (hw->mac.type) {
5190 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005191 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5192 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005193 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005194 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005195 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005196 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5197 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005198 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005199 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5200 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005201 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5202 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005203 /* Flow Director hash filters enabled */
5204 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5205 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005206 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005207 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005208 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005209#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005210 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5211 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5212 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005213#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005214 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005215 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005216#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005217#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005218 break;
5219 default:
5220 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005221 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005222
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005223 /* n-tuple support exists, always init our spinlock */
5224 spin_lock_init(&adapter->fdir_perfect_lock);
5225
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005226#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005227 switch (hw->mac.type) {
5228 case ixgbe_mac_X540:
5229 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5230 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5231 break;
5232 default:
5233 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5234 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5235 break;
5236 }
5237
Alexander Duyck2f90b862008-11-20 20:52:10 -08005238 /* Configure DCB traffic classes */
5239 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5240 tc = &adapter->dcb_cfg.tc_config[j];
5241 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5242 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5243 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5244 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5245 tc->dcb_pfc = pfc_disabled;
5246 }
John Fastabend4de2a022011-09-27 03:52:01 +00005247
5248 /* Initialize default user to priority mapping, UPx->TC0 */
5249 tc = &adapter->dcb_cfg.tc_config[0];
5250 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5251 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5252
Alexander Duyck2f90b862008-11-20 20:52:10 -08005253 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5254 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005255 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005256 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005257 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005258 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005259 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005260
5261#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005262
5263 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005264 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005265 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005266#ifdef CONFIG_DCB
5267 adapter->last_lfc_mode = hw->fc.current_mode;
5268#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005269 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005270 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5271 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005272 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005273
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005274 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005275 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005276 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005277
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005278 /* set default ring sizes */
5279 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5280 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5281
Alexander Duyckbd198052011-06-11 01:45:08 +00005282 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005283 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005284
Auke Kok9a799d72007-09-15 14:07:45 -07005285 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005286 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005287 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005288 return -EIO;
5289 }
5290
Auke Kok9a799d72007-09-15 14:07:45 -07005291 set_bit(__IXGBE_DOWN, &adapter->state);
5292
5293 return 0;
5294}
5295
5296/**
5297 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005298 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005299 *
5300 * Return 0 on success, negative on failure
5301 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005302int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005303{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005304 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005305 int orig_node = dev_to_node(dev);
5306 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005307 int size;
5308
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005309 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005310
5311 if (tx_ring->q_vector)
5312 numa_node = tx_ring->q_vector->numa_node;
5313
5314 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005315 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005316 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005317 if (!tx_ring->tx_buffer_info)
5318 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005319
5320 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005321 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005322 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005323
Alexander Duyckde88eee2012-02-08 07:49:59 +00005324 set_dev_node(dev, numa_node);
5325 tx_ring->desc = dma_alloc_coherent(dev,
5326 tx_ring->size,
5327 &tx_ring->dma,
5328 GFP_KERNEL);
5329 set_dev_node(dev, orig_node);
5330 if (!tx_ring->desc)
5331 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5332 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005333 if (!tx_ring->desc)
5334 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005335
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005336 tx_ring->next_to_use = 0;
5337 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005338 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005339
5340err:
5341 vfree(tx_ring->tx_buffer_info);
5342 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005343 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005344 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005345}
5346
5347/**
Alexander Duyck69888672008-09-11 20:05:39 -07005348 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5349 * @adapter: board private structure
5350 *
5351 * If this function returns with an error, then it's possible one or
5352 * more of the rings is populated (while the rest are not). It is the
5353 * callers duty to clean those orphaned rings.
5354 *
5355 * Return 0 on success, negative on failure
5356 **/
5357static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5358{
5359 int i, err = 0;
5360
5361 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005362 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005363 if (!err)
5364 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005365 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005366 break;
5367 }
5368
5369 return err;
5370}
5371
5372/**
Auke Kok9a799d72007-09-15 14:07:45 -07005373 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005374 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005375 *
5376 * Returns 0 on success, negative on failure
5377 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005378int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005379{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005380 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005381 int orig_node = dev_to_node(dev);
5382 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005383 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005384
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005385 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005386
5387 if (rx_ring->q_vector)
5388 numa_node = rx_ring->q_vector->numa_node;
5389
5390 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005391 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005392 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005393 if (!rx_ring->rx_buffer_info)
5394 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005395
Auke Kok9a799d72007-09-15 14:07:45 -07005396 /* Round up to nearest 4K */
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005397 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5398 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005399
Alexander Duyckde88eee2012-02-08 07:49:59 +00005400 set_dev_node(dev, numa_node);
5401 rx_ring->desc = dma_alloc_coherent(dev,
5402 rx_ring->size,
5403 &rx_ring->dma,
5404 GFP_KERNEL);
5405 set_dev_node(dev, orig_node);
5406 if (!rx_ring->desc)
5407 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5408 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005409 if (!rx_ring->desc)
5410 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005411
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005412 rx_ring->next_to_clean = 0;
5413 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005414
5415 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005416err:
5417 vfree(rx_ring->rx_buffer_info);
5418 rx_ring->rx_buffer_info = NULL;
5419 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005420 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005421}
5422
5423/**
Alexander Duyck69888672008-09-11 20:05:39 -07005424 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5425 * @adapter: board private structure
5426 *
5427 * If this function returns with an error, then it's possible one or
5428 * more of the rings is populated (while the rest are not). It is the
5429 * callers duty to clean those orphaned rings.
5430 *
5431 * Return 0 on success, negative on failure
5432 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005433static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5434{
5435 int i, err = 0;
5436
5437 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005438 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005439 if (!err)
5440 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005441 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005442 break;
5443 }
5444
5445 return err;
5446}
5447
5448/**
Auke Kok9a799d72007-09-15 14:07:45 -07005449 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005450 * @tx_ring: Tx descriptor ring for a specific queue
5451 *
5452 * Free all transmit software resources
5453 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005454void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005455{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005456 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005457
5458 vfree(tx_ring->tx_buffer_info);
5459 tx_ring->tx_buffer_info = NULL;
5460
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005461 /* if not set, then don't free */
5462 if (!tx_ring->desc)
5463 return;
5464
5465 dma_free_coherent(tx_ring->dev, tx_ring->size,
5466 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005467
5468 tx_ring->desc = NULL;
5469}
5470
5471/**
5472 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5473 * @adapter: board private structure
5474 *
5475 * Free all transmit software resources
5476 **/
5477static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5478{
5479 int i;
5480
5481 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005482 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005483 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005484}
5485
5486/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005487 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005488 * @rx_ring: ring to clean the resources from
5489 *
5490 * Free all receive software resources
5491 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005492void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005493{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005494 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005495
5496 vfree(rx_ring->rx_buffer_info);
5497 rx_ring->rx_buffer_info = NULL;
5498
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005499 /* if not set, then don't free */
5500 if (!rx_ring->desc)
5501 return;
5502
5503 dma_free_coherent(rx_ring->dev, rx_ring->size,
5504 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005505
5506 rx_ring->desc = NULL;
5507}
5508
5509/**
5510 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5511 * @adapter: board private structure
5512 *
5513 * Free all receive software resources
5514 **/
5515static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5516{
5517 int i;
5518
5519 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005520 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005521 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005522}
5523
5524/**
Auke Kok9a799d72007-09-15 14:07:45 -07005525 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5526 * @netdev: network interface device structure
5527 * @new_mtu: new value for maximum frame size
5528 *
5529 * Returns 0 on success, negative on failure
5530 **/
5531static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5532{
5533 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005534 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005535 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5536
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005537 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005538 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5539 hw->mac.type != ixgbe_mac_X540) {
5540 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5541 return -EINVAL;
5542 } else {
5543 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5544 return -EINVAL;
5545 }
Auke Kok9a799d72007-09-15 14:07:45 -07005546
Emil Tantilov396e7992010-07-01 20:05:12 +00005547 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005548 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005549 netdev->mtu = new_mtu;
5550
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005551 if (netif_running(netdev))
5552 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005553
5554 return 0;
5555}
5556
5557/**
5558 * ixgbe_open - Called when a network interface is made active
5559 * @netdev: network interface device structure
5560 *
5561 * Returns 0 on success, negative value on failure
5562 *
5563 * The open entry point is called when a network interface is made
5564 * active by the system (IFF_UP). At this point all resources needed
5565 * for transmit and receive operations are allocated, the interrupt
5566 * handler is registered with the OS, the watchdog timer is started,
5567 * and the stack is notified that the interface is ready.
5568 **/
5569static int ixgbe_open(struct net_device *netdev)
5570{
5571 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5572 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005573
Auke Kok4bebfaa2008-02-11 09:26:01 -08005574 /* disallow open during test */
5575 if (test_bit(__IXGBE_TESTING, &adapter->state))
5576 return -EBUSY;
5577
Jesse Brandeburg54386462009-04-17 20:44:27 +00005578 netif_carrier_off(netdev);
5579
Auke Kok9a799d72007-09-15 14:07:45 -07005580 /* allocate transmit descriptors */
5581 err = ixgbe_setup_all_tx_resources(adapter);
5582 if (err)
5583 goto err_setup_tx;
5584
Auke Kok9a799d72007-09-15 14:07:45 -07005585 /* allocate receive descriptors */
5586 err = ixgbe_setup_all_rx_resources(adapter);
5587 if (err)
5588 goto err_setup_rx;
5589
5590 ixgbe_configure(adapter);
5591
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005592 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005593 if (err)
5594 goto err_req_irq;
5595
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005596 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005597
5598 return 0;
5599
Auke Kok9a799d72007-09-15 14:07:45 -07005600err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005601err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005602 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005603err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005604 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005605 ixgbe_reset(adapter);
5606
5607 return err;
5608}
5609
5610/**
5611 * ixgbe_close - Disables a network interface
5612 * @netdev: network interface device structure
5613 *
5614 * Returns 0, this is not allowed to fail
5615 *
5616 * The close entry point is called when an interface is de-activated
5617 * by the OS. The hardware is still under the drivers control, but
5618 * needs to be disabled. A global MAC reset is issued to stop the
5619 * hardware, and all transmit and receive resources are freed.
5620 **/
5621static int ixgbe_close(struct net_device *netdev)
5622{
5623 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005624
5625 ixgbe_down(adapter);
5626 ixgbe_free_irq(adapter);
5627
Alexander Duycke4911d52011-05-11 07:18:52 +00005628 ixgbe_fdir_filter_exit(adapter);
5629
Auke Kok9a799d72007-09-15 14:07:45 -07005630 ixgbe_free_all_tx_resources(adapter);
5631 ixgbe_free_all_rx_resources(adapter);
5632
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005633 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005634
5635 return 0;
5636}
5637
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005638#ifdef CONFIG_PM
5639static int ixgbe_resume(struct pci_dev *pdev)
5640{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005641 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5642 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005643 u32 err;
5644
5645 pci_set_power_state(pdev, PCI_D0);
5646 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005647 /*
5648 * pci_restore_state clears dev->state_saved so call
5649 * pci_save_state to restore it.
5650 */
5651 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005652
5653 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005654 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005655 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005656 return err;
5657 }
5658 pci_set_master(pdev);
5659
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005660 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005661
5662 err = ixgbe_init_interrupt_scheme(adapter);
5663 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005664 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005665 return err;
5666 }
5667
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005668 ixgbe_reset(adapter);
5669
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005670 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5671
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005672 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005673 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005674 if (err)
5675 return err;
5676 }
5677
5678 netif_device_attach(netdev);
5679
5680 return 0;
5681}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005682#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005683
5684static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005685{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005686 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5687 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005688 struct ixgbe_hw *hw = &adapter->hw;
5689 u32 ctrl, fctrl;
5690 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005691#ifdef CONFIG_PM
5692 int retval = 0;
5693#endif
5694
5695 netif_device_detach(netdev);
5696
5697 if (netif_running(netdev)) {
5698 ixgbe_down(adapter);
5699 ixgbe_free_irq(adapter);
5700 ixgbe_free_all_tx_resources(adapter);
5701 ixgbe_free_all_rx_resources(adapter);
5702 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005703
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005704 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005705#ifdef CONFIG_DCB
5706 kfree(adapter->ixgbe_ieee_pfc);
5707 kfree(adapter->ixgbe_ieee_ets);
5708#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005709
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005710#ifdef CONFIG_PM
5711 retval = pci_save_state(pdev);
5712 if (retval)
5713 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005714
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005715#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005716 if (wufc) {
5717 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005718
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005719 /* turn on all-multi mode if wake on multicast is enabled */
5720 if (wufc & IXGBE_WUFC_MC) {
5721 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5722 fctrl |= IXGBE_FCTRL_MPE;
5723 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5724 }
5725
5726 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5727 ctrl |= IXGBE_CTRL_GIO_DIS;
5728 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5729
5730 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5731 } else {
5732 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5733 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5734 }
5735
Alexander Duyckbd508172010-11-16 19:27:03 -08005736 switch (hw->mac.type) {
5737 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005738 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005739 break;
5740 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005741 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005742 pci_wake_from_d3(pdev, !!wufc);
5743 break;
5744 default:
5745 break;
5746 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005747
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005748 *enable_wake = !!wufc;
5749
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005750 ixgbe_release_hw_control(adapter);
5751
5752 pci_disable_device(pdev);
5753
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005754 return 0;
5755}
5756
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005757#ifdef CONFIG_PM
5758static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5759{
5760 int retval;
5761 bool wake;
5762
5763 retval = __ixgbe_shutdown(pdev, &wake);
5764 if (retval)
5765 return retval;
5766
5767 if (wake) {
5768 pci_prepare_to_sleep(pdev);
5769 } else {
5770 pci_wake_from_d3(pdev, false);
5771 pci_set_power_state(pdev, PCI_D3hot);
5772 }
5773
5774 return 0;
5775}
5776#endif /* CONFIG_PM */
5777
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005778static void ixgbe_shutdown(struct pci_dev *pdev)
5779{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005780 bool wake;
5781
5782 __ixgbe_shutdown(pdev, &wake);
5783
5784 if (system_state == SYSTEM_POWER_OFF) {
5785 pci_wake_from_d3(pdev, wake);
5786 pci_set_power_state(pdev, PCI_D3hot);
5787 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005788}
5789
5790/**
Auke Kok9a799d72007-09-15 14:07:45 -07005791 * ixgbe_update_stats - Update the board statistics counters.
5792 * @adapter: board private structure
5793 **/
5794void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5795{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005796 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005797 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005798 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005799 u64 total_mpc = 0;
5800 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005801 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5802 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005803 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005804#ifdef IXGBE_FCOE
5805 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5806 unsigned int cpu;
5807 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5808#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005809
Don Skidmored08935c2010-06-11 13:20:29 +00005810 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5811 test_bit(__IXGBE_RESETTING, &adapter->state))
5812 return;
5813
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005814 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005815 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005816 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005817 for (i = 0; i < 16; i++)
5818 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005819 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005820 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005821 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5822 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005823 }
5824 adapter->rsc_total_count = rsc_count;
5825 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005826 }
5827
Alexander Duyck5b7da512010-11-16 19:26:50 -08005828 for (i = 0; i < adapter->num_rx_queues; i++) {
5829 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5830 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5831 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5832 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005833 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005834 bytes += rx_ring->stats.bytes;
5835 packets += rx_ring->stats.packets;
5836 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005837 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005838 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5839 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005840 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005841 netdev->stats.rx_bytes = bytes;
5842 netdev->stats.rx_packets = packets;
5843
5844 bytes = 0;
5845 packets = 0;
5846 /* gather some stats to the adapter struct that are per queue */
5847 for (i = 0; i < adapter->num_tx_queues; i++) {
5848 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5849 restart_queue += tx_ring->tx_stats.restart_queue;
5850 tx_busy += tx_ring->tx_stats.tx_busy;
5851 bytes += tx_ring->stats.bytes;
5852 packets += tx_ring->stats.packets;
5853 }
5854 adapter->restart_queue = restart_queue;
5855 adapter->tx_busy = tx_busy;
5856 netdev->stats.tx_bytes = bytes;
5857 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005858
Joe Perches7ca647b2010-09-07 21:35:40 +00005859 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005860
5861 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005862 for (i = 0; i < 8; i++) {
5863 /* for packet buffers not used, the register should read 0 */
5864 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5865 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005866 hwstats->mpc[i] += mpc;
5867 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005868 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5869 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005870 switch (hw->mac.type) {
5871 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005872 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5873 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5874 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005875 hwstats->pxonrxc[i] +=
5876 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005877 break;
5878 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005879 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005880 hwstats->pxonrxc[i] +=
5881 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005882 break;
5883 default:
5884 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005885 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005886 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005887
5888 /*16 register reads */
5889 for (i = 0; i < 16; i++) {
5890 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5891 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5892 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5893 (hw->mac.type == ixgbe_mac_X540)) {
5894 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5895 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5896 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5897 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5898 }
5899 }
5900
Joe Perches7ca647b2010-09-07 21:35:40 +00005901 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005902 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005903 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005904
John Fastabendc84d3242010-11-16 19:27:12 -08005905 ixgbe_update_xoff_received(adapter);
5906
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005907 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005908 switch (hw->mac.type) {
5909 case ixgbe_mac_82598EB:
5910 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005911 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5912 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5913 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5914 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005915 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005916 /* OS2BMC stats are X540 only*/
5917 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5918 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5919 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5920 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5921 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005922 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005923 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005925 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005926 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005927 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005928 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005929 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5930 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005931#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005932 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5933 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5934 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5935 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5936 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5937 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005938 /* Add up per cpu counters for total ddp aloc fail */
5939 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5940 for_each_possible_cpu(cpu) {
5941 fcoe_noddp_counts_sum +=
5942 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5943 fcoe_noddp_ext_buff_counts_sum +=
5944 *per_cpu_ptr(fcoe->
5945 pcpu_noddp_ext_buff, cpu);
5946 }
5947 }
5948 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5949 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005950#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005951 break;
5952 default:
5953 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005954 }
Auke Kok9a799d72007-09-15 14:07:45 -07005955 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005956 hwstats->bprc += bprc;
5957 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005958 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005959 hwstats->mprc -= bprc;
5960 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5961 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5962 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5963 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5964 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5965 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5966 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5967 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005968 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005969 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005970 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005971 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005972 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5973 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005974 /*
5975 * 82598 errata - tx of flow control packets is included in tx counters
5976 */
5977 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005978 hwstats->gptc -= xon_off_tot;
5979 hwstats->mptc -= xon_off_tot;
5980 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5981 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5982 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5983 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5984 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5985 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5986 hwstats->ptc64 -= xon_off_tot;
5987 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5988 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5989 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5990 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5991 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5992 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005993
5994 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005995 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005996
5997 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005998 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005999 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006000 netdev->stats.rx_length_errors = hwstats->rlec;
6001 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006002 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006003}
6004
6005/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006006 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6007 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006008 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006009static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006010{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006011 struct ixgbe_hw *hw = &adapter->hw;
6012 int i;
6013
Alexander Duyckd034acf2011-04-27 09:25:34 +00006014 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6015 return;
6016
6017 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6018
6019 /* if interface is down do nothing */
6020 if (test_bit(__IXGBE_DOWN, &adapter->state))
6021 return;
6022
6023 /* do nothing if we are not using signature filters */
6024 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6025 return;
6026
6027 adapter->fdir_overflow++;
6028
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006029 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6030 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006031 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006032 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006033 /* re-enable flow director interrupts */
6034 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006035 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006036 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006037 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006038 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006039}
6040
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006041/**
6042 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6043 * @adapter - pointer to the device adapter structure
6044 *
6045 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006046 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006047 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006048 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006049 */
6050static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6051{
Auke Kok9a799d72007-09-15 14:07:45 -07006052 struct ixgbe_hw *hw = &adapter->hw;
6053 u64 eics = 0;
6054 int i;
6055
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006056 /* If we're down or resetting, just bail */
6057 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6058 test_bit(__IXGBE_RESETTING, &adapter->state))
6059 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006060
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006061 /* Force detection of hung controller */
6062 if (netif_carrier_ok(adapter->netdev)) {
6063 for (i = 0; i < adapter->num_tx_queues; i++)
6064 set_check_for_tx_hang(adapter->tx_ring[i]);
6065 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006066
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006067 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006068 /*
6069 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006070 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006071 * would set *both* EIMS and EICS for any bit in EIAM
6072 */
6073 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6074 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006075 } else {
6076 /* get one bit for every active tx/rx interrupt vector */
6077 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6078 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006079 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006080 eics |= ((u64)1 << i);
6081 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006082 }
6083
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006084 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006085 ixgbe_irq_rearm_queues(adapter, eics);
6086
Alexander Duyckfe49f042009-06-04 16:00:09 +00006087}
6088
6089/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006090 * ixgbe_watchdog_update_link - update the link status
6091 * @adapter - pointer to the device adapter structure
6092 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006093 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006094static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006095{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006096 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006097 u32 link_speed = adapter->link_speed;
6098 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006099 int i;
6100
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006101 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6102 return;
6103
6104 if (hw->mac.ops.check_link) {
6105 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006106 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006107 /* always assume link is up, if no check link function */
6108 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6109 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006110 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006111 if (link_up) {
6112 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6113 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6114 hw->mac.ops.fc_enable(hw, i);
6115 } else {
6116 hw->mac.ops.fc_enable(hw, 0);
6117 }
6118 }
6119
6120 if (link_up ||
6121 time_after(jiffies, (adapter->link_check_timeout +
6122 IXGBE_TRY_LINK_TIMEOUT))) {
6123 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6124 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6125 IXGBE_WRITE_FLUSH(hw);
6126 }
6127
6128 adapter->link_up = link_up;
6129 adapter->link_speed = link_speed;
6130}
6131
6132/**
6133 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6134 * print link up message
6135 * @adapter - pointer to the device adapter structure
6136 **/
6137static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6138{
6139 struct net_device *netdev = adapter->netdev;
6140 struct ixgbe_hw *hw = &adapter->hw;
6141 u32 link_speed = adapter->link_speed;
6142 bool flow_rx, flow_tx;
6143
6144 /* only continue if link was previously down */
6145 if (netif_carrier_ok(netdev))
6146 return;
6147
6148 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6149
6150 switch (hw->mac.type) {
6151 case ixgbe_mac_82598EB: {
6152 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6153 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6154 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6155 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6156 }
6157 break;
6158 case ixgbe_mac_X540:
6159 case ixgbe_mac_82599EB: {
6160 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6161 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6162 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6163 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6164 }
6165 break;
6166 default:
6167 flow_tx = false;
6168 flow_rx = false;
6169 break;
6170 }
6171 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6172 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6173 "10 Gbps" :
6174 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6175 "1 Gbps" :
6176 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6177 "100 Mbps" :
6178 "unknown speed"))),
6179 ((flow_rx && flow_tx) ? "RX/TX" :
6180 (flow_rx ? "RX" :
6181 (flow_tx ? "TX" : "None"))));
6182
6183 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006184 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006185}
6186
6187/**
6188 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6189 * print link down message
6190 * @adapter - pointer to the adapter structure
6191 **/
6192static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6193{
6194 struct net_device *netdev = adapter->netdev;
6195 struct ixgbe_hw *hw = &adapter->hw;
6196
6197 adapter->link_up = false;
6198 adapter->link_speed = 0;
6199
6200 /* only continue if link was up previously */
6201 if (!netif_carrier_ok(netdev))
6202 return;
6203
6204 /* poll for SFP+ cable when link is down */
6205 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6206 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6207
6208 e_info(drv, "NIC Link is Down\n");
6209 netif_carrier_off(netdev);
6210}
6211
6212/**
6213 * ixgbe_watchdog_flush_tx - flush queues on link down
6214 * @adapter - pointer to the device adapter structure
6215 **/
6216static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6217{
6218 int i;
6219 int some_tx_pending = 0;
6220
6221 if (!netif_carrier_ok(adapter->netdev)) {
6222 for (i = 0; i < adapter->num_tx_queues; i++) {
6223 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6224 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6225 some_tx_pending = 1;
6226 break;
6227 }
6228 }
6229
6230 if (some_tx_pending) {
6231 /* We've lost link, so the controller stops DMA,
6232 * but we've got queued Tx work that's never going
6233 * to get done, so reset controller to flush Tx.
6234 * (Do the reset outside of interrupt context).
6235 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006236 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006237 }
6238 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006239}
6240
Greg Rosea985b6c32010-11-18 03:02:52 +00006241static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6242{
6243 u32 ssvpc;
6244
6245 /* Do not perform spoof check for 82598 */
6246 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6247 return;
6248
6249 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6250
6251 /*
6252 * ssvpc register is cleared on read, if zero then no
6253 * spoofed packets in the last interval.
6254 */
6255 if (!ssvpc)
6256 return;
6257
6258 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6259}
6260
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006261/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006262 * ixgbe_watchdog_subtask - check and bring link up
6263 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006264 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006265static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006266{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006267 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006268 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6269 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006270 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006271
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006272 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006273
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006274 if (adapter->link_up)
6275 ixgbe_watchdog_link_is_up(adapter);
6276 else
6277 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006278
Greg Rosea985b6c32010-11-18 03:02:52 +00006279 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006280 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006281
6282 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006283}
6284
Alexander Duyck70864002011-04-27 09:13:56 +00006285/**
6286 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6287 * @adapter - the ixgbe adapter structure
6288 **/
6289static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6290{
6291 struct ixgbe_hw *hw = &adapter->hw;
6292 s32 err;
6293
6294 /* not searching for SFP so there is nothing to do here */
6295 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6296 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6297 return;
6298
6299 /* someone else is in init, wait until next service event */
6300 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6301 return;
6302
6303 err = hw->phy.ops.identify_sfp(hw);
6304 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6305 goto sfp_out;
6306
6307 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6308 /* If no cable is present, then we need to reset
6309 * the next time we find a good cable. */
6310 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6311 }
6312
6313 /* exit on error */
6314 if (err)
6315 goto sfp_out;
6316
6317 /* exit if reset not needed */
6318 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6319 goto sfp_out;
6320
6321 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6322
6323 /*
6324 * A module may be identified correctly, but the EEPROM may not have
6325 * support for that module. setup_sfp() will fail in that case, so
6326 * we should not allow that module to load.
6327 */
6328 if (hw->mac.type == ixgbe_mac_82598EB)
6329 err = hw->phy.ops.reset(hw);
6330 else
6331 err = hw->mac.ops.setup_sfp(hw);
6332
6333 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6334 goto sfp_out;
6335
6336 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6337 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6338
6339sfp_out:
6340 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6341
6342 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6343 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6344 e_dev_err("failed to initialize because an unsupported "
6345 "SFP+ module type was detected.\n");
6346 e_dev_err("Reload the driver after installing a "
6347 "supported module.\n");
6348 unregister_netdev(adapter->netdev);
6349 }
6350}
6351
6352/**
6353 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6354 * @adapter - the ixgbe adapter structure
6355 **/
6356static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6357{
6358 struct ixgbe_hw *hw = &adapter->hw;
6359 u32 autoneg;
6360 bool negotiation;
6361
6362 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6363 return;
6364
6365 /* someone else is in init, wait until next service event */
6366 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6367 return;
6368
6369 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6370
6371 autoneg = hw->phy.autoneg_advertised;
6372 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6373 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006374 if (hw->mac.ops.setup_link)
6375 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6376
6377 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6378 adapter->link_check_timeout = jiffies;
6379 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6380}
6381
Greg Rose83c61fa2011-09-07 05:59:35 +00006382#ifdef CONFIG_PCI_IOV
6383static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6384{
6385 int vf;
6386 struct ixgbe_hw *hw = &adapter->hw;
6387 struct net_device *netdev = adapter->netdev;
6388 u32 gpc;
6389 u32 ciaa, ciad;
6390
6391 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6392 if (gpc) /* If incrementing then no need for the check below */
6393 return;
6394 /*
6395 * Check to see if a bad DMA write target from an errant or
6396 * malicious VF has caused a PCIe error. If so then we can
6397 * issue a VFLR to the offending VF(s) and then resume without
6398 * requesting a full slot reset.
6399 */
6400
6401 for (vf = 0; vf < adapter->num_vfs; vf++) {
6402 ciaa = (vf << 16) | 0x80000000;
6403 /* 32 bit read so align, we really want status at offset 6 */
6404 ciaa |= PCI_COMMAND;
6405 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6406 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6407 ciaa &= 0x7FFFFFFF;
6408 /* disable debug mode asap after reading data */
6409 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6410 /* Get the upper 16 bits which will be the PCI status reg */
6411 ciad >>= 16;
6412 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6413 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6414 /* Issue VFLR */
6415 ciaa = (vf << 16) | 0x80000000;
6416 ciaa |= 0xA8;
6417 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6418 ciad = 0x00008000; /* VFLR */
6419 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6420 ciaa &= 0x7FFFFFFF;
6421 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6422 }
6423 }
6424}
6425
6426#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006427/**
6428 * ixgbe_service_timer - Timer Call-back
6429 * @data: pointer to adapter cast into an unsigned long
6430 **/
6431static void ixgbe_service_timer(unsigned long data)
6432{
6433 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6434 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006435 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006436
Greg Rose83c61fa2011-09-07 05:59:35 +00006437#ifdef CONFIG_PCI_IOV
6438 ready = false;
6439
6440 /*
6441 * don't bother with SR-IOV VF DMA hang check if there are
6442 * no VFs or the link is down
6443 */
6444 if (!adapter->num_vfs ||
6445 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6446 ready = true;
6447 goto normal_timer_service;
6448 }
6449
6450 /* If we have VFs allocated then we must check for DMA hangs */
6451 ixgbe_check_for_bad_vf(adapter);
6452 next_event_offset = HZ / 50;
6453 adapter->timer_event_accumulator++;
6454
6455 if (adapter->timer_event_accumulator >= 100) {
6456 ready = true;
6457 adapter->timer_event_accumulator = 0;
6458 }
6459
6460 goto schedule_event;
6461
6462normal_timer_service:
6463#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006464 /* poll faster when waiting for link */
6465 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6466 next_event_offset = HZ / 10;
6467 else
6468 next_event_offset = HZ * 2;
6469
Greg Rose83c61fa2011-09-07 05:59:35 +00006470#ifdef CONFIG_PCI_IOV
6471schedule_event:
6472#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006473 /* Reset the timer */
6474 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6475
Greg Rose83c61fa2011-09-07 05:59:35 +00006476 if (ready)
6477 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006478}
6479
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006480static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6481{
6482 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6483 return;
6484
6485 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6486
6487 /* If we're already down or resetting, just bail */
6488 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6489 test_bit(__IXGBE_RESETTING, &adapter->state))
6490 return;
6491
6492 ixgbe_dump(adapter);
6493 netdev_err(adapter->netdev, "Reset adapter\n");
6494 adapter->tx_timeout_count++;
6495
6496 ixgbe_reinit_locked(adapter);
6497}
6498
Alexander Duyck70864002011-04-27 09:13:56 +00006499/**
6500 * ixgbe_service_task - manages and runs subtasks
6501 * @work: pointer to work_struct containing our data
6502 **/
6503static void ixgbe_service_task(struct work_struct *work)
6504{
6505 struct ixgbe_adapter *adapter = container_of(work,
6506 struct ixgbe_adapter,
6507 service_task);
6508
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006509 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006510 ixgbe_sfp_detection_subtask(adapter);
6511 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006512 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006513 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006514 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006515 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006516
6517 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006518}
6519
Alexander Duyck897ab152011-05-27 05:31:47 +00006520void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6521 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006522{
6523 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006524 u16 i = tx_ring->next_to_use;
6525
Alexander Duycke4f74022012-01-31 02:59:44 +00006526 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006527
6528 i++;
6529 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6530
6531 /* set bits to identify this as an advanced context descriptor */
6532 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6533
6534 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6535 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6536 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6537 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6538}
6539
6540static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6541 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6542{
Auke Kok9a799d72007-09-15 14:07:45 -07006543 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006544 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006545 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006546
Alexander Duyck897ab152011-05-27 05:31:47 +00006547 if (!skb_is_gso(skb))
6548 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006549
Alexander Duyck897ab152011-05-27 05:31:47 +00006550 if (skb_header_cloned(skb)) {
6551 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6552 if (err)
6553 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006554 }
6555
Alexander Duyck897ab152011-05-27 05:31:47 +00006556 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6557 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6558
6559 if (protocol == __constant_htons(ETH_P_IP)) {
6560 struct iphdr *iph = ip_hdr(skb);
6561 iph->tot_len = 0;
6562 iph->check = 0;
6563 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6564 iph->daddr, 0,
6565 IPPROTO_TCP,
6566 0);
6567 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6568 } else if (skb_is_gso_v6(skb)) {
6569 ipv6_hdr(skb)->payload_len = 0;
6570 tcp_hdr(skb)->check =
6571 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6572 &ipv6_hdr(skb)->daddr,
6573 0, IPPROTO_TCP, 0);
6574 }
6575
6576 l4len = tcp_hdrlen(skb);
6577 *hdr_len = skb_transport_offset(skb) + l4len;
6578
6579 /* mss_l4len_id: use 1 as index for TSO */
6580 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6581 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6582 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6583
6584 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6585 vlan_macip_lens = skb_network_header_len(skb);
6586 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6587 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6588
6589 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6590 mss_l4len_idx);
6591
6592 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006593}
6594
Alexander Duyck897ab152011-05-27 05:31:47 +00006595static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006596 struct sk_buff *skb, u32 tx_flags,
6597 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006598{
Alexander Duyck897ab152011-05-27 05:31:47 +00006599 u32 vlan_macip_lens = 0;
6600 u32 mss_l4len_idx = 0;
6601 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006602
Alexander Duyck897ab152011-05-27 05:31:47 +00006603 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006604 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6605 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006606 return false;
6607 } else {
6608 u8 l4_hdr = 0;
6609 switch (protocol) {
6610 case __constant_htons(ETH_P_IP):
6611 vlan_macip_lens |= skb_network_header_len(skb);
6612 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6613 l4_hdr = ip_hdr(skb)->protocol;
6614 break;
6615 case __constant_htons(ETH_P_IPV6):
6616 vlan_macip_lens |= skb_network_header_len(skb);
6617 l4_hdr = ipv6_hdr(skb)->nexthdr;
6618 break;
6619 default:
6620 if (unlikely(net_ratelimit())) {
6621 dev_warn(tx_ring->dev,
6622 "partial checksum but proto=%x!\n",
6623 skb->protocol);
6624 }
6625 break;
6626 }
Auke Kok9a799d72007-09-15 14:07:45 -07006627
Alexander Duyck897ab152011-05-27 05:31:47 +00006628 switch (l4_hdr) {
6629 case IPPROTO_TCP:
6630 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6631 mss_l4len_idx = tcp_hdrlen(skb) <<
6632 IXGBE_ADVTXD_L4LEN_SHIFT;
6633 break;
6634 case IPPROTO_SCTP:
6635 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6636 mss_l4len_idx = sizeof(struct sctphdr) <<
6637 IXGBE_ADVTXD_L4LEN_SHIFT;
6638 break;
6639 case IPPROTO_UDP:
6640 mss_l4len_idx = sizeof(struct udphdr) <<
6641 IXGBE_ADVTXD_L4LEN_SHIFT;
6642 break;
6643 default:
6644 if (unlikely(net_ratelimit())) {
6645 dev_warn(tx_ring->dev,
6646 "partial checksum but l4 proto=%x!\n",
6647 skb->protocol);
6648 }
6649 break;
6650 }
Auke Kok9a799d72007-09-15 14:07:45 -07006651 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006652
Alexander Duyck897ab152011-05-27 05:31:47 +00006653 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6654 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6655
6656 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6657 type_tucmd, mss_l4len_idx);
6658
6659 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006660}
6661
Alexander Duyckd3d00232011-07-15 02:31:25 +00006662static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6663{
6664 /* set type for advanced descriptor with frame checksum insertion */
6665 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6666 IXGBE_ADVTXD_DCMD_IFCS |
6667 IXGBE_ADVTXD_DCMD_DEXT);
6668
6669 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006670 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006671 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6672
6673 /* set segmentation enable bits for TSO/FSO */
6674#ifdef IXGBE_FCOE
6675 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6676#else
6677 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6678#endif
6679 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6680
6681 return cmd_type;
6682}
6683
6684static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6685{
6686 __le32 olinfo_status =
6687 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6688
6689 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6690 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6691 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6692 /* enble IPv4 checksum for TSO */
6693 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6694 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6695 }
6696
6697 /* enable L4 checksum for TSO and TX checksum offload */
6698 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6699 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6700
6701#ifdef IXGBE_FCOE
6702 /* use index 1 context for FCOE/FSO */
6703 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6704 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6705 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6706
6707#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006708 /*
6709 * Check Context must be set if Tx switch is enabled, which it
6710 * always is for case where virtual functions are running
6711 */
6712 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6713 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6714
Alexander Duyckd3d00232011-07-15 02:31:25 +00006715 return olinfo_status;
6716}
6717
6718#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6719 IXGBE_TXD_CMD_RS)
6720
6721static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6722 struct sk_buff *skb,
6723 struct ixgbe_tx_buffer *first,
6724 u32 tx_flags,
6725 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006726{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006727 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006728 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006729 union ixgbe_adv_tx_desc *tx_desc;
6730 dma_addr_t dma;
6731 __le32 cmd_type, olinfo_status;
6732 struct skb_frag_struct *frag;
6733 unsigned int f = 0;
6734 unsigned int data_len = skb->data_len;
6735 unsigned int size = skb_headlen(skb);
6736 u32 offset = 0;
6737 u32 paylen = skb->len - hdr_len;
6738 u16 i = tx_ring->next_to_use;
6739 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006740
Alexander Duyckd3d00232011-07-15 02:31:25 +00006741#ifdef IXGBE_FCOE
6742 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6743 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6744 data_len -= sizeof(struct fcoe_crc_eof);
6745 } else {
6746 size -= sizeof(struct fcoe_crc_eof) - data_len;
6747 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006748 }
Auke Kok9a799d72007-09-15 14:07:45 -07006749 }
6750
Alexander Duyckd3d00232011-07-15 02:31:25 +00006751#endif
6752 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6753 if (dma_mapping_error(dev, dma))
6754 goto dma_error;
6755
6756 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6757 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6758
Alexander Duycke4f74022012-01-31 02:59:44 +00006759 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006760
6761 for (;;) {
6762 while (size > IXGBE_MAX_DATA_PER_TXD) {
6763 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6764 tx_desc->read.cmd_type_len =
6765 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6766 tx_desc->read.olinfo_status = olinfo_status;
6767
6768 offset += IXGBE_MAX_DATA_PER_TXD;
6769 size -= IXGBE_MAX_DATA_PER_TXD;
6770
6771 tx_desc++;
6772 i++;
6773 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006774 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006775 i = 0;
6776 }
6777 }
6778
6779 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6780 tx_buffer_info->length = offset + size;
6781 tx_buffer_info->tx_flags = tx_flags;
6782 tx_buffer_info->dma = dma;
6783
6784 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
Ben Greearf43f3132012-03-06 09:42:04 +00006785 if (unlikely(skb->no_fcs))
6786 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006787 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6788 tx_desc->read.olinfo_status = olinfo_status;
6789
6790 if (!data_len)
6791 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006792
6793 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006794#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006795 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006796#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006797 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006798#endif
6799 data_len -= size;
6800 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006801
Alexander Duyckd3d00232011-07-15 02:31:25 +00006802 offset = 0;
6803 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006804
Ian Campbell877749b2011-08-29 23:18:26 +00006805 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006806 if (dma_mapping_error(dev, dma))
6807 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006808
Alexander Duyckd3d00232011-07-15 02:31:25 +00006809 tx_desc++;
6810 i++;
6811 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006812 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006813 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006814 }
6815 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006816
Alexander Duyckd3d00232011-07-15 02:31:25 +00006817 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6818
6819 i++;
6820 if (i == tx_ring->count)
6821 i = 0;
6822
6823 tx_ring->next_to_use = i;
6824
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006825 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6826 gso_segs = skb_shinfo(skb)->gso_segs;
6827#ifdef IXGBE_FCOE
6828 /* adjust for FCoE Sequence Offload */
6829 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6830 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6831 skb_shinfo(skb)->gso_size);
6832#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006833 else
6834 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006835
6836 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006837 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6838 tx_buffer_info->gso_segs = gso_segs;
6839 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006840
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006841 netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount);
6842
Alexander Duyckd3d00232011-07-15 02:31:25 +00006843 /* set the timestamp */
6844 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006845
6846 /*
6847 * Force memory writes to complete before letting h/w
6848 * know there are new descriptors to fetch. (Only
6849 * applicable for weak-ordered memory model archs,
6850 * such as IA-64).
6851 */
6852 wmb();
6853
Alexander Duyckd3d00232011-07-15 02:31:25 +00006854 /* set next_to_watch value indicating a packet is present */
6855 first->next_to_watch = tx_desc;
6856
6857 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006858 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006859
6860 return;
6861dma_error:
6862 dev_err(dev, "TX DMA map failed\n");
6863
6864 /* clear dma mappings for failed tx_buffer_info map */
6865 for (;;) {
6866 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6867 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6868 if (tx_buffer_info == first)
6869 break;
6870 if (i == 0)
6871 i = tx_ring->count;
6872 i--;
6873 }
6874
6875 dev_kfree_skb_any(skb);
6876
6877 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006878}
6879
Alexander Duyck69830522011-01-06 14:29:58 +00006880static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6881 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006882{
Alexander Duyck69830522011-01-06 14:29:58 +00006883 struct ixgbe_q_vector *q_vector = ring->q_vector;
6884 union ixgbe_atr_hash_dword input = { .dword = 0 };
6885 union ixgbe_atr_hash_dword common = { .dword = 0 };
6886 union {
6887 unsigned char *network;
6888 struct iphdr *ipv4;
6889 struct ipv6hdr *ipv6;
6890 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006891 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006892 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006893
Alexander Duyck69830522011-01-06 14:29:58 +00006894 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6895 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006896 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006897
Alexander Duyck69830522011-01-06 14:29:58 +00006898 /* do nothing if sampling is disabled */
6899 if (!ring->atr_sample_rate)
6900 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006901
Alexander Duyck69830522011-01-06 14:29:58 +00006902 ring->atr_count++;
6903
6904 /* snag network header to get L4 type and address */
6905 hdr.network = skb_network_header(skb);
6906
6907 /* Currently only IPv4/IPv6 with TCP is supported */
6908 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6909 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6910 (protocol != __constant_htons(ETH_P_IP) ||
6911 hdr.ipv4->protocol != IPPROTO_TCP))
6912 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006913
6914 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006915
Alexander Duyck66f32a82011-06-29 05:43:22 +00006916 /* skip this packet since it is invalid or the socket is closing */
6917 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006918 return;
6919
6920 /* sample on all syn packets or once every atr sample count */
6921 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6922 return;
6923
6924 /* reset sample count */
6925 ring->atr_count = 0;
6926
6927 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6928
6929 /*
6930 * src and dst are inverted, think how the receiver sees them
6931 *
6932 * The input is broken into two sections, a non-compressed section
6933 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6934 * is XORed together and stored in the compressed dword.
6935 */
6936 input.formatted.vlan_id = vlan_id;
6937
6938 /*
6939 * since src port and flex bytes occupy the same word XOR them together
6940 * and write the value to source port portion of compressed dword
6941 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006942 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006943 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6944 else
6945 common.port.src ^= th->dest ^ protocol;
6946 common.port.dst ^= th->source;
6947
6948 if (protocol == __constant_htons(ETH_P_IP)) {
6949 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6950 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6951 } else {
6952 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6953 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6954 hdr.ipv6->saddr.s6_addr32[1] ^
6955 hdr.ipv6->saddr.s6_addr32[2] ^
6956 hdr.ipv6->saddr.s6_addr32[3] ^
6957 hdr.ipv6->daddr.s6_addr32[0] ^
6958 hdr.ipv6->daddr.s6_addr32[1] ^
6959 hdr.ipv6->daddr.s6_addr32[2] ^
6960 hdr.ipv6->daddr.s6_addr32[3];
6961 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006962
6963 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006964 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6965 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006966}
6967
Alexander Duyck63544e92011-05-27 05:31:42 +00006968static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006969{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006970 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006971 /* Herbert's original patch had:
6972 * smp_mb__after_netif_stop_queue();
6973 * but since that doesn't exist yet, just open code it. */
6974 smp_mb();
6975
6976 /* We need to check again in a case another CPU has just
6977 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006978 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006979 return -EBUSY;
6980
6981 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006982 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006983 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006984 return 0;
6985}
6986
Alexander Duyck82d4e462011-06-11 01:44:58 +00006987static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006988{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006989 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006990 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006991 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006992}
6993
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006994static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6995{
6996 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006997 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6998 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006999#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00007000 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00007001
John Fastabende5b64632011-03-08 03:44:52 +00007002 if (((protocol == htons(ETH_P_FCOE)) ||
7003 (protocol == htons(ETH_P_FIP))) &&
7004 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
7005 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
7006 txq += adapter->ring_feature[RING_F_FCOE].mask;
7007 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00007008 }
7009#endif
7010
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007011 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
7012 while (unlikely(txq >= dev->real_num_tx_queues))
7013 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00007014 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007015 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007016
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007017 return skb_tx_hash(dev, skb);
7018}
7019
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007020netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007021 struct ixgbe_adapter *adapter,
7022 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007023{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007024 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007025 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007026 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007027#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7028 unsigned short f;
7029#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007030 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007031 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007032 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007033
Alexander Duycka535c302011-05-27 05:31:52 +00007034 /*
7035 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007036 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007037 * + 2 desc gap to keep tail from touching head,
7038 * + 1 desc for context descriptor,
7039 * otherwise try next time
7040 */
7041#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7042 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7043 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7044#else
7045 count += skb_shinfo(skb)->nr_frags;
7046#endif
7047 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7048 tx_ring->tx_stats.tx_busy++;
7049 return NETDEV_TX_BUSY;
7050 }
7051
Alexander Duyck66f32a82011-06-29 05:43:22 +00007052 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007053 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007054 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7055 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7056 /* else if it is a SW VLAN check the next protocol and store the tag */
7057 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7058 struct vlan_hdr *vhdr, _vhdr;
7059 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7060 if (!vhdr)
7061 goto out_drop;
7062
7063 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007064 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7065 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007066 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007067 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007068
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007069#ifdef CONFIG_PCI_IOV
7070 /*
7071 * Use the l2switch_enable flag - would be false if the DMA
7072 * Tx switch had been disabled.
7073 */
7074 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7075 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7076
7077#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007078 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007079 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007080 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7081 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007082 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007083 tx_flags |= (skb->priority & 0x7) <<
7084 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007085 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7086 struct vlan_ethhdr *vhdr;
7087 if (skb_header_cloned(skb) &&
7088 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7089 goto out_drop;
7090 vhdr = (struct vlan_ethhdr *)skb->data;
7091 vhdr->h_vlan_TCI = htons(tx_flags >>
7092 IXGBE_TX_FLAGS_VLAN_SHIFT);
7093 } else {
7094 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7095 }
7096 }
Alexander Duycka535c302011-05-27 05:31:52 +00007097
Alexander Duycka535c302011-05-27 05:31:52 +00007098 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007099 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007100
Yi Zoueacd73f2009-05-13 13:11:06 +00007101#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007102 /* setup tx offload for FCoE */
7103 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7104 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007105 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7106 if (tso < 0)
7107 goto out_drop;
7108 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007109 tx_flags |= IXGBE_TX_FLAGS_FSO |
7110 IXGBE_TX_FLAGS_FCOE;
7111 else
7112 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007113
Alexander Duyck66f32a82011-06-29 05:43:22 +00007114 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007115 }
Auke Kok9a799d72007-09-15 14:07:45 -07007116
Auke Kok9a799d72007-09-15 14:07:45 -07007117#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007118 /* setup IPv4/IPv6 offloads */
7119 if (protocol == __constant_htons(ETH_P_IP))
7120 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007121
Alexander Duyck66f32a82011-06-29 05:43:22 +00007122 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7123 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007124 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007125 else if (tso)
7126 tx_flags |= IXGBE_TX_FLAGS_TSO;
7127 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7128 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7129
7130 /* add the ATR filter if ATR is on */
7131 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7132 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7133
7134#ifdef IXGBE_FCOE
7135xmit_fcoe:
7136#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007137 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7138
7139 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007140
7141 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007142
7143out_drop:
7144 dev_kfree_skb_any(skb);
7145 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007146}
7147
7148static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7149{
7150 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7151 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007152
Auke Kok9a799d72007-09-15 14:07:45 -07007153 tx_ring = adapter->tx_ring[skb->queue_mapping];
7154 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7155}
7156
7157/**
7158 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007159 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007160 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007161 *
Auke Kok9a799d72007-09-15 14:07:45 -07007162 * Returns 0 on success, negative on failure
7163 **/
7164static int ixgbe_set_mac(struct net_device *netdev, void *p)
7165{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007166 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7167 struct ixgbe_hw *hw = &adapter->hw;
7168 struct sockaddr *addr = p;
7169
7170 if (!is_valid_ether_addr(addr->sa_data))
7171 return -EADDRNOTAVAIL;
7172
7173 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7174 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7175
7176 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7177 IXGBE_RAH_AV);
7178
7179 return 0;
7180}
7181
7182static int
7183ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7184{
7185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7186 struct ixgbe_hw *hw = &adapter->hw;
7187 u16 value;
7188 int rc;
7189
7190 if (prtad != hw->phy.mdio.prtad)
7191 return -EINVAL;
7192 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7193 if (!rc)
7194 rc = value;
7195 return rc;
7196}
7197
7198static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7199 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007200{
7201 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007202 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007203
7204 if (prtad != hw->phy.mdio.prtad)
7205 return -EINVAL;
7206 return hw->phy.ops.write_reg(hw, addr, devad, value);
7207}
7208
7209static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7210{
7211 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7212
7213 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7214}
7215
7216/**
7217 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7218 * netdev->dev_addrs
7219 * @netdev: network interface device structure
7220 *
7221 * Returns non-zero on failure
7222 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007223static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007224{
7225 int err = 0;
7226 struct ixgbe_adapter *adapter = netdev_priv(dev);
7227 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7228
7229 if (is_valid_ether_addr(mac->san_addr)) {
7230 rtnl_lock();
7231 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7232 rtnl_unlock();
7233 }
7234 return err;
7235}
7236
7237/**
7238 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7239 * netdev->dev_addrs
7240 * @netdev: network interface device structure
7241 *
Auke Kok9a799d72007-09-15 14:07:45 -07007242 * Returns non-zero on failure
7243 **/
7244static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7245{
7246 int err = 0;
7247 struct ixgbe_adapter *adapter = netdev_priv(dev);
7248 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7249
7250 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007251 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007252 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007253 rtnl_unlock();
7254 }
7255 return err;
7256}
Auke Kok9a799d72007-09-15 14:07:45 -07007257
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007258#ifdef CONFIG_NET_POLL_CONTROLLER
7259/*
7260 * Polling 'interrupt' - used by things like netconsole to send skbs
7261 * without having to re-enable interrupts. It's not called while
7262 * the interrupt routine is executing.
7263 */
7264static void ixgbe_netpoll(struct net_device *netdev)
7265{
7266 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007267 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007268
7269 /* if interface is down do nothing */
7270 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007271 return;
7272
7273 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007274 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007275 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007276 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007277 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007278 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007279 }
7280 } else {
7281 ixgbe_intr(adapter->pdev->irq, netdev);
7282 }
7283 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7284}
7285#endif
7286
Eric Dumazetde1036b2010-10-20 23:00:04 +00007287static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7288 struct rtnl_link_stats64 *stats)
7289{
7290 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7291 int i;
7292
Eric Dumazet1a515022010-11-16 19:26:42 -08007293 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007294 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007295 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007296 u64 bytes, packets;
7297 unsigned int start;
7298
Eric Dumazet1a515022010-11-16 19:26:42 -08007299 if (ring) {
7300 do {
7301 start = u64_stats_fetch_begin_bh(&ring->syncp);
7302 packets = ring->stats.packets;
7303 bytes = ring->stats.bytes;
7304 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7305 stats->rx_packets += packets;
7306 stats->rx_bytes += bytes;
7307 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007308 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007309
7310 for (i = 0; i < adapter->num_tx_queues; i++) {
7311 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7312 u64 bytes, packets;
7313 unsigned int start;
7314
7315 if (ring) {
7316 do {
7317 start = u64_stats_fetch_begin_bh(&ring->syncp);
7318 packets = ring->stats.packets;
7319 bytes = ring->stats.bytes;
7320 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7321 stats->tx_packets += packets;
7322 stats->tx_bytes += bytes;
7323 }
7324 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007325 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007326 /* following stats updated by ixgbe_watchdog_task() */
7327 stats->multicast = netdev->stats.multicast;
7328 stats->rx_errors = netdev->stats.rx_errors;
7329 stats->rx_length_errors = netdev->stats.rx_length_errors;
7330 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7331 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7332 return stats;
7333}
7334
John Fastabend8b1c0b22011-05-03 02:26:48 +00007335/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7336 * #adapter: pointer to ixgbe_adapter
7337 * @tc: number of traffic classes currently enabled
7338 *
7339 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7340 * 802.1Q priority maps to a packet buffer that exists.
7341 */
7342static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7343{
7344 struct ixgbe_hw *hw = &adapter->hw;
7345 u32 reg, rsave;
7346 int i;
7347
7348 /* 82598 have a static priority to TC mapping that can not
7349 * be changed so no validation is needed.
7350 */
7351 if (hw->mac.type == ixgbe_mac_82598EB)
7352 return;
7353
7354 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7355 rsave = reg;
7356
7357 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7358 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7359
7360 /* If up2tc is out of bounds default to zero */
7361 if (up2tc > tc)
7362 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7363 }
7364
7365 if (reg != rsave)
7366 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7367
7368 return;
7369}
7370
7371
7372/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7373 * classes.
7374 *
7375 * @netdev: net device to configure
7376 * @tc: number of traffic classes to enable
7377 */
7378int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7379{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007380 struct ixgbe_adapter *adapter = netdev_priv(dev);
7381 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007382
John Fastabende7589ea2011-07-18 22:38:36 +00007383 /* Multiple traffic classes requires multiple queues */
7384 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7385 e_err(drv, "Enable failed, needs MSI-X\n");
7386 return -EINVAL;
7387 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007388
7389 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007390 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007391 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7392 return -EINVAL;
7393
7394 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007395 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007396 * hardware is not flexible enough to do this dynamically.
7397 */
7398 if (netif_running(dev))
7399 ixgbe_close(dev);
7400 ixgbe_clear_interrupt_scheme(adapter);
7401
John Fastabende7589ea2011-07-18 22:38:36 +00007402 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007403 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007404 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7405
7406 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7407 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7408
7409 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7410 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7411 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007412 netdev_reset_tc(dev);
7413
John Fastabende7589ea2011-07-18 22:38:36 +00007414 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7415
7416 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7417 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7418
7419 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7420 adapter->dcb_cfg.pfc_mode_enable = false;
7421 }
7422
John Fastabend8b1c0b22011-05-03 02:26:48 +00007423 ixgbe_init_interrupt_scheme(adapter);
7424 ixgbe_validate_rtr(adapter, tc);
7425 if (netif_running(dev))
7426 ixgbe_open(dev);
7427
7428 return 0;
7429}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007430
Don Skidmore082757a2011-07-21 05:55:00 +00007431void ixgbe_do_reset(struct net_device *netdev)
7432{
7433 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7434
7435 if (netif_running(netdev))
7436 ixgbe_reinit_locked(adapter);
7437 else
7438 ixgbe_reset(adapter);
7439}
7440
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007441static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7442 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007443{
7444 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7445
7446#ifdef CONFIG_DCB
7447 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7448 data &= ~NETIF_F_HW_VLAN_RX;
7449#endif
7450
7451 /* return error if RXHASH is being enabled when RSS is not supported */
7452 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7453 data &= ~NETIF_F_RXHASH;
7454
7455 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7456 if (!(data & NETIF_F_RXCSUM))
7457 data &= ~NETIF_F_LRO;
7458
7459 /* Turn off LRO if not RSC capable or invalid ITR settings */
7460 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7461 data &= ~NETIF_F_LRO;
7462 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7463 (adapter->rx_itr_setting != 1 &&
7464 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7465 data &= ~NETIF_F_LRO;
7466 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7467 }
7468
7469 return data;
7470}
7471
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007472static int ixgbe_set_features(struct net_device *netdev,
7473 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007474{
7475 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ben Greear3f2d1c02012-03-08 08:28:41 +00007476 netdev_features_t changed = netdev->features ^ data;
Don Skidmore082757a2011-07-21 05:55:00 +00007477 bool need_reset = false;
7478
Don Skidmore082757a2011-07-21 05:55:00 +00007479 /* Make sure RSC matches LRO, reset if change */
7480 if (!!(data & NETIF_F_LRO) !=
7481 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7482 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7483 switch (adapter->hw.mac.type) {
7484 case ixgbe_mac_X540:
7485 case ixgbe_mac_82599EB:
7486 need_reset = true;
7487 break;
7488 default:
7489 break;
7490 }
7491 }
7492
7493 /*
7494 * Check if Flow Director n-tuple support was enabled or disabled. If
7495 * the state changed, we need to reset.
7496 */
7497 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7498 /* turn off ATR, enable perfect filters and reset */
7499 if (data & NETIF_F_NTUPLE) {
7500 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7501 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7502 need_reset = true;
7503 }
7504 } else if (!(data & NETIF_F_NTUPLE)) {
7505 /* turn off Flow Director, set ATR and reset */
7506 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7507 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7508 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7509 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7510 need_reset = true;
7511 }
7512
Ben Greear3f2d1c02012-03-08 08:28:41 +00007513 if (changed & NETIF_F_RXALL)
7514 need_reset = true;
7515
7516 netdev->features = data;
Don Skidmore082757a2011-07-21 05:55:00 +00007517 if (need_reset)
7518 ixgbe_do_reset(netdev);
7519
7520 return 0;
7521
7522}
7523
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007524static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007525 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007526 .ndo_stop = ixgbe_close,
7527 .ndo_start_xmit = ixgbe_xmit_frame,
7528 .ndo_select_queue = ixgbe_select_queue,
7529 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007530 .ndo_validate_addr = eth_validate_addr,
7531 .ndo_set_mac_address = ixgbe_set_mac,
7532 .ndo_change_mtu = ixgbe_change_mtu,
7533 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007534 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7535 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007536 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007537 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7538 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7539 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007540 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007541 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007542 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007543 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007544#ifdef CONFIG_NET_POLL_CONTROLLER
7545 .ndo_poll_controller = ixgbe_netpoll,
7546#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007547#ifdef IXGBE_FCOE
7548 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007549 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007550 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007551 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7552 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007553 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007554 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007555#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007556 .ndo_set_features = ixgbe_set_features,
7557 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007558};
7559
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007560static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7561 const struct ixgbe_info *ii)
7562{
7563#ifdef CONFIG_PCI_IOV
7564 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007565
Greg Rosec6bda302011-08-24 02:37:55 +00007566 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007567 return;
7568
7569 /* The 82599 supports up to 64 VFs per physical function
7570 * but this implementation limits allocation to 63 so that
7571 * basic networking resources are still available to the
7572 * physical function
7573 */
7574 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007575 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007576#endif /* CONFIG_PCI_IOV */
7577}
7578
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007579/**
Auke Kok9a799d72007-09-15 14:07:45 -07007580 * ixgbe_probe - Device Initialization Routine
7581 * @pdev: PCI device information struct
7582 * @ent: entry in ixgbe_pci_tbl
7583 *
7584 * Returns 0 on success, negative on failure
7585 *
7586 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7587 * The OS initialization, configuring of the adapter private structure,
7588 * and a hardware reset occur.
7589 **/
7590static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007591 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007592{
7593 struct net_device *netdev;
7594 struct ixgbe_adapter *adapter = NULL;
7595 struct ixgbe_hw *hw;
7596 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007597 static int cards_found;
7598 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007599 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007600 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007601#ifdef IXGBE_FCOE
7602 u16 device_caps;
7603#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007604 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007605 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007606
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007607 /* Catch broken hardware that put the wrong VF device ID in
7608 * the PCIe SR-IOV capability.
7609 */
7610 if (pdev->is_virtfn) {
7611 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7612 pci_name(pdev), pdev->vendor, pdev->device);
7613 return -EINVAL;
7614 }
7615
gouji-new9ce77662009-05-06 10:44:45 +00007616 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007617 if (err)
7618 return err;
7619
Nick Nunley1b507732010-04-27 13:10:27 +00007620 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7621 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007622 pci_using_dac = 1;
7623 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007624 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007625 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007626 err = dma_set_coherent_mask(&pdev->dev,
7627 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007628 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007629 dev_err(&pdev->dev,
7630 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007631 goto err_dma;
7632 }
7633 }
7634 pci_using_dac = 0;
7635 }
7636
gouji-new9ce77662009-05-06 10:44:45 +00007637 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007638 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007639 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007640 dev_err(&pdev->dev,
7641 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007642 goto err_pci_reg;
7643 }
7644
Frans Pop19d5afd2009-10-02 10:04:12 -07007645 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007646
Auke Kok9a799d72007-09-15 14:07:45 -07007647 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007648 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007649
John Fastabende901acd2011-04-26 07:26:08 +00007650#ifdef CONFIG_IXGBE_DCB
7651 indices *= MAX_TRAFFIC_CLASS;
7652#endif
7653
John Fastabendc85a2612010-02-25 23:15:21 +00007654 if (ii->mac == ixgbe_mac_82598EB)
7655 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7656 else
7657 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7658
John Fastabende901acd2011-04-26 07:26:08 +00007659#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007660 indices += min_t(unsigned int, num_possible_cpus(),
7661 IXGBE_MAX_FCOE_INDICES);
7662#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007663 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007664 if (!netdev) {
7665 err = -ENOMEM;
7666 goto err_alloc_etherdev;
7667 }
7668
Auke Kok9a799d72007-09-15 14:07:45 -07007669 SET_NETDEV_DEV(netdev, &pdev->dev);
7670
Auke Kok9a799d72007-09-15 14:07:45 -07007671 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007672 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007673
7674 adapter->netdev = netdev;
7675 adapter->pdev = pdev;
7676 hw = &adapter->hw;
7677 hw->back = adapter;
7678 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7679
Jeff Kirsher05857982008-09-11 19:57:00 -07007680 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007681 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007682 if (!hw->hw_addr) {
7683 err = -EIO;
7684 goto err_ioremap;
7685 }
7686
7687 for (i = 1; i <= 5; i++) {
7688 if (pci_resource_len(pdev, i) == 0)
7689 continue;
7690 }
7691
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007692 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007693 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007694 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007695 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007696
Auke Kok9a799d72007-09-15 14:07:45 -07007697 adapter->bd_number = cards_found;
7698
Auke Kok9a799d72007-09-15 14:07:45 -07007699 /* Setup hw api */
7700 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007701 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007702
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007703 /* EEPROM */
7704 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7705 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7706 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7707 if (!(eec & (1 << 8)))
7708 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7709
7710 /* PHY */
7711 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007712 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007713 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7714 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7715 hw->phy.mdio.mmds = 0;
7716 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7717 hw->phy.mdio.dev = netdev;
7718 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7719 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007720
Don Skidmore8ca783a2009-05-26 20:40:47 -07007721 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007722
7723 /* setup the private structure */
7724 err = ixgbe_sw_init(adapter);
7725 if (err)
7726 goto err_sw_init;
7727
Don Skidmoree86bff02010-02-11 04:14:08 +00007728 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007729 switch (adapter->hw.mac.type) {
7730 case ixgbe_mac_82599EB:
7731 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007732 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007733 break;
7734 default:
7735 break;
7736 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007737
Don Skidmorebf069c92009-05-07 10:39:54 +00007738 /*
7739 * If there is a fan on this device and it has failed log the
7740 * failure.
7741 */
7742 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7743 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7744 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007745 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007746 }
7747
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007748 if (allow_unsupported_sfp)
7749 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7750
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007751 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007752 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007753 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007754 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007755 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7756 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007757 err = 0;
7758 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007759 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007760 "module type was detected.\n");
7761 e_dev_err("Reload the driver after installing a supported "
7762 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007763 goto err_sw_init;
7764 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007765 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007766 goto err_sw_init;
7767 }
7768
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007769 ixgbe_probe_vf(adapter, ii);
7770
Emil Tantilov396e7992010-07-01 20:05:12 +00007771 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007772 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007773 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007774 NETIF_F_HW_VLAN_TX |
7775 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007776 NETIF_F_HW_VLAN_FILTER |
7777 NETIF_F_TSO |
7778 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007779 NETIF_F_RXHASH |
7780 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007781
Don Skidmore082757a2011-07-21 05:55:00 +00007782 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007783
Don Skidmore58be7662011-04-12 09:42:11 +00007784 switch (adapter->hw.mac.type) {
7785 case ixgbe_mac_82599EB:
7786 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007787 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007788 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7789 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007790 break;
7791 default:
7792 break;
7793 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007794
Ben Greear3f2d1c02012-03-08 08:28:41 +00007795 netdev->hw_features |= NETIF_F_RXALL;
7796
Jeff Kirsherad31c402008-06-05 04:05:30 -07007797 netdev->vlan_features |= NETIF_F_TSO;
7798 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007799 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007800 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007801 netdev->vlan_features |= NETIF_F_SG;
7802
Jiri Pirko01789342011-08-16 06:29:00 +00007803 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007804 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007805
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007806 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7807 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7808 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007809
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007810#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007811 netdev->dcbnl_ops = &dcbnl_ops;
7812#endif
7813
Yi Zoueacd73f2009-05-13 13:11:06 +00007814#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007815 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007816 if (hw->mac.ops.get_device_caps) {
7817 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007818 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7819 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007820 }
7821 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007822 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7823 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7824 netdev->vlan_features |= NETIF_F_FSO;
7825 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7826 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007827#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007828 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007829 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007830 netdev->vlan_features |= NETIF_F_HIGHDMA;
7831 }
Auke Kok9a799d72007-09-15 14:07:45 -07007832
Don Skidmore082757a2011-07-21 05:55:00 +00007833 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7834 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007835 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007836 netdev->features |= NETIF_F_LRO;
7837
Auke Kok9a799d72007-09-15 14:07:45 -07007838 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007839 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007840 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007841 err = -EIO;
7842 goto err_eeprom;
7843 }
7844
7845 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7846 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7847
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007848 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007849 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007850 err = -EIO;
7851 goto err_eeprom;
7852 }
7853
Alexander Duyck70864002011-04-27 09:13:56 +00007854 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7855 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007856
Alexander Duyck70864002011-04-27 09:13:56 +00007857 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7858 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007859
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007860 err = ixgbe_init_interrupt_scheme(adapter);
7861 if (err)
7862 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007863
Don Skidmore082757a2011-07-21 05:55:00 +00007864 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7865 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007866 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007867 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007868
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007869 /* WOL not supported for all but the following */
7870 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007871 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007872 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007873 /* Only these subdevice supports WOL */
7874 switch (pdev->subsystem_device) {
7875 case IXGBE_SUBDEV_ID_82599_560FLR:
7876 /* only support first port */
7877 if (hw->bus.func != 0)
7878 break;
7879 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007880 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007881 break;
7882 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007883 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007884 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7885 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007886 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007887 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007888 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007889 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007890 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007891 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007892 case IXGBE_DEV_ID_X540T:
7893 /* Check eeprom to see if it is enabled */
7894 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7895 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7896
7897 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7898 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7899 (hw->bus.func == 0)))
7900 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007901 break;
7902 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007903 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7904
Emil Tantilov15e52092011-09-29 05:01:29 +00007905 /* save off EEPROM version number */
7906 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7907 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7908
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007909 /* pick up the PCI bus settings for reporting later */
7910 hw->mac.ops.get_bus_info(hw);
7911
Auke Kok9a799d72007-09-15 14:07:45 -07007912 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007913 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007914 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7915 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007916 "Unknown"),
7917 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7918 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7919 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7920 "Unknown"),
7921 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007922
7923 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7924 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007925 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007926 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007927 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007928 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007929 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007930 else
Don Skidmore289700db2010-12-03 03:32:58 +00007931 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7932 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007933
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007934 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007935 e_dev_warn("PCI-Express bandwidth available for this card is "
7936 "not sufficient for optimal performance.\n");
7937 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7938 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007939 }
7940
Auke Kok9a799d72007-09-15 14:07:45 -07007941 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007942 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007943
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007944 if (err == IXGBE_ERR_EEPROM_VERSION) {
7945 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007946 e_dev_warn("This device is a pre-production adapter/LOM. "
7947 "Please be aware there may be issues associated "
7948 "with your hardware. If you are experiencing "
7949 "problems please contact your Intel or hardware "
7950 "representative who provided you with this "
7951 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007952 }
Auke Kok9a799d72007-09-15 14:07:45 -07007953 strcpy(netdev->name, "eth%d");
7954 err = register_netdev(netdev);
7955 if (err)
7956 goto err_register;
7957
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007958 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7959 if (hw->mac.ops.disable_tx_laser &&
7960 ((hw->phy.multispeed_fiber) ||
7961 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7962 (hw->mac.type == ixgbe_mac_82599EB))))
7963 hw->mac.ops.disable_tx_laser(hw);
7964
Jesse Brandeburg54386462009-04-17 20:44:27 +00007965 /* carrier off reporting is important to ethtool even BEFORE open */
7966 netif_carrier_off(netdev);
7967
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007968#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007969 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007970 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007971 ixgbe_setup_dca(adapter);
7972 }
7973#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007974 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007975 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007976 for (i = 0; i < adapter->num_vfs; i++)
7977 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7978 }
7979
Jacob Keller2466dd92011-09-08 03:50:54 +00007980 /* firmware requires driver version to be 0xFFFFFFFF
7981 * since os does not support feature
7982 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007983 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007984 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7985 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007986
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007987 /* add san mac addr to netdev */
7988 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007989
Neerav Parikhea818752012-01-04 20:23:40 +00007990 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007991 cards_found++;
7992 return 0;
7993
7994err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007995 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007996 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007997err_sw_init:
7998err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007999 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
8000 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008001 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07008002 iounmap(hw->hw_addr);
8003err_ioremap:
8004 free_netdev(netdev);
8005err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008006 pci_release_selected_regions(pdev,
8007 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008008err_pci_reg:
8009err_dma:
8010 pci_disable_device(pdev);
8011 return err;
8012}
8013
8014/**
8015 * ixgbe_remove - Device Removal Routine
8016 * @pdev: PCI device information struct
8017 *
8018 * ixgbe_remove is called by the PCI subsystem to alert the driver
8019 * that it should release a PCI device. The could be caused by a
8020 * Hot-Plug event, or because the driver is going to be removed from
8021 * memory.
8022 **/
8023static void __devexit ixgbe_remove(struct pci_dev *pdev)
8024{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008025 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8026 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008027
8028 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008029 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008030
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008031#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008032 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8033 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8034 dca_remove_requester(&pdev->dev);
8035 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8036 }
8037
8038#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008039#ifdef IXGBE_FCOE
8040 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8041 ixgbe_cleanup_fcoe(adapter);
8042
8043#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008044
8045 /* remove the added san mac */
8046 ixgbe_del_sanmac_netdev(netdev);
8047
Donald Skidmorec4900be2008-11-20 21:11:42 -08008048 if (netdev->reg_state == NETREG_REGISTERED)
8049 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008050
Greg Rosec6bda302011-08-24 02:37:55 +00008051 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8052 if (!(ixgbe_check_vf_assignment(adapter)))
8053 ixgbe_disable_sriov(adapter);
8054 else
8055 e_dev_warn("Unloading driver while VFs are assigned "
8056 "- VFs will not be deallocated\n");
8057 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008058
Alexander Duyck7a921c92009-05-06 10:43:28 +00008059 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008060
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008061 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008062
8063 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008064 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008065 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008066
Emil Tantilov849c4542010-06-03 16:53:41 +00008067 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008068
Auke Kok9a799d72007-09-15 14:07:45 -07008069 free_netdev(netdev);
8070
Frans Pop19d5afd2009-10-02 10:04:12 -07008071 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008072
Auke Kok9a799d72007-09-15 14:07:45 -07008073 pci_disable_device(pdev);
8074}
8075
8076/**
8077 * ixgbe_io_error_detected - called when PCI error is detected
8078 * @pdev: Pointer to PCI device
8079 * @state: The current pci connection state
8080 *
8081 * This function is called after a PCI bus error affecting
8082 * this device has been detected.
8083 */
8084static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008085 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008086{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008087 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8088 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008089
Greg Rose83c61fa2011-09-07 05:59:35 +00008090#ifdef CONFIG_PCI_IOV
8091 struct pci_dev *bdev, *vfdev;
8092 u32 dw0, dw1, dw2, dw3;
8093 int vf, pos;
8094 u16 req_id, pf_func;
8095
8096 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8097 adapter->num_vfs == 0)
8098 goto skip_bad_vf_detection;
8099
8100 bdev = pdev->bus->self;
8101 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8102 bdev = bdev->bus->self;
8103
8104 if (!bdev)
8105 goto skip_bad_vf_detection;
8106
8107 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8108 if (!pos)
8109 goto skip_bad_vf_detection;
8110
8111 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8112 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8113 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8114 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8115
8116 req_id = dw1 >> 16;
8117 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8118 if (!(req_id & 0x0080))
8119 goto skip_bad_vf_detection;
8120
8121 pf_func = req_id & 0x01;
8122 if ((pf_func & 1) == (pdev->devfn & 1)) {
8123 unsigned int device_id;
8124
8125 vf = (req_id & 0x7F) >> 1;
8126 e_dev_err("VF %d has caused a PCIe error\n", vf);
8127 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8128 "%8.8x\tdw3: %8.8x\n",
8129 dw0, dw1, dw2, dw3);
8130 switch (adapter->hw.mac.type) {
8131 case ixgbe_mac_82599EB:
8132 device_id = IXGBE_82599_VF_DEVICE_ID;
8133 break;
8134 case ixgbe_mac_X540:
8135 device_id = IXGBE_X540_VF_DEVICE_ID;
8136 break;
8137 default:
8138 device_id = 0;
8139 break;
8140 }
8141
8142 /* Find the pci device of the offending VF */
8143 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8144 while (vfdev) {
8145 if (vfdev->devfn == (req_id & 0xFF))
8146 break;
8147 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8148 device_id, vfdev);
8149 }
8150 /*
8151 * There's a slim chance the VF could have been hot plugged,
8152 * so if it is no longer present we don't need to issue the
8153 * VFLR. Just clean up the AER in that case.
8154 */
8155 if (vfdev) {
8156 e_dev_err("Issuing VFLR to VF %d\n", vf);
8157 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8158 }
8159
8160 pci_cleanup_aer_uncorrect_error_status(pdev);
8161 }
8162
8163 /*
8164 * Even though the error may have occurred on the other port
8165 * we still need to increment the vf error reference count for
8166 * both ports because the I/O resume function will be called
8167 * for both of them.
8168 */
8169 adapter->vferr_refcount++;
8170
8171 return PCI_ERS_RESULT_RECOVERED;
8172
8173skip_bad_vf_detection:
8174#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008175 netif_device_detach(netdev);
8176
Breno Leitao3044b8d2009-05-06 10:44:26 +00008177 if (state == pci_channel_io_perm_failure)
8178 return PCI_ERS_RESULT_DISCONNECT;
8179
Auke Kok9a799d72007-09-15 14:07:45 -07008180 if (netif_running(netdev))
8181 ixgbe_down(adapter);
8182 pci_disable_device(pdev);
8183
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008184 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008185 return PCI_ERS_RESULT_NEED_RESET;
8186}
8187
8188/**
8189 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8190 * @pdev: Pointer to PCI device
8191 *
8192 * Restart the card from scratch, as if from a cold-boot.
8193 */
8194static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8195{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008196 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008197 pci_ers_result_t result;
8198 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008199
gouji-new9ce77662009-05-06 10:44:45 +00008200 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008201 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008202 result = PCI_ERS_RESULT_DISCONNECT;
8203 } else {
8204 pci_set_master(pdev);
8205 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008206 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008207
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008208 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008209
8210 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008211 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008212 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008213 }
Auke Kok9a799d72007-09-15 14:07:45 -07008214
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008215 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8216 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008217 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8218 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008219 /* non-fatal, continue */
8220 }
Auke Kok9a799d72007-09-15 14:07:45 -07008221
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008222 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008223}
8224
8225/**
8226 * ixgbe_io_resume - called when traffic can start flowing again.
8227 * @pdev: Pointer to PCI device
8228 *
8229 * This callback is called when the error recovery driver tells us that
8230 * its OK to resume normal operation.
8231 */
8232static void ixgbe_io_resume(struct pci_dev *pdev)
8233{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008234 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8235 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008236
Greg Rose83c61fa2011-09-07 05:59:35 +00008237#ifdef CONFIG_PCI_IOV
8238 if (adapter->vferr_refcount) {
8239 e_info(drv, "Resuming after VF err\n");
8240 adapter->vferr_refcount--;
8241 return;
8242 }
8243
8244#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008245 if (netif_running(netdev))
8246 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008247
8248 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008249}
8250
8251static struct pci_error_handlers ixgbe_err_handler = {
8252 .error_detected = ixgbe_io_error_detected,
8253 .slot_reset = ixgbe_io_slot_reset,
8254 .resume = ixgbe_io_resume,
8255};
8256
8257static struct pci_driver ixgbe_driver = {
8258 .name = ixgbe_driver_name,
8259 .id_table = ixgbe_pci_tbl,
8260 .probe = ixgbe_probe,
8261 .remove = __devexit_p(ixgbe_remove),
8262#ifdef CONFIG_PM
8263 .suspend = ixgbe_suspend,
8264 .resume = ixgbe_resume,
8265#endif
8266 .shutdown = ixgbe_shutdown,
8267 .err_handler = &ixgbe_err_handler
8268};
8269
8270/**
8271 * ixgbe_init_module - Driver Registration Routine
8272 *
8273 * ixgbe_init_module is the first routine called when the driver is
8274 * loaded. All it does is register with the PCI subsystem.
8275 **/
8276static int __init ixgbe_init_module(void)
8277{
8278 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008279 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008280 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008281
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008282#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008283 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008284#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008285
Auke Kok9a799d72007-09-15 14:07:45 -07008286 ret = pci_register_driver(&ixgbe_driver);
8287 return ret;
8288}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008289
Auke Kok9a799d72007-09-15 14:07:45 -07008290module_init(ixgbe_init_module);
8291
8292/**
8293 * ixgbe_exit_module - Driver Exit Cleanup Routine
8294 *
8295 * ixgbe_exit_module is called just before the driver is removed
8296 * from memory.
8297 **/
8298static void __exit ixgbe_exit_module(void)
8299{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008300#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008301 dca_unregister_notify(&dca_notifier);
8302#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008303 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008304 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008305}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008306
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008307#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008308static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008309 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008310{
8311 int ret_val;
8312
8313 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008314 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008315
8316 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8317}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008318
Alexander Duyckb4533682009-03-31 21:32:42 +00008319#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008320
Auke Kok9a799d72007-09-15 14:07:45 -07008321module_exit(ixgbe_exit_module);
8322
8323/* ixgbe_main.c */