blob: 40d729eb14439bae2ca10ef62b66025d4e9a1e58 [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),
Alexander Duyckf8003262012-03-03 02:35:52 +0000472 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000473 }
474 }
475
476 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000477 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000478 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000479 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000480 else
Joe Perchesc7689572010-09-07 21:35:17 +0000481 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000482
483 }
484 }
485
486exit:
487 return;
488}
489
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800490static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
491{
492 u32 ctrl_ext;
493
494 /* Let firmware take over control of h/w */
495 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
496 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000497 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800498}
499
500static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
501{
502 u32 ctrl_ext;
503
504 /* Let firmware know the driver has taken over */
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}
Auke Kok9a799d72007-09-15 14:07:45 -0700509
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000510/*
511 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
512 * @adapter: pointer to adapter struct
513 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
514 * @queue: queue to map the corresponding interrupt to
515 * @msix_vector: the vector to map to the corresponding queue
516 *
517 */
518static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000519 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700520{
521 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000522 struct ixgbe_hw *hw = &adapter->hw;
523 switch (hw->mac.type) {
524 case ixgbe_mac_82598EB:
525 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
526 if (direction == -1)
527 direction = 0;
528 index = (((direction * 64) + queue) >> 2) & 0x1F;
529 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
530 ivar &= ~(0xFF << (8 * (queue & 0x3)));
531 ivar |= (msix_vector << (8 * (queue & 0x3)));
532 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
533 break;
534 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800535 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000536 if (direction == -1) {
537 /* other causes */
538 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
539 index = ((queue & 1) * 8);
540 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
541 ivar &= ~(0xFF << index);
542 ivar |= (msix_vector << index);
543 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
544 break;
545 } else {
546 /* tx or rx causes */
547 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
548 index = ((16 * (queue & 1)) + (8 * direction));
549 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
550 ivar &= ~(0xFF << index);
551 ivar |= (msix_vector << index);
552 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
553 break;
554 }
555 default:
556 break;
557 }
Auke Kok9a799d72007-09-15 14:07:45 -0700558}
559
Alexander Duyckfe49f042009-06-04 16:00:09 +0000560static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000561 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000562{
563 u32 mask;
564
Alexander Duyckbd508172010-11-16 19:27:03 -0800565 switch (adapter->hw.mac.type) {
566 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000567 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800569 break;
570 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800571 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572 mask = (qmask & 0xFFFFFFFF);
573 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
574 mask = (qmask >> 32);
575 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800576 break;
577 default:
578 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000579 }
580}
581
Alexander Duyckd3d00232011-07-15 02:31:25 +0000582static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
583 struct ixgbe_tx_buffer *tx_buffer)
584{
585 if (tx_buffer->dma) {
586 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
587 dma_unmap_page(ring->dev,
588 tx_buffer->dma,
589 tx_buffer->length,
590 DMA_TO_DEVICE);
591 else
592 dma_unmap_single(ring->dev,
593 tx_buffer->dma,
594 tx_buffer->length,
595 DMA_TO_DEVICE);
596 }
597 tx_buffer->dma = 0;
598}
599
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800600void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
601 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700602{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000603 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
604 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700605 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000606 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700607 /* tx_buffer_info must be completely set up in the transmit path */
608}
609
John Fastabendc84d3242010-11-16 19:27:12 -0800610static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700611{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700612 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800613 struct ixgbe_hw_stats *hwstats = &adapter->stats;
614 u32 data = 0;
615 u32 xoff[8] = {0};
616 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700617
John Fastabendc84d3242010-11-16 19:27:12 -0800618 if ((hw->fc.current_mode == ixgbe_fc_full) ||
619 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
620 switch (hw->mac.type) {
621 case ixgbe_mac_82598EB:
622 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
623 break;
624 default:
625 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
626 }
627 hwstats->lxoffrxc += data;
628
629 /* refill credits (no tx hang) if we received xoff */
630 if (!data)
631 return;
632
633 for (i = 0; i < adapter->num_tx_queues; i++)
634 clear_bit(__IXGBE_HANG_CHECK_ARMED,
635 &adapter->tx_ring[i]->state);
636 return;
637 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
638 return;
639
640 /* update stats for each tc, only valid with PFC enabled */
641 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
642 switch (hw->mac.type) {
643 case ixgbe_mac_82598EB:
644 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
645 break;
646 default:
647 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
648 }
649 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700650 }
651
John Fastabendc84d3242010-11-16 19:27:12 -0800652 /* disarm tx queues that have received xoff frames */
653 for (i = 0; i < adapter->num_tx_queues; i++) {
654 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000655 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800656
657 if (xoff[tc])
658 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
659 }
660}
661
662static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
663{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000664 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800665}
666
667static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
668{
669 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
670 struct ixgbe_hw *hw = &adapter->hw;
671
672 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
673 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
674
675 if (head != tail)
676 return (head < tail) ?
677 tail - head : (tail + ring->count - head);
678
679 return 0;
680}
681
682static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
683{
684 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
685 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
686 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
687 bool ret = false;
688
689 clear_check_for_tx_hang(tx_ring);
690
691 /*
692 * Check for a hung queue, but be thorough. This verifies
693 * that a transmit has been completed since the previous
694 * check AND there is at least one packet pending. The
695 * ARMED bit is set to indicate a potential hang. The
696 * bit is cleared if a pause frame is received to remove
697 * false hang detection due to PFC or 802.3x frames. By
698 * requiring this to fail twice we avoid races with
699 * pfc clearing the ARMED bit and conditions where we
700 * run the check_tx_hang logic with a transmit completion
701 * pending but without time to complete it yet.
702 */
703 if ((tx_done_old == tx_done) && tx_pending) {
704 /* make sure it is true for two checks in a row */
705 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
706 &tx_ring->state);
707 } else {
708 /* update completed stats and continue */
709 tx_ring->tx_stats.tx_done_old = tx_done;
710 /* reset the countdown */
711 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
712 }
713
714 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700715}
716
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000717/**
718 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
719 * @adapter: driver private struct
720 **/
721static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
722{
723
724 /* Do the reset outside of interrupt context */
725 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
726 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
727 ixgbe_service_event_schedule(adapter);
728 }
729}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700730
Auke Kok9a799d72007-09-15 14:07:45 -0700731/**
732 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000733 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700734 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700735 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000736static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000737 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700738{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000739 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000740 struct ixgbe_tx_buffer *tx_buffer;
741 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700742 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000743 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000744 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700745
Alexander Duyckd3d00232011-07-15 02:31:25 +0000746 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000747 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800748
Alexander Duyck30065e62011-07-15 03:05:14 +0000749 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000750 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700751
Alexander Duyckd3d00232011-07-15 02:31:25 +0000752 /* if next_to_watch is not set then there is no work pending */
753 if (!eop_desc)
754 break;
755
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000756 /* prevent any other reads prior to eop_desc */
757 rmb();
758
Alexander Duyckd3d00232011-07-15 02:31:25 +0000759 /* if DD is not set pending work has not been completed */
760 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
761 break;
762
Alexander Duyckd3d00232011-07-15 02:31:25 +0000763 /* clear next_to_watch to prevent false hangs */
764 tx_buffer->next_to_watch = NULL;
765
Alexander Duyck091a6242012-02-08 07:51:01 +0000766 /* update the statistics for this packet */
767 total_bytes += tx_buffer->bytecount;
768 total_packets += tx_buffer->gso_segs;
769
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000770 /* free the skb */
771 dev_kfree_skb_any(tx_buffer->skb);
772
773 /* clear tx_buffer data */
774 tx_buffer->skb = NULL;
775
Alexander Duyckd3d00232011-07-15 02:31:25 +0000776 do {
777 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Alexander Duyck091a6242012-02-08 07:51:01 +0000778 if (likely(tx_desc == eop_desc))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000779 eop_desc = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800780
Alexander Duyckd3d00232011-07-15 02:31:25 +0000781 tx_buffer++;
782 tx_desc++;
783 i++;
784 if (unlikely(i == tx_ring->count)) {
785 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700786
Alexander Duyckd3d00232011-07-15 02:31:25 +0000787 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000788 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000789 }
790
791 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800792 }
793
Auke Kok9a799d72007-09-15 14:07:45 -0700794 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000795 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800796 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000797 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000798 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000799 q_vector->tx.total_bytes += total_bytes;
800 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800801
John Fastabendc84d3242010-11-16 19:27:12 -0800802 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800803 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800804 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycke4f74022012-01-31 02:59:44 +0000805 tx_desc = IXGBE_TX_DESC(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800806 e_err(drv, "Detected Tx Unit Hang\n"
807 " Tx Queue <%d>\n"
808 " TDH, TDT <%x>, <%x>\n"
809 " next_to_use <%x>\n"
810 " next_to_clean <%x>\n"
811 "tx_buffer_info[next_to_clean]\n"
812 " time_stamp <%lx>\n"
813 " jiffies <%lx>\n",
814 tx_ring->queue_index,
815 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
816 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000817 tx_ring->next_to_use, i,
818 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800819
820 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
821
822 e_info(probe,
823 "tx hang %d detected on queue %d, resetting adapter\n",
824 adapter->tx_timeout_count + 1, tx_ring->queue_index);
825
826 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000827 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800828
829 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000830 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800831 }
Auke Kok9a799d72007-09-15 14:07:45 -0700832
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000833 netdev_tx_completed_queue(txring_txq(tx_ring),
834 total_packets, total_bytes);
835
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800836#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000837 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000838 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800839 /* Make sure that anybody stopping the queue after this
840 * sees the new next_to_clean.
841 */
842 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800843 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800844 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800845 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800846 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800847 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800848 }
Auke Kok9a799d72007-09-15 14:07:45 -0700849
Alexander Duyck59224552011-08-31 00:01:06 +0000850 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700851}
852
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400853#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800854static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800855 struct ixgbe_ring *tx_ring,
856 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800857{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000858 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000859 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
860 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800861
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800862 switch (hw->mac.type) {
863 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000864 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800865 break;
866 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800867 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000868 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
869 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
870 break;
871 default:
872 /* for unknown hardware do not write register */
873 return;
874 }
875
876 /*
877 * We can enable relaxed ordering for reads, but not writes when
878 * DCA is enabled. This is due to a known issue in some chipsets
879 * which will cause the DCA tag to be cleared.
880 */
881 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
882 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
883 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
884
885 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
886}
887
888static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
889 struct ixgbe_ring *rx_ring,
890 int cpu)
891{
892 struct ixgbe_hw *hw = &adapter->hw;
893 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
894 u8 reg_idx = rx_ring->reg_idx;
895
896
897 switch (hw->mac.type) {
898 case ixgbe_mac_82599EB:
899 case ixgbe_mac_X540:
900 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800901 break;
902 default:
903 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800904 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000905
906 /*
907 * We can enable relaxed ordering for reads, but not writes when
908 * DCA is enabled. This is due to a known issue in some chipsets
909 * which will cause the DCA tag to be cleared.
910 */
911 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
912 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
913 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
914
915 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800916}
917
918static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
919{
920 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000921 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800922 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800923
924 if (q_vector->cpu == cpu)
925 goto out_no_update;
926
Alexander Duycka5579282012-02-08 07:50:04 +0000927 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000928 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800929
Alexander Duycka5579282012-02-08 07:50:04 +0000930 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000931 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800932
933 q_vector->cpu = cpu;
934out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800935 put_cpu();
936}
937
938static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
939{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800940 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800941 int i;
942
943 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
944 return;
945
Alexander Duycke35ec122009-05-21 13:07:12 +0000946 /* always use CB2 mode, difference is masked in the CB driver */
947 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
948
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800949 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
950 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
951 else
952 num_q_vectors = 1;
953
954 for (i = 0; i < num_q_vectors; i++) {
955 adapter->q_vector[i]->cpu = -1;
956 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800957 }
958}
959
960static int __ixgbe_notify_dca(struct device *dev, void *data)
961{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800962 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800963 unsigned long event = *(unsigned long *)data;
964
Don Skidmore2a72c312011-07-20 02:27:05 +0000965 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800966 return 0;
967
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800968 switch (event) {
969 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700970 /* if we're already enabled, don't do it again */
971 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
972 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300973 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700974 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800975 ixgbe_setup_dca(adapter);
976 break;
977 }
978 /* Fall Through since DCA is disabled. */
979 case DCA_PROVIDER_REMOVE:
980 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
981 dca_remove_requester(dev);
982 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
983 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
984 }
985 break;
986 }
987
Denis V. Lunev652f0932008-03-27 14:39:17 +0300988 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800989}
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000990
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000991#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +0000992static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
993 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000994 struct sk_buff *skb)
995{
Alexander Duyck8a0da212012-01-31 02:59:49 +0000996 if (ring->netdev->features & NETIF_F_RXHASH)
997 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000998}
999
Alexander Duyckf8003262012-03-03 02:35:52 +00001000#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001001/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001002 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1003 * @adapter: address of board private structure
1004 * @rx_desc: advanced rx descriptor
1005 *
1006 * Returns : true if it is FCoE pkt
1007 */
1008static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1009 union ixgbe_adv_rx_desc *rx_desc)
1010{
1011 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1012
1013 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1014 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1015 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1016 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1017}
1018
Alexander Duyckf8003262012-03-03 02:35:52 +00001019#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001020/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001021 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001022 * @ring: structure containing ring specific data
1023 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001024 * @skb: skb currently being received and modified
1025 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001026static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001027 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001028 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001029{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001030 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001031
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001032 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001033 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001034 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001035
1036 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001037 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1038 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001039 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001040 return;
1041 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001042
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001043 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001044 return;
1045
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001046 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001047 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001048
1049 /*
1050 * 82599 errata, UDP frames with a 0 checksum can be marked as
1051 * checksum errors.
1052 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001053 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1054 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001055 return;
1056
Alexander Duyck8a0da212012-01-31 02:59:49 +00001057 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001058 return;
1059 }
1060
Auke Kok9a799d72007-09-15 14:07:45 -07001061 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001062 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001063}
1064
Alexander Duyck84ea2592010-11-16 19:26:49 -08001065static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001066{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001067 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001068
1069 /* update next to alloc since we have filled the ring */
1070 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001071 /*
1072 * Force memory writes to complete before letting h/w
1073 * know there are new descriptors to fetch. (Only
1074 * applicable for weak-ordered memory model archs,
1075 * such as IA-64).
1076 */
1077 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001078 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001079}
1080
Alexander Duyckf990b792012-01-31 02:59:34 +00001081static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1082 struct ixgbe_rx_buffer *bi)
1083{
1084 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001085 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001086
Alexander Duyckf8003262012-03-03 02:35:52 +00001087 /* since we are recycling buffers we should seldom need to alloc */
1088 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001089 return true;
1090
Alexander Duyckf8003262012-03-03 02:35:52 +00001091 /* alloc new page for storage */
1092 if (likely(!page)) {
1093 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1094 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001095 if (unlikely(!page)) {
1096 rx_ring->rx_stats.alloc_rx_page_failed++;
1097 return false;
1098 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001099 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001100 }
1101
Alexander Duyckf8003262012-03-03 02:35:52 +00001102 /* map page for use */
1103 dma = dma_map_page(rx_ring->dev, page, 0,
1104 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001105
Alexander Duyckf8003262012-03-03 02:35:52 +00001106 /*
1107 * if mapping failed free memory back to system since
1108 * there isn't much point in holding memory we can't use
1109 */
1110 if (dma_mapping_error(rx_ring->dev, dma)) {
1111 put_page(page);
1112 bi->page = NULL;
1113
Alexander Duyckf990b792012-01-31 02:59:34 +00001114 rx_ring->rx_stats.alloc_rx_page_failed++;
1115 return false;
1116 }
1117
Alexander Duyckf8003262012-03-03 02:35:52 +00001118 bi->dma = dma;
1119 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1120
Alexander Duyckf990b792012-01-31 02:59:34 +00001121 return true;
1122}
1123
Auke Kok9a799d72007-09-15 14:07:45 -07001124/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001125 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001126 * @rx_ring: ring to place buffers on
1127 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001128 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001129void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001130{
Auke Kok9a799d72007-09-15 14:07:45 -07001131 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001132 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001133 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001134
Alexander Duyckf8003262012-03-03 02:35:52 +00001135 /* nothing to do */
1136 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001137 return;
1138
Alexander Duycke4f74022012-01-31 02:59:44 +00001139 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001140 bi = &rx_ring->rx_buffer_info[i];
1141 i -= rx_ring->count;
1142
Alexander Duyckf8003262012-03-03 02:35:52 +00001143 do {
1144 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001145 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001146
Alexander Duyckf8003262012-03-03 02:35:52 +00001147 /*
1148 * Refresh the desc even if buffer_addrs didn't change
1149 * because each write-back erases this info.
1150 */
1151 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001152
Alexander Duyckf990b792012-01-31 02:59:34 +00001153 rx_desc++;
1154 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001155 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001156 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001157 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001158 bi = rx_ring->rx_buffer_info;
1159 i -= rx_ring->count;
1160 }
1161
1162 /* clear the hdr_addr for the next_to_use descriptor */
1163 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001164
1165 cleaned_count--;
1166 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001167
Alexander Duyckf990b792012-01-31 02:59:34 +00001168 i += rx_ring->count;
1169
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001170 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001171 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001172}
1173
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001174/**
1175 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1176 * @data: pointer to the start of the headers
1177 * @max_len: total length of section to find headers in
1178 *
1179 * This function is meant to determine the length of headers that will
1180 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1181 * motivation of doing this is to only perform one pull for IPv4 TCP
1182 * packets so that we can do basic things like calculating the gso_size
1183 * based on the average data per packet.
1184 **/
1185static unsigned int ixgbe_get_headlen(unsigned char *data,
1186 unsigned int max_len)
1187{
1188 union {
1189 unsigned char *network;
1190 /* l2 headers */
1191 struct ethhdr *eth;
1192 struct vlan_hdr *vlan;
1193 /* l3 headers */
1194 struct iphdr *ipv4;
1195 } hdr;
1196 __be16 protocol;
1197 u8 nexthdr = 0; /* default to not TCP */
1198 u8 hlen;
1199
1200 /* this should never happen, but better safe than sorry */
1201 if (max_len < ETH_HLEN)
1202 return max_len;
1203
1204 /* initialize network frame pointer */
1205 hdr.network = data;
1206
1207 /* set first protocol and move network header forward */
1208 protocol = hdr.eth->h_proto;
1209 hdr.network += ETH_HLEN;
1210
1211 /* handle any vlan tag if present */
1212 if (protocol == __constant_htons(ETH_P_8021Q)) {
1213 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1214 return max_len;
1215
1216 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1217 hdr.network += VLAN_HLEN;
1218 }
1219
1220 /* handle L3 protocols */
1221 if (protocol == __constant_htons(ETH_P_IP)) {
1222 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1223 return max_len;
1224
1225 /* access ihl as a u8 to avoid unaligned access on ia64 */
1226 hlen = (hdr.network[0] & 0x0F) << 2;
1227
1228 /* verify hlen meets minimum size requirements */
1229 if (hlen < sizeof(struct iphdr))
1230 return hdr.network - data;
1231
1232 /* record next protocol */
1233 nexthdr = hdr.ipv4->protocol;
1234 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001235#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001236 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1237 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1238 return max_len;
1239 hdr.network += FCOE_HEADER_LEN;
1240#endif
1241 } else {
1242 return hdr.network - data;
1243 }
1244
1245 /* finally sort out TCP */
1246 if (nexthdr == IPPROTO_TCP) {
1247 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1248 return max_len;
1249
1250 /* access doff as a u8 to avoid unaligned access on ia64 */
1251 hlen = (hdr.network[12] & 0xF0) >> 2;
1252
1253 /* verify hlen meets minimum size requirements */
1254 if (hlen < sizeof(struct tcphdr))
1255 return hdr.network - data;
1256
1257 hdr.network += hlen;
1258 }
1259
1260 /*
1261 * If everything has gone correctly hdr.network should be the
1262 * data section of the packet and will be the end of the header.
1263 * If not then it probably represents the end of the last recognized
1264 * header.
1265 */
1266 if ((hdr.network - data) < max_len)
1267 return hdr.network - data;
1268 else
1269 return max_len;
1270}
1271
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001272static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1273 union ixgbe_adv_rx_desc *rx_desc,
1274 struct sk_buff *skb)
1275{
1276 __le32 rsc_enabled;
1277 u32 rsc_cnt;
1278
1279 if (!ring_is_rsc_enabled(rx_ring))
1280 return;
1281
1282 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1283 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1284
1285 /* If this is an RSC frame rsc_cnt should be non-zero */
1286 if (!rsc_enabled)
1287 return;
1288
1289 rsc_cnt = le32_to_cpu(rsc_enabled);
1290 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1291
1292 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001293}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001294
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001295static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1296 struct sk_buff *skb)
1297{
Alexander Duyckf8003262012-03-03 02:35:52 +00001298 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001299
1300 /* set gso_size to avoid messing up TCP MSS */
1301 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1302 IXGBE_CB(skb)->append_cnt);
1303}
1304
1305static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1306 struct sk_buff *skb)
1307{
1308 /* if append_cnt is 0 then frame is not RSC */
1309 if (!IXGBE_CB(skb)->append_cnt)
1310 return;
1311
1312 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1313 rx_ring->rx_stats.rsc_flush++;
1314
1315 ixgbe_set_rsc_gso_size(rx_ring, skb);
1316
1317 /* gso_size is computed using append_cnt so always clear it last */
1318 IXGBE_CB(skb)->append_cnt = 0;
1319}
1320
Alexander Duyck8a0da212012-01-31 02:59:49 +00001321/**
1322 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1323 * @rx_ring: rx descriptor ring packet is being transacted on
1324 * @rx_desc: pointer to the EOP Rx descriptor
1325 * @skb: pointer to current skb being populated
1326 *
1327 * This function checks the ring, descriptor, and packet information in
1328 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1329 * other fields within the skb.
1330 **/
1331static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1332 union ixgbe_adv_rx_desc *rx_desc,
1333 struct sk_buff *skb)
1334{
1335 ixgbe_update_rsc_stats(rx_ring, skb);
1336
1337 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1338
1339 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1340
1341 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1342 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1343 __vlan_hwaccel_put_tag(skb, vid);
1344 }
1345
1346 skb_record_rx_queue(skb, rx_ring->queue_index);
1347
1348 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1349}
1350
1351static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1352 struct sk_buff *skb)
1353{
1354 struct ixgbe_adapter *adapter = q_vector->adapter;
1355
1356 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1357 napi_gro_receive(&q_vector->napi, skb);
1358 else
1359 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001360}
1361
Alexander Duyckf8003262012-03-03 02:35:52 +00001362/**
1363 * ixgbe_is_non_eop - process handling of non-EOP buffers
1364 * @rx_ring: Rx ring being processed
1365 * @rx_desc: Rx descriptor for current buffer
1366 * @skb: Current socket buffer containing buffer in progress
1367 *
1368 * This function updates next to clean. If the buffer is an EOP buffer
1369 * this function exits returning false, otherwise it will place the
1370 * sk_buff in the next buffer to be chained and return true indicating
1371 * that this is in fact a non-EOP buffer.
1372 **/
1373static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1374 union ixgbe_adv_rx_desc *rx_desc,
1375 struct sk_buff *skb)
1376{
1377 u32 ntc = rx_ring->next_to_clean + 1;
1378
1379 /* fetch, update, and store next to clean */
1380 ntc = (ntc < rx_ring->count) ? ntc : 0;
1381 rx_ring->next_to_clean = ntc;
1382
1383 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1384
1385 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1386 return false;
1387
1388 /* append_cnt indicates packet is RSC, if so fetch nextp */
1389 if (IXGBE_CB(skb)->append_cnt) {
1390 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1391 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1392 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1393 }
1394
1395 /* place skb in next buffer to be received */
1396 rx_ring->rx_buffer_info[ntc].skb = skb;
1397 rx_ring->rx_stats.non_eop_descs++;
1398
1399 return true;
1400}
1401
1402/**
1403 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1404 * @rx_ring: rx descriptor ring packet is being transacted on
1405 * @rx_desc: pointer to the EOP Rx descriptor
1406 * @skb: pointer to current skb being fixed
1407 *
1408 * Check for corrupted packet headers caused by senders on the local L2
1409 * embedded NIC switch not setting up their Tx Descriptors right. These
1410 * should be very rare.
1411 *
1412 * Also address the case where we are pulling data in on pages only
1413 * and as such no data is present in the skb header.
1414 *
1415 * In addition if skb is not at least 60 bytes we need to pad it so that
1416 * it is large enough to qualify as a valid Ethernet frame.
1417 *
1418 * Returns true if an error was encountered and skb was freed.
1419 **/
1420static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1421 union ixgbe_adv_rx_desc *rx_desc,
1422 struct sk_buff *skb)
1423{
1424 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1425 struct net_device *netdev = rx_ring->netdev;
1426 unsigned char *va;
1427 unsigned int pull_len;
1428
1429 /* if the page was released unmap it, else just sync our portion */
1430 if (unlikely(IXGBE_CB(skb)->page_released)) {
1431 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1432 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1433 IXGBE_CB(skb)->page_released = false;
1434 } else {
1435 dma_sync_single_range_for_cpu(rx_ring->dev,
1436 IXGBE_CB(skb)->dma,
1437 frag->page_offset,
1438 ixgbe_rx_bufsz(rx_ring),
1439 DMA_FROM_DEVICE);
1440 }
1441 IXGBE_CB(skb)->dma = 0;
1442
1443 /* verify that the packet does not have any known errors */
1444 if (unlikely(ixgbe_test_staterr(rx_desc,
1445 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1446 !(netdev->features & NETIF_F_RXALL))) {
1447 dev_kfree_skb_any(skb);
1448 return true;
1449 }
1450
1451 /*
1452 * it is valid to use page_address instead of kmap since we are
1453 * working with pages allocated out of the lomem pool per
1454 * alloc_page(GFP_ATOMIC)
1455 */
1456 va = skb_frag_address(frag);
1457
1458 /*
1459 * we need the header to contain the greater of either ETH_HLEN or
1460 * 60 bytes if the skb->len is less than 60 for skb_pad.
1461 */
1462 pull_len = skb_frag_size(frag);
1463 if (pull_len > 256)
1464 pull_len = ixgbe_get_headlen(va, pull_len);
1465
1466 /* align pull length to size of long to optimize memcpy performance */
1467 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1468
1469 /* update all of the pointers */
1470 skb_frag_size_sub(frag, pull_len);
1471 frag->page_offset += pull_len;
1472 skb->data_len -= pull_len;
1473 skb->tail += pull_len;
1474
1475 /*
1476 * if we sucked the frag empty then we should free it,
1477 * if there are other frags here something is screwed up in hardware
1478 */
1479 if (skb_frag_size(frag) == 0) {
1480 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1481 skb_shinfo(skb)->nr_frags = 0;
1482 __skb_frag_unref(frag);
1483 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1484 }
1485
1486 /* if skb_pad returns an error the skb was freed */
1487 if (unlikely(skb->len < 60)) {
1488 int pad_len = 60 - skb->len;
1489
1490 if (skb_pad(skb, pad_len))
1491 return true;
1492 __skb_put(skb, pad_len);
1493 }
1494
1495 return false;
1496}
1497
1498/**
1499 * ixgbe_can_reuse_page - determine if we can reuse a page
1500 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1501 *
1502 * Returns true if page can be reused in another Rx buffer
1503 **/
1504static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1505{
1506 struct page *page = rx_buffer->page;
1507
1508 /* if we are only owner of page and it is local we can reuse it */
1509 return likely(page_count(page) == 1) &&
1510 likely(page_to_nid(page) == numa_node_id());
1511}
1512
1513/**
1514 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1515 * @rx_ring: rx descriptor ring to store buffers on
1516 * @old_buff: donor buffer to have page reused
1517 *
1518 * Syncronizes page for reuse by the adapter
1519 **/
1520static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1521 struct ixgbe_rx_buffer *old_buff)
1522{
1523 struct ixgbe_rx_buffer *new_buff;
1524 u16 nta = rx_ring->next_to_alloc;
1525 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1526
1527 new_buff = &rx_ring->rx_buffer_info[nta];
1528
1529 /* update, and store next to alloc */
1530 nta++;
1531 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1532
1533 /* transfer page from old buffer to new buffer */
1534 new_buff->page = old_buff->page;
1535 new_buff->dma = old_buff->dma;
1536
1537 /* flip page offset to other buffer and store to new_buff */
1538 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1539
1540 /* sync the buffer for use by the device */
1541 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1542 new_buff->page_offset, bufsz,
1543 DMA_FROM_DEVICE);
1544
1545 /* bump ref count on page before it is given to the stack */
1546 get_page(new_buff->page);
1547}
1548
1549/**
1550 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1551 * @rx_ring: rx descriptor ring to transact packets on
1552 * @rx_buffer: buffer containing page to add
1553 * @rx_desc: descriptor containing length of buffer written by hardware
1554 * @skb: sk_buff to place the data into
1555 *
1556 * This function is based on skb_add_rx_frag. I would have used that
1557 * function however it doesn't handle the truesize case correctly since we
1558 * are allocating more memory than might be used for a single receive.
1559 **/
1560static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1561 struct ixgbe_rx_buffer *rx_buffer,
1562 struct sk_buff *skb, int size)
1563{
1564 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1565 rx_buffer->page, rx_buffer->page_offset,
1566 size);
1567 skb->len += size;
1568 skb->data_len += size;
1569 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1570}
1571
1572/**
1573 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1574 * @q_vector: structure containing interrupt and ring information
1575 * @rx_ring: rx descriptor ring to transact packets on
1576 * @budget: Total limit on number of packets to process
1577 *
1578 * This function provides a "bounce buffer" approach to Rx interrupt
1579 * processing. The advantage to this is that on systems that have
1580 * expensive overhead for IOMMU access this provides a means of avoiding
1581 * it by maintaining the mapping of the page to the syste.
1582 *
1583 * Returns true if all work is completed without reaching budget
1584 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001585static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001586 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001587 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001588{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001589 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001590#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001592 int ddp_bytes = 0;
1593#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001594 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001595
Alexander Duyckf8003262012-03-03 02:35:52 +00001596 do {
1597 struct ixgbe_rx_buffer *rx_buffer;
1598 union ixgbe_adv_rx_desc *rx_desc;
1599 struct sk_buff *skb;
1600 struct page *page;
1601 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001602
Alexander Duyckf8003262012-03-03 02:35:52 +00001603 /* return some buffers to hardware, one at a time is too slow */
1604 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1605 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1606 cleaned_count = 0;
1607 }
Auke Kok9a799d72007-09-15 14:07:45 -07001608
Alexander Duyckf8003262012-03-03 02:35:52 +00001609 ntc = rx_ring->next_to_clean;
1610 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1611 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001612
Alexander Duyckf8003262012-03-03 02:35:52 +00001613 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1614 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001615
Alexander Duyckf8003262012-03-03 02:35:52 +00001616 /*
1617 * This memory barrier is needed to keep us from reading
1618 * any other fields out of the rx_desc until we know the
1619 * RXD_STAT_DD bit is set
1620 */
1621 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001622
Alexander Duyckf8003262012-03-03 02:35:52 +00001623 page = rx_buffer->page;
1624 prefetchw(page);
1625
1626 skb = rx_buffer->skb;
1627
1628 if (likely(!skb)) {
1629 void *page_addr = page_address(page) +
1630 rx_buffer->page_offset;
1631
1632 /* prefetch first cache line of first page */
1633 prefetch(page_addr);
1634#if L1_CACHE_BYTES < 128
1635 prefetch(page_addr + L1_CACHE_BYTES);
1636#endif
1637
1638 /* allocate a skb to store the frags */
1639 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1640 IXGBE_RX_HDR_SIZE);
1641 if (unlikely(!skb)) {
1642 rx_ring->rx_stats.alloc_rx_buff_failed++;
1643 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001644 }
1645
Alexander Duyckf8003262012-03-03 02:35:52 +00001646 /*
1647 * we will be copying header into skb->data in
1648 * pskb_may_pull so it is in our interest to prefetch
1649 * it now to avoid a possible cache miss
1650 */
1651 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001652
1653 /*
1654 * Delay unmapping of the first packet. It carries the
1655 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001656 * after the writeback. Only unmap it when EOP is
1657 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001658 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001659 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001660 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001661 /* we are reusing so sync this buffer for CPU use */
1662 dma_sync_single_range_for_cpu(rx_ring->dev,
1663 rx_buffer->dma,
1664 rx_buffer->page_offset,
1665 ixgbe_rx_bufsz(rx_ring),
1666 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001667 }
1668
Alexander Duyckf8003262012-03-03 02:35:52 +00001669 /* pull page into skb */
1670 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1671 le16_to_cpu(rx_desc->wb.upper.length));
1672
1673 if (ixgbe_can_reuse_page(rx_buffer)) {
1674 /* hand second half of page back to the ring */
1675 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1676 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1677 /* the page has been released from the ring */
1678 IXGBE_CB(skb)->page_released = true;
1679 } else {
1680 /* we are not reusing the buffer so unmap it */
1681 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1682 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001683 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001684 }
1685
Alexander Duyckf8003262012-03-03 02:35:52 +00001686 /* clear contents of buffer_info */
1687 rx_buffer->skb = NULL;
1688 rx_buffer->dma = 0;
1689 rx_buffer->page = NULL;
1690
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001691 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1692
Auke Kok9a799d72007-09-15 14:07:45 -07001693 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001694
Alexander Duyckf8003262012-03-03 02:35:52 +00001695 /* place incomplete frames back on ring for completion */
1696 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1697 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001698
Alexander Duyckf8003262012-03-03 02:35:52 +00001699 /* verify the packet layout is correct */
1700 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1701 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001702
1703 /* probably a little skewed due to removing CRC */
1704 total_rx_bytes += skb->len;
1705 total_rx_packets++;
1706
Alexander Duyck8a0da212012-01-31 02:59:49 +00001707 /* populate checksum, timestamp, VLAN, and protocol */
1708 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1709
Yi Zou332d4a72009-05-13 13:11:53 +00001710#ifdef IXGBE_FCOE
1711 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001712 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001713 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001714 if (!ddp_bytes) {
1715 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001716 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001717 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001718 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001719
Yi Zou332d4a72009-05-13 13:11:53 +00001720#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001721 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001722
Alexander Duyckf8003262012-03-03 02:35:52 +00001723 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001724 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001725 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001726
Yi Zou3d8fd382009-06-08 14:38:44 +00001727#ifdef IXGBE_FCOE
1728 /* include DDPed FCoE data */
1729 if (ddp_bytes > 0) {
1730 unsigned int mss;
1731
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001732 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001733 sizeof(struct fc_frame_header) -
1734 sizeof(struct fcoe_crc_eof);
1735 if (mss > 512)
1736 mss &= ~511;
1737 total_rx_bytes += ddp_bytes;
1738 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1739 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001740
Alexander Duyckf8003262012-03-03 02:35:52 +00001741#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001742 u64_stats_update_begin(&rx_ring->syncp);
1743 rx_ring->stats.packets += total_rx_packets;
1744 rx_ring->stats.bytes += total_rx_bytes;
1745 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001746 q_vector->rx.total_packets += total_rx_packets;
1747 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001748
Alexander Duyckf8003262012-03-03 02:35:52 +00001749 if (cleaned_count)
1750 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1751
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001752 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001753}
1754
Auke Kok9a799d72007-09-15 14:07:45 -07001755/**
1756 * ixgbe_configure_msix - Configure MSI-X hardware
1757 * @adapter: board private structure
1758 *
1759 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1760 * interrupts.
1761 **/
1762static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1763{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001764 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001765 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001766 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001767
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001768 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1769
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001770 /* Populate MSIX to EITR Select */
1771 if (adapter->num_vfs > 32) {
1772 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1773 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1774 }
1775
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001776 /*
1777 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001778 * corresponding register.
1779 */
1780 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001781 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001782 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001783
Alexander Duycka5579282012-02-08 07:50:04 +00001784 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001785 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001786
Alexander Duycka5579282012-02-08 07:50:04 +00001787 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001788 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001789
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001790 if (q_vector->tx.ring && !q_vector->rx.ring) {
1791 /* tx only vector */
1792 if (adapter->tx_itr_setting == 1)
1793 q_vector->itr = IXGBE_10K_ITR;
1794 else
1795 q_vector->itr = adapter->tx_itr_setting;
1796 } else {
1797 /* rx or rx/tx vector */
1798 if (adapter->rx_itr_setting == 1)
1799 q_vector->itr = IXGBE_20K_ITR;
1800 else
1801 q_vector->itr = adapter->rx_itr_setting;
1802 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001803
Alexander Duyckfe49f042009-06-04 16:00:09 +00001804 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001805 }
1806
Alexander Duyckbd508172010-11-16 19:27:03 -08001807 switch (adapter->hw.mac.type) {
1808 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001809 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001810 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001811 break;
1812 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001813 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001814 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001815 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001816 default:
1817 break;
1818 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001819 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001820
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001821 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001822 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001823 mask &= ~(IXGBE_EIMS_OTHER |
1824 IXGBE_EIMS_MAILBOX |
1825 IXGBE_EIMS_LSC);
1826
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001827 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001828}
1829
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001830enum latency_range {
1831 lowest_latency = 0,
1832 low_latency = 1,
1833 bulk_latency = 2,
1834 latency_invalid = 255
1835};
1836
1837/**
1838 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001839 * @q_vector: structure containing interrupt and ring information
1840 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001841 *
1842 * Stores a new ITR value based on packets and byte
1843 * counts during the last interrupt. The advantage of per interrupt
1844 * computation is faster updates and more accurate ITR for the current
1845 * traffic pattern. Constants in this function were computed
1846 * based on theoretical maximum wire speed and thresholds were set based
1847 * on testing data as well as attempting to minimize response time
1848 * while increasing bulk throughput.
1849 * this functionality is controlled by the InterruptThrottleRate module
1850 * parameter (see ixgbe_param.c)
1851 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001852static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1853 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001854{
Alexander Duyckbd198052011-06-11 01:45:08 +00001855 int bytes = ring_container->total_bytes;
1856 int packets = ring_container->total_packets;
1857 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001858 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001859 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001860
1861 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001862 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001863
1864 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001865 * 0-10MB/s lowest (100000 ints/s)
1866 * 10-20MB/s low (20000 ints/s)
1867 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001868 */
1869 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001870 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001871 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1872
1873 switch (itr_setting) {
1874 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001875 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001876 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001877 break;
1878 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001879 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001880 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001881 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001882 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001883 break;
1884 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001885 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001886 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001887 break;
1888 }
1889
Alexander Duyckbd198052011-06-11 01:45:08 +00001890 /* clear work counters since we have the values we need */
1891 ring_container->total_bytes = 0;
1892 ring_container->total_packets = 0;
1893
1894 /* write updated itr to ring container */
1895 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001896}
1897
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001898/**
1899 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001900 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001901 *
1902 * This function is made to be called by ethtool and by the driver
1903 * when it needs to update EITR registers at runtime. Hardware
1904 * specific quirks/differences are taken care of here.
1905 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001906void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001907{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001908 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001909 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001910 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001911 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001912
Alexander Duyckbd508172010-11-16 19:27:03 -08001913 switch (adapter->hw.mac.type) {
1914 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001915 /* must write high and low 16 bits to reset counter */
1916 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001917 break;
1918 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001919 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001920 /*
1921 * set the WDIS bit to not clear the timer bits and cause an
1922 * immediate assertion of the interrupt
1923 */
1924 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001925 break;
1926 default:
1927 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001928 }
1929 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1930}
1931
Alexander Duyckbd198052011-06-11 01:45:08 +00001932static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001933{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001934 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001935 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001936
Alexander Duyckbd198052011-06-11 01:45:08 +00001937 ixgbe_update_itr(q_vector, &q_vector->tx);
1938 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001939
Alexander Duyck08c88332011-06-11 01:45:03 +00001940 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001941
1942 switch (current_itr) {
1943 /* counts and packets in update_itr are dependent on these numbers */
1944 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001945 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001946 break;
1947 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001948 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001949 break;
1950 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001951 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001952 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001953 default:
1954 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001955 }
1956
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001957 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001958 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001959 new_itr = (10 * new_itr * q_vector->itr) /
1960 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001961
Alexander Duyckbd198052011-06-11 01:45:08 +00001962 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001963 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001964
1965 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001966 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001967}
1968
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001969/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00001970 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00001971 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001972 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001973static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001974{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001975 struct ixgbe_hw *hw = &adapter->hw;
1976 u32 eicr = adapter->interrupt_event;
1977
Alexander Duyckf0f97782011-04-22 04:08:09 +00001978 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001979 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001980
Alexander Duyckf0f97782011-04-22 04:08:09 +00001981 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1982 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1983 return;
1984
1985 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1986
Joe Perches7ca647b2010-09-07 21:35:40 +00001987 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001988 case IXGBE_DEV_ID_82599_T3_LOM:
1989 /*
1990 * Since the warning interrupt is for both ports
1991 * we don't have to check if:
1992 * - This interrupt wasn't for our port.
1993 * - We may have missed the interrupt so always have to
1994 * check if we got a LSC
1995 */
1996 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1997 !(eicr & IXGBE_EICR_LSC))
1998 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001999
Alexander Duyckf0f97782011-04-22 04:08:09 +00002000 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2001 u32 autoneg;
2002 bool link_up = false;
2003
Joe Perches7ca647b2010-09-07 21:35:40 +00002004 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2005
Alexander Duyckf0f97782011-04-22 04:08:09 +00002006 if (link_up)
2007 return;
2008 }
2009
2010 /* Check if this is not due to overtemp */
2011 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2012 return;
2013
2014 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002015 default:
2016 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2017 return;
2018 break;
2019 }
2020 e_crit(drv,
2021 "Network adapter has been stopped because it has over heated. "
2022 "Restart the computer. If the problem persists, "
2023 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002024
2025 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002026}
2027
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002028static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2029{
2030 struct ixgbe_hw *hw = &adapter->hw;
2031
2032 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2033 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002034 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002035 /* write to clear the interrupt */
2036 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2037 }
2038}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002039
Jacob Keller4f51bf72011-08-20 04:49:45 +00002040static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2041{
2042 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2043 return;
2044
2045 switch (adapter->hw.mac.type) {
2046 case ixgbe_mac_82599EB:
2047 /*
2048 * Need to check link state so complete overtemp check
2049 * on service task
2050 */
2051 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2052 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2053 adapter->interrupt_event = eicr;
2054 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2055 ixgbe_service_event_schedule(adapter);
2056 return;
2057 }
2058 return;
2059 case ixgbe_mac_X540:
2060 if (!(eicr & IXGBE_EICR_TS))
2061 return;
2062 break;
2063 default:
2064 return;
2065 }
2066
2067 e_crit(drv,
2068 "Network adapter has been stopped because it has over heated. "
2069 "Restart the computer. If the problem persists, "
2070 "power off the system and replace the adapter\n");
2071}
2072
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002073static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2074{
2075 struct ixgbe_hw *hw = &adapter->hw;
2076
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002077 if (eicr & IXGBE_EICR_GPI_SDP2) {
2078 /* Clear the interrupt */
2079 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002080 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2081 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2082 ixgbe_service_event_schedule(adapter);
2083 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002084 }
2085
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002086 if (eicr & IXGBE_EICR_GPI_SDP1) {
2087 /* Clear the interrupt */
2088 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002089 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2090 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2091 ixgbe_service_event_schedule(adapter);
2092 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002093 }
2094}
2095
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002096static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2097{
2098 struct ixgbe_hw *hw = &adapter->hw;
2099
2100 adapter->lsc_int++;
2101 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2102 adapter->link_check_timeout = jiffies;
2103 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2104 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002105 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002106 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002107 }
2108}
2109
Alexander Duyckfe49f042009-06-04 16:00:09 +00002110static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2111 u64 qmask)
2112{
2113 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002114 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002115
Alexander Duyckbd508172010-11-16 19:27:03 -08002116 switch (hw->mac.type) {
2117 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002118 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002119 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2120 break;
2121 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002122 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002123 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002124 if (mask)
2125 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002126 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002127 if (mask)
2128 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2129 break;
2130 default:
2131 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002132 }
2133 /* skip the flush */
2134}
2135
2136static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002137 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002138{
2139 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002140 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002141
Alexander Duyckbd508172010-11-16 19:27:03 -08002142 switch (hw->mac.type) {
2143 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002144 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002145 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2146 break;
2147 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002148 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002149 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002150 if (mask)
2151 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002152 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002153 if (mask)
2154 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2155 break;
2156 default:
2157 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002158 }
2159 /* skip the flush */
2160}
2161
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002162/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002163 * ixgbe_irq_enable - Enable default interrupt generation settings
2164 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002165 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002166static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2167 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002168{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002169 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002170
Alexander Duyck2c4af692011-07-15 07:29:55 +00002171 /* don't reenable LSC while waiting for link */
2172 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2173 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002174
Alexander Duyck2c4af692011-07-15 07:29:55 +00002175 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002176 switch (adapter->hw.mac.type) {
2177 case ixgbe_mac_82599EB:
2178 mask |= IXGBE_EIMS_GPI_SDP0;
2179 break;
2180 case ixgbe_mac_X540:
2181 mask |= IXGBE_EIMS_TS;
2182 break;
2183 default:
2184 break;
2185 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002186 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2187 mask |= IXGBE_EIMS_GPI_SDP1;
2188 switch (adapter->hw.mac.type) {
2189 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002190 mask |= IXGBE_EIMS_GPI_SDP1;
2191 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002192 case ixgbe_mac_X540:
2193 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002194 mask |= IXGBE_EIMS_MAILBOX;
2195 break;
2196 default:
2197 break;
2198 }
2199 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2200 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2201 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002202
Alexander Duyck2c4af692011-07-15 07:29:55 +00002203 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2204 if (queues)
2205 ixgbe_irq_enable_queues(adapter, ~0);
2206 if (flush)
2207 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002208}
2209
Alexander Duyck2c4af692011-07-15 07:29:55 +00002210static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002211{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002212 struct ixgbe_adapter *adapter = data;
2213 struct ixgbe_hw *hw = &adapter->hw;
2214 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002215
Alexander Duyck2c4af692011-07-15 07:29:55 +00002216 /*
2217 * Workaround for Silicon errata. Use clear-by-write instead
2218 * of clear-by-read. Reading with EICS will return the
2219 * interrupt causes without clearing, which later be done
2220 * with the write to EICR.
2221 */
2222 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2223 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002224
Alexander Duyck2c4af692011-07-15 07:29:55 +00002225 if (eicr & IXGBE_EICR_LSC)
2226 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002227
Alexander Duyck2c4af692011-07-15 07:29:55 +00002228 if (eicr & IXGBE_EICR_MAILBOX)
2229 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002230
Alexander Duyck2c4af692011-07-15 07:29:55 +00002231 switch (hw->mac.type) {
2232 case ixgbe_mac_82599EB:
2233 case ixgbe_mac_X540:
2234 if (eicr & IXGBE_EICR_ECC)
2235 e_info(link, "Received unrecoverable ECC Err, please "
2236 "reboot\n");
2237 /* Handle Flow Director Full threshold interrupt */
2238 if (eicr & IXGBE_EICR_FLOW_DIR) {
2239 int reinit_count = 0;
2240 int i;
2241 for (i = 0; i < adapter->num_tx_queues; i++) {
2242 struct ixgbe_ring *ring = adapter->tx_ring[i];
2243 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2244 &ring->state))
2245 reinit_count++;
2246 }
2247 if (reinit_count) {
2248 /* no more flow director interrupts until after init */
2249 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2250 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2251 ixgbe_service_event_schedule(adapter);
2252 }
2253 }
2254 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002255 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002256 break;
2257 default:
2258 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002259 }
2260
Alexander Duyck2c4af692011-07-15 07:29:55 +00002261 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002262
Alexander Duyck2c4af692011-07-15 07:29:55 +00002263 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002264 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002265 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002266
Alexander Duyck2c4af692011-07-15 07:29:55 +00002267 return IRQ_HANDLED;
2268}
2269
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002270static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002271{
2272 struct ixgbe_q_vector *q_vector = data;
2273
Auke Kok9a799d72007-09-15 14:07:45 -07002274 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002275
2276 if (q_vector->rx.ring || q_vector->tx.ring)
2277 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002278
2279 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002280}
2281
Auke Kok9a799d72007-09-15 14:07:45 -07002282/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002283 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2284 * @adapter: board private structure
2285 *
2286 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2287 * interrupts from the kernel.
2288 **/
2289static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2290{
2291 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002292 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2293 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002294 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002295
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002296 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002297 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002298 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002299
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002300 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002301 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002302 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002303 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002304 } else if (q_vector->rx.ring) {
2305 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2306 "%s-%s-%d", netdev->name, "rx", ri++);
2307 } else if (q_vector->tx.ring) {
2308 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2309 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002310 } else {
2311 /* skip this unused q_vector */
2312 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002313 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002314 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2315 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002316 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002317 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002318 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002319 goto free_queue_irqs;
2320 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002321 /* If Flow Director is enabled, set interrupt affinity */
2322 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2323 /* assign the mask for this irq */
2324 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002325 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002326 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 }
2328
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002329 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002330 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002331 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002332 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002333 goto free_queue_irqs;
2334 }
2335
2336 return 0;
2337
2338free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002339 while (vector) {
2340 vector--;
2341 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2342 NULL);
2343 free_irq(adapter->msix_entries[vector].vector,
2344 adapter->q_vector[vector]);
2345 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2347 pci_disable_msix(adapter->pdev);
2348 kfree(adapter->msix_entries);
2349 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002350 return err;
2351}
2352
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002353/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002354 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002355 * @irq: interrupt number
2356 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002357 **/
2358static irqreturn_t ixgbe_intr(int irq, void *data)
2359{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002360 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002361 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002362 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002363 u32 eicr;
2364
Don Skidmore54037502009-02-21 15:42:56 -08002365 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002366 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002367 * before the read of EICR.
2368 */
2369 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2370
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002371 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002372 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002373 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002374 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002375 /*
2376 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002377 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002378 * have disabled interrupts due to EIAM
2379 * finish the workaround of silicon errata on 82598. Unmask
2380 * the interrupt that we masked before the EICR read.
2381 */
2382 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2383 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002384 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002385 }
Auke Kok9a799d72007-09-15 14:07:45 -07002386
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002387 if (eicr & IXGBE_EICR_LSC)
2388 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002389
Alexander Duyckbd508172010-11-16 19:27:03 -08002390 switch (hw->mac.type) {
2391 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002392 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002393 /* Fall through */
2394 case ixgbe_mac_X540:
2395 if (eicr & IXGBE_EICR_ECC)
2396 e_info(link, "Received unrecoverable ECC err, please "
2397 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002398 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002399 break;
2400 default:
2401 break;
2402 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002403
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002404 ixgbe_check_fan_failure(adapter, eicr);
2405
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002406 /* would disable interrupts here but EIAM disabled it */
2407 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002408
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002409 /*
2410 * re-enable link(maybe) and non-queue interrupts, no flush.
2411 * ixgbe_poll will re-enable the queue interrupts
2412 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002413 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2414 ixgbe_irq_enable(adapter, false, false);
2415
Auke Kok9a799d72007-09-15 14:07:45 -07002416 return IRQ_HANDLED;
2417}
2418
2419/**
2420 * ixgbe_request_irq - initialize interrupts
2421 * @adapter: board private structure
2422 *
2423 * Attempts to configure interrupts using the best available
2424 * capabilities of the hardware and kernel.
2425 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002426static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002427{
2428 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002429 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002430
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002431 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002432 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002433 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002434 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002435 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002436 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002437 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002438 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002439
Alexander Duyckde88eee2012-02-08 07:49:59 +00002440 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002441 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002442
Auke Kok9a799d72007-09-15 14:07:45 -07002443 return err;
2444}
2445
2446static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2447{
Auke Kok9a799d72007-09-15 14:07:45 -07002448 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002449 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002450
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002453 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002454 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002456 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002457 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002458 if (!adapter->q_vector[i]->rx.ring &&
2459 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002460 continue;
2461
Alexander Duyck207867f2011-07-15 03:05:37 +00002462 /* clear the affinity_mask in the IRQ descriptor */
2463 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2464 NULL);
2465
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002466 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002467 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002468 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002469 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002470 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002471 }
2472}
2473
2474/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002475 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2476 * @adapter: board private structure
2477 **/
2478static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2479{
Alexander Duyckbd508172010-11-16 19:27:03 -08002480 switch (adapter->hw.mac.type) {
2481 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002482 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002483 break;
2484 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002485 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002486 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2487 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002488 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002489 break;
2490 default:
2491 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002492 }
2493 IXGBE_WRITE_FLUSH(&adapter->hw);
2494 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2495 int i;
2496 for (i = 0; i < adapter->num_msix_vectors; i++)
2497 synchronize_irq(adapter->msix_entries[i].vector);
2498 } else {
2499 synchronize_irq(adapter->pdev->irq);
2500 }
2501}
2502
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002503/**
Auke Kok9a799d72007-09-15 14:07:45 -07002504 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2505 *
2506 **/
2507static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2508{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002509 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002510
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002511 /* rx/tx vector */
2512 if (adapter->rx_itr_setting == 1)
2513 q_vector->itr = IXGBE_20K_ITR;
2514 else
2515 q_vector->itr = adapter->rx_itr_setting;
2516
2517 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002518
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002519 ixgbe_set_ivar(adapter, 0, 0, 0);
2520 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002521
Emil Tantilov396e7992010-07-01 20:05:12 +00002522 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002523}
2524
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002525/**
2526 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2527 * @adapter: board private structure
2528 * @ring: structure containing ring specific data
2529 *
2530 * Configure the Tx descriptor ring after a reset.
2531 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002532void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2533 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002534{
2535 struct ixgbe_hw *hw = &adapter->hw;
2536 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002537 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002538 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002539 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002540
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002541 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002542 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002543 IXGBE_WRITE_FLUSH(hw);
2544
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002545 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002546 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002547 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2548 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2549 ring->count * sizeof(union ixgbe_adv_tx_desc));
2550 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2551 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002552 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002553
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002554 /*
2555 * set WTHRESH to encourage burst writeback, it should not be set
2556 * higher than 1 when ITR is 0 as it could cause false TX hangs
2557 *
2558 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2559 * to or less than the number of on chip descriptors, which is
2560 * currently 40.
2561 */
Alexander Duycke954b372012-02-08 07:49:38 +00002562 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002563 txdctl |= (1 << 16); /* WTHRESH = 1 */
2564 else
2565 txdctl |= (8 << 16); /* WTHRESH = 8 */
2566
Alexander Duycke954b372012-02-08 07:49:38 +00002567 /*
2568 * Setting PTHRESH to 32 both improves performance
2569 * and avoids a TX hang with DFP enabled
2570 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002571 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2572 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002573
2574 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002575 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2576 adapter->atr_sample_rate) {
2577 ring->atr_sample_rate = adapter->atr_sample_rate;
2578 ring->atr_count = 0;
2579 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2580 } else {
2581 ring->atr_sample_rate = 0;
2582 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002583
John Fastabendc84d3242010-11-16 19:27:12 -08002584 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2585
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002586 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002587 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2588
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002589 netdev_tx_reset_queue(txring_txq(ring));
2590
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002591 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2592 if (hw->mac.type == ixgbe_mac_82598EB &&
2593 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2594 return;
2595
2596 /* poll to verify queue is enabled */
2597 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002598 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002599 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2600 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2601 if (!wait_loop)
2602 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002603}
2604
Alexander Duyck120ff942010-08-19 13:34:50 +00002605static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2606{
2607 struct ixgbe_hw *hw = &adapter->hw;
2608 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002609 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002610 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002611
2612 if (hw->mac.type == ixgbe_mac_82598EB)
2613 return;
2614
2615 /* disable the arbiter while setting MTQC */
2616 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2617 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2618 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2619
2620 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002621 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002622 case (IXGBE_FLAG_SRIOV_ENABLED):
2623 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2624 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2625 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002626 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002627 if (!tcs)
2628 reg = IXGBE_MTQC_64Q_1PB;
2629 else if (tcs <= 4)
2630 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2631 else
2632 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2633
2634 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2635
2636 /* Enable Security TX Buffer IFG for multiple pb */
2637 if (tcs) {
2638 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2639 reg |= IXGBE_SECTX_DCB;
2640 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2641 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002642 break;
2643 }
2644
2645 /* re-enable the arbiter */
2646 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2647 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2648}
2649
Auke Kok9a799d72007-09-15 14:07:45 -07002650/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002651 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002652 * @adapter: board private structure
2653 *
2654 * Configure the Tx unit of the MAC after a reset.
2655 **/
2656static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2657{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002658 struct ixgbe_hw *hw = &adapter->hw;
2659 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002660 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002661
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002662 ixgbe_setup_mtqc(adapter);
2663
2664 if (hw->mac.type != ixgbe_mac_82598EB) {
2665 /* DMATXCTL.EN must be before Tx queues are enabled */
2666 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2667 dmatxctl |= IXGBE_DMATXCTL_TE;
2668 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2669 }
2670
Auke Kok9a799d72007-09-15 14:07:45 -07002671 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002672 for (i = 0; i < adapter->num_tx_queues; i++)
2673 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002674}
2675
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002676#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002677
Yi Zoua6616b42009-08-06 13:05:23 +00002678static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002679 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002680{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002681 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002682 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002683
Alexander Duyckbd508172010-11-16 19:27:03 -08002684 switch (adapter->hw.mac.type) {
2685 case ixgbe_mac_82598EB: {
2686 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2687 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002688 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002689 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002690 break;
2691 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002692 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002693 default:
2694 break;
2695 }
2696
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002697 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002698
2699 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2700 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002701 if (adapter->num_vfs)
2702 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002703
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002704 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2705 IXGBE_SRRCTL_BSIZEHDR_MASK;
2706
Alexander Duyckf8003262012-03-03 02:35:52 +00002707#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2708 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002709#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002710 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002711#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002712 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002713
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002714 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002715}
2716
Alexander Duyck05abb122010-08-19 13:35:41 +00002717static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002718{
Alexander Duyck05abb122010-08-19 13:35:41 +00002719 struct ixgbe_hw *hw = &adapter->hw;
2720 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002721 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2722 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002723 u32 mrqc = 0, reta = 0;
2724 u32 rxcsum;
2725 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002726 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002727 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2728
2729 if (tcs)
2730 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002731
Alexander Duyck05abb122010-08-19 13:35:41 +00002732 /* Fill out hash function seeds */
2733 for (i = 0; i < 10; i++)
2734 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002735
Alexander Duyck05abb122010-08-19 13:35:41 +00002736 /* Fill out redirection table */
2737 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002738 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002739 j = 0;
2740 /* reta = 4-byte sliding window of
2741 * 0x00..(indices-1)(indices-1)00..etc. */
2742 reta = (reta << 8) | (j * 0x11);
2743 if ((i & 3) == 3)
2744 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2745 }
2746
2747 /* Disable indicating checksum in descriptor, enables RSS hash */
2748 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2749 rxcsum |= IXGBE_RXCSUM_PCSD;
2750 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2751
John Fastabend8b1c0b22011-05-03 02:26:48 +00002752 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2753 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002754 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002755 } else {
2756 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2757 | IXGBE_FLAG_SRIOV_ENABLED);
2758
2759 switch (mask) {
2760 case (IXGBE_FLAG_RSS_ENABLED):
2761 if (!tcs)
2762 mrqc = IXGBE_MRQC_RSSEN;
2763 else if (tcs <= 4)
2764 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2765 else
2766 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2767 break;
2768 case (IXGBE_FLAG_SRIOV_ENABLED):
2769 mrqc = IXGBE_MRQC_VMDQEN;
2770 break;
2771 default:
2772 break;
2773 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002774 }
2775
Alexander Duyck05abb122010-08-19 13:35:41 +00002776 /* Perform hash on these packet types */
2777 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2778 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2779 | IXGBE_MRQC_RSS_FIELD_IPV6
2780 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2781
2782 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002783}
2784
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002785/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002786 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2787 * @adapter: address of board private structure
2788 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002789 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002790static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002791 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002792{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002793 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002794 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002795 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002796
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002797 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002798 return;
2799
Alexander Duyck73670962010-08-19 13:38:34 +00002800 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002801 rscctrl |= IXGBE_RSCCTL_RSCEN;
2802 /*
2803 * we must limit the number of descriptors so that the
2804 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002805 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002806 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002807#if (PAGE_SIZE <= 8192)
2808 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2809#elif (PAGE_SIZE <= 16384)
2810 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002811#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002812 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002813#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002814 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002815}
2816
Alexander Duyck9e10e042010-08-19 13:40:06 +00002817/**
2818 * ixgbe_set_uta - Set unicast filter table address
2819 * @adapter: board private structure
2820 *
2821 * The unicast table address is a register array of 32-bit registers.
2822 * The table is meant to be used in a way similar to how the MTA is used
2823 * however due to certain limitations in the hardware it is necessary to
2824 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2825 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2826 **/
2827static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2828{
2829 struct ixgbe_hw *hw = &adapter->hw;
2830 int i;
2831
2832 /* The UTA table only exists on 82599 hardware and newer */
2833 if (hw->mac.type < ixgbe_mac_82599EB)
2834 return;
2835
2836 /* we only need to do this if VMDq is enabled */
2837 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2838 return;
2839
2840 for (i = 0; i < 128; i++)
2841 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2842}
2843
2844#define IXGBE_MAX_RX_DESC_POLL 10
2845static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2846 struct ixgbe_ring *ring)
2847{
2848 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002849 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2850 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002851 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002852
2853 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2854 if (hw->mac.type == ixgbe_mac_82598EB &&
2855 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2856 return;
2857
2858 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002859 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002860 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2861 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2862
2863 if (!wait_loop) {
2864 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2865 "the polling period\n", reg_idx);
2866 }
2867}
2868
Yi Zou2d39d572011-01-06 14:29:56 +00002869void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2870 struct ixgbe_ring *ring)
2871{
2872 struct ixgbe_hw *hw = &adapter->hw;
2873 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2874 u32 rxdctl;
2875 u8 reg_idx = ring->reg_idx;
2876
2877 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2878 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2879
2880 /* write value back with RXDCTL.ENABLE bit cleared */
2881 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2882
2883 if (hw->mac.type == ixgbe_mac_82598EB &&
2884 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2885 return;
2886
2887 /* the hardware may take up to 100us to really disable the rx queue */
2888 do {
2889 udelay(10);
2890 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2891 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2892
2893 if (!wait_loop) {
2894 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2895 "the polling period\n", reg_idx);
2896 }
2897}
2898
Alexander Duyck84418e32010-08-19 13:40:54 +00002899void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2900 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002901{
2902 struct ixgbe_hw *hw = &adapter->hw;
2903 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002904 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002905 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002906
Alexander Duyck9e10e042010-08-19 13:40:06 +00002907 /* disable queue to avoid issues while updating state */
2908 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002909 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002910
Alexander Duyckacd37172010-08-19 13:36:05 +00002911 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2912 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2913 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2914 ring->count * sizeof(union ixgbe_adv_rx_desc));
2915 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2916 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002917 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002918
2919 ixgbe_configure_srrctl(adapter, ring);
2920 ixgbe_configure_rscctl(adapter, ring);
2921
Greg Rosee9f98072011-01-26 01:06:07 +00002922 /* If operating in IOV mode set RLPML for X540 */
2923 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2924 hw->mac.type == ixgbe_mac_X540) {
2925 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2926 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2927 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2928 }
2929
Alexander Duyck9e10e042010-08-19 13:40:06 +00002930 if (hw->mac.type == ixgbe_mac_82598EB) {
2931 /*
2932 * enable cache line friendly hardware writes:
2933 * PTHRESH=32 descriptors (half the internal cache),
2934 * this also removes ugly rx_no_buffer_count increment
2935 * HTHRESH=4 descriptors (to minimize latency on fetch)
2936 * WTHRESH=8 burst writeback up to two cache lines
2937 */
2938 rxdctl &= ~0x3FFFFF;
2939 rxdctl |= 0x080420;
2940 }
2941
2942 /* enable receive descriptor ring */
2943 rxdctl |= IXGBE_RXDCTL_ENABLE;
2944 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2945
2946 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002947 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002948}
2949
Alexander Duyck48654522010-08-19 13:36:27 +00002950static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2951{
2952 struct ixgbe_hw *hw = &adapter->hw;
2953 int p;
2954
2955 /* PSRTYPE must be initialized in non 82598 adapters */
2956 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002957 IXGBE_PSRTYPE_UDPHDR |
2958 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002959 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002960 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002961
2962 if (hw->mac.type == ixgbe_mac_82598EB)
2963 return;
2964
2965 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2966 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2967
2968 for (p = 0; p < adapter->num_rx_pools; p++)
2969 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2970 psrtype);
2971}
2972
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002973static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2974{
2975 struct ixgbe_hw *hw = &adapter->hw;
2976 u32 gcr_ext;
2977 u32 vt_reg_bits;
2978 u32 reg_offset, vf_shift;
2979 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00002980 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002981
2982 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2983 return;
2984
2985 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2986 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2987 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2988 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2989
2990 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00002991 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002992
2993 /* Enable only the PF's pool for Tx/Rx */
2994 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2995 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2996 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2997 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2998 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2999
3000 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3001 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3002
3003 /*
3004 * Set up VF register offsets for selected VT Mode,
3005 * i.e. 32 or 64 VFs for SR-IOV
3006 */
3007 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3008 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3009 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3010 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3011
3012 /* enable Tx loopback for VF/PF communication */
3013 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003014 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003015 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003016 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003017 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003018 /* For VFs that have spoof checking turned off */
3019 for (i = 0; i < adapter->num_vfs; i++) {
3020 if (!adapter->vfinfo[i].spoofchk_enabled)
3021 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3022 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003023}
3024
Alexander Duyck477de6e2010-08-19 13:38:11 +00003025static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003026{
Auke Kok9a799d72007-09-15 14:07:45 -07003027 struct ixgbe_hw *hw = &adapter->hw;
3028 struct net_device *netdev = adapter->netdev;
3029 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003030 struct ixgbe_ring *rx_ring;
3031 int i;
3032 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003033
Alexander Duyck477de6e2010-08-19 13:38:11 +00003034#ifdef IXGBE_FCOE
3035 /* adjust max frame to be able to do baby jumbo for FCoE */
3036 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3037 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3038 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3039
3040#endif /* IXGBE_FCOE */
3041 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3042 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3043 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3044 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3045
3046 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003047 }
3048
Alexander Duyck919e78a2011-08-26 09:52:38 +00003049 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3050 max_frame += VLAN_HLEN;
3051
Auke Kok9a799d72007-09-15 14:07:45 -07003052 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003053 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3054 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003055 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3056
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003057 /*
3058 * Setup the HW Rx Head and Tail Descriptor Pointers and
3059 * the Base and Length of the Rx Descriptor Ring
3060 */
Auke Kok9a799d72007-09-15 14:07:45 -07003061 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003062 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003063 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3064 set_ring_rsc_enabled(rx_ring);
3065 else
3066 clear_ring_rsc_enabled(rx_ring);
Yi Zou63f39bd2009-05-17 12:34:35 +00003067#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003068 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003069 struct ixgbe_ring_feature *f;
3070 f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckf8003262012-03-03 02:35:52 +00003071 if ((i >= f->mask) && (i < f->mask + f->indices))
3072 set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state);
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/**
Alexander Duyckf8003262012-03-03 02:35:52 +00003994 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
3995 * @rx_ring: ring to setup
3996 *
3997 * On many IA platforms the L1 cache has a critical stride of 4K, this
3998 * results in each receive buffer starting in the same cache set. To help
3999 * reduce the pressure on this cache set we can interleave the offsets so
4000 * that only every other buffer will be in the same cache set.
4001 **/
4002static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4003{
4004 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4005 u16 i;
4006
4007 for (i = 0; i < rx_ring->count; i += 2) {
4008 rx_buffer[0].page_offset = 0;
4009 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4010 rx_buffer = &rx_buffer[2];
4011 }
4012}
4013
4014/**
Auke Kok9a799d72007-09-15 14:07:45 -07004015 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004016 * @rx_ring: ring to free buffers from
4017 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004018static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004019{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004020 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004021 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004022 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004023
Alexander Duyck84418e32010-08-19 13:40:54 +00004024 /* ring already cleared, nothing to do */
4025 if (!rx_ring->rx_buffer_info)
4026 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004027
Alexander Duyck84418e32010-08-19 13:40:54 +00004028 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004029 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004030 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004031
Alexander Duyckf8003262012-03-03 02:35:52 +00004032 rx_buffer = &rx_ring->rx_buffer_info[i];
4033 if (rx_buffer->skb) {
4034 struct sk_buff *skb = rx_buffer->skb;
4035 if (IXGBE_CB(skb)->page_released) {
4036 dma_unmap_page(dev,
4037 IXGBE_CB(skb)->dma,
4038 ixgbe_rx_bufsz(rx_ring),
4039 DMA_FROM_DEVICE);
4040 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004041 }
4042 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004043 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004044 rx_buffer->skb = NULL;
4045 if (rx_buffer->dma)
4046 dma_unmap_page(dev, rx_buffer->dma,
4047 ixgbe_rx_pg_size(rx_ring),
4048 DMA_FROM_DEVICE);
4049 rx_buffer->dma = 0;
4050 if (rx_buffer->page)
4051 put_page(rx_buffer->page);
4052 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004053 }
4054
4055 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4056 memset(rx_ring->rx_buffer_info, 0, size);
4057
Alexander Duyckf8003262012-03-03 02:35:52 +00004058 ixgbe_init_rx_page_offset(rx_ring);
4059
Auke Kok9a799d72007-09-15 14:07:45 -07004060 /* Zero out the descriptor ring */
4061 memset(rx_ring->desc, 0, rx_ring->size);
4062
Alexander Duyckf8003262012-03-03 02:35:52 +00004063 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004064 rx_ring->next_to_clean = 0;
4065 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004066}
4067
4068/**
4069 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004070 * @tx_ring: ring to be cleaned
4071 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004072static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004073{
4074 struct ixgbe_tx_buffer *tx_buffer_info;
4075 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004076 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004077
Alexander Duyck84418e32010-08-19 13:40:54 +00004078 /* ring already cleared, nothing to do */
4079 if (!tx_ring->tx_buffer_info)
4080 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004081
Alexander Duyck84418e32010-08-19 13:40:54 +00004082 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004083 for (i = 0; i < tx_ring->count; i++) {
4084 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004085 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004086 }
4087
4088 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4089 memset(tx_ring->tx_buffer_info, 0, size);
4090
4091 /* Zero out the descriptor ring */
4092 memset(tx_ring->desc, 0, tx_ring->size);
4093
4094 tx_ring->next_to_use = 0;
4095 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004096}
4097
4098/**
Auke Kok9a799d72007-09-15 14:07:45 -07004099 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4100 * @adapter: board private structure
4101 **/
4102static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4103{
4104 int i;
4105
4106 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004107 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004108}
4109
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004110/**
4111 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4112 * @adapter: board private structure
4113 **/
4114static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4115{
4116 int i;
4117
4118 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004119 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004120}
4121
Alexander Duycke4911d52011-05-11 07:18:52 +00004122static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4123{
4124 struct hlist_node *node, *node2;
4125 struct ixgbe_fdir_filter *filter;
4126
4127 spin_lock(&adapter->fdir_perfect_lock);
4128
4129 hlist_for_each_entry_safe(filter, node, node2,
4130 &adapter->fdir_filter_list, fdir_node) {
4131 hlist_del(&filter->fdir_node);
4132 kfree(filter);
4133 }
4134 adapter->fdir_filter_count = 0;
4135
4136 spin_unlock(&adapter->fdir_perfect_lock);
4137}
4138
Auke Kok9a799d72007-09-15 14:07:45 -07004139void ixgbe_down(struct ixgbe_adapter *adapter)
4140{
4141 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004142 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004143 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004144 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004145
4146 /* signal that we are down to the interrupt handler */
4147 set_bit(__IXGBE_DOWN, &adapter->state);
4148
4149 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004150 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4151 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004152
Yi Zou2d39d572011-01-06 14:29:56 +00004153 /* disable all enabled rx queues */
4154 for (i = 0; i < adapter->num_rx_queues; i++)
4155 /* this call also flushes the previous write */
4156 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4157
Don Skidmore032b4322011-03-18 09:32:53 +00004158 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004159
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004160 netif_tx_stop_all_queues(netdev);
4161
Alexander Duyck70864002011-04-27 09:13:56 +00004162 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004163 netif_carrier_off(netdev);
4164 netif_tx_disable(netdev);
4165
4166 ixgbe_irq_disable(adapter);
4167
4168 ixgbe_napi_disable_all(adapter);
4169
Alexander Duyckd034acf2011-04-27 09:25:34 +00004170 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4171 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004172 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4173
4174 del_timer_sync(&adapter->service_timer);
4175
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004176 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004177 /* Clear EITR Select mapping */
4178 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4179
4180 /* Mark all the VFs as inactive */
4181 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004182 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004183
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004184 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004185 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004186
Auke Kok9a799d72007-09-15 14:07:45 -07004187 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004188 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004189 }
4190
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004191 /* disable transmits in the hardware now that interrupts are off */
4192 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004193 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004194 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004195 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004196
4197 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004198 switch (hw->mac.type) {
4199 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004200 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004201 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004202 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4203 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004204 break;
4205 default:
4206 break;
4207 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004208
Paul Larson6f4a0e42008-06-24 17:00:56 -07004209 if (!pci_channel_offline(adapter->pdev))
4210 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004211
4212 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4213 if (hw->mac.ops.disable_tx_laser &&
4214 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004215 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004216 (hw->mac.type == ixgbe_mac_82599EB))))
4217 hw->mac.ops.disable_tx_laser(hw);
4218
Auke Kok9a799d72007-09-15 14:07:45 -07004219 ixgbe_clean_all_tx_rings(adapter);
4220 ixgbe_clean_all_rx_rings(adapter);
4221
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004222#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004223 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004224 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004225#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004226}
4227
Auke Kok9a799d72007-09-15 14:07:45 -07004228/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004229 * ixgbe_poll - NAPI Rx polling callback
4230 * @napi: structure for representing this polling device
4231 * @budget: how many packets driver is allowed to clean
4232 *
4233 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004234 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004235static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004236{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004237 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004238 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004239 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004240 struct ixgbe_ring *ring;
4241 int per_ring_budget;
4242 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004243
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004244#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004245 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4246 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004247#endif
4248
Alexander Duycka5579282012-02-08 07:50:04 +00004249 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004250 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004251
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004252 /* attempt to distribute budget to each queue fairly, but don't allow
4253 * the budget to go below 1 because we'll exit polling */
4254 if (q_vector->rx.count > 1)
4255 per_ring_budget = max(budget/q_vector->rx.count, 1);
4256 else
4257 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004258
Alexander Duycka5579282012-02-08 07:50:04 +00004259 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004260 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4261 per_ring_budget);
4262
4263 /* If all work not completed, return budget and keep polling */
4264 if (!clean_complete)
4265 return budget;
4266
4267 /* all work done, exit the polling mode */
4268 napi_complete(napi);
4269 if (adapter->rx_itr_setting & 1)
4270 ixgbe_set_itr(q_vector);
4271 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4272 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4273
4274 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004275}
4276
4277/**
4278 * ixgbe_tx_timeout - Respond to a Tx Hang
4279 * @netdev: network interface device structure
4280 **/
4281static void ixgbe_tx_timeout(struct net_device *netdev)
4282{
4283 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4284
4285 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004286 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004287}
4288
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004289/**
4290 * ixgbe_set_rss_queues: Allocate queues for RSS
4291 * @adapter: board private structure to initialize
4292 *
4293 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4294 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4295 *
4296 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004297static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4298{
4299 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004300 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004301
4302 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004303 f->mask = 0xF;
4304 adapter->num_rx_queues = f->indices;
4305 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004306 ret = true;
4307 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004308 ret = false;
4309 }
4310
4311 return ret;
4312}
4313
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004314/**
4315 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4316 * @adapter: board private structure to initialize
4317 *
4318 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4319 * to the original CPU that initiated the Tx session. This runs in addition
4320 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4321 * Rx load across CPUs using RSS.
4322 *
4323 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004324static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004325{
4326 bool ret = false;
4327 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4328
4329 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4330 f_fdir->mask = 0;
4331
Alexander Duyck24ddd962012-02-10 02:08:32 +00004332 /*
4333 * Use RSS in addition to Flow Director to ensure the best
4334 * distribution of flows across cores, even when an FDIR flow
4335 * isn't matched.
4336 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004337 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4338 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004339 adapter->num_tx_queues = f_fdir->indices;
4340 adapter->num_rx_queues = f_fdir->indices;
4341 ret = true;
4342 } else {
4343 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004344 }
4345 return ret;
4346}
4347
Yi Zou0331a832009-05-17 12:33:52 +00004348#ifdef IXGBE_FCOE
4349/**
4350 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4351 * @adapter: board private structure to initialize
4352 *
4353 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4354 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4355 * rx queues out of the max number of rx queues, instead, it is used as the
4356 * index of the first rx queue used by FCoE.
4357 *
4358 **/
4359static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4360{
Yi Zou0331a832009-05-17 12:33:52 +00004361 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4362
John Fastabende5b64632011-03-08 03:44:52 +00004363 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4364 return false;
4365
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004366 f->indices = min_t(int, num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004367
John Fastabende901acd2011-04-26 07:26:08 +00004368 adapter->num_rx_queues = 1;
4369 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004370
John Fastabende901acd2011-04-26 07:26:08 +00004371 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4372 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004373 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004374 ixgbe_set_fdir_queues(adapter);
4375 else
4376 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004377 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004378
John Fastabende901acd2011-04-26 07:26:08 +00004379 /* adding FCoE rx rings to the end */
4380 f->mask = adapter->num_rx_queues;
4381 adapter->num_rx_queues += f->indices;
4382 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004383
John Fastabende5b64632011-03-08 03:44:52 +00004384 return true;
4385}
4386#endif /* IXGBE_FCOE */
4387
John Fastabende901acd2011-04-26 07:26:08 +00004388/* Artificial max queue cap per traffic class in DCB mode */
4389#define DCB_QUEUE_CAP 8
4390
John Fastabende5b64632011-03-08 03:44:52 +00004391#ifdef CONFIG_IXGBE_DCB
4392static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4393{
John Fastabende901acd2011-04-26 07:26:08 +00004394 int per_tc_q, q, i, offset = 0;
4395 struct net_device *dev = adapter->netdev;
4396 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004397
John Fastabende901acd2011-04-26 07:26:08 +00004398 if (!tcs)
4399 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004400
John Fastabende901acd2011-04-26 07:26:08 +00004401 /* Map queue offset and counts onto allocated tx queues */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004402 per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP);
4403 q = min_t(int, num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004404
John Fastabend8b1c0b22011-05-03 02:26:48 +00004405 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004406 netdev_set_tc_queue(dev, i, q, offset);
4407 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004408 }
4409
John Fastabende901acd2011-04-26 07:26:08 +00004410 adapter->num_tx_queues = q * tcs;
4411 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004412
4413#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004414 /* FCoE enabled queues require special configuration indexed
4415 * by feature specific indices and mask. Here we map FCoE
4416 * indices onto the DCB queue pairs allowing FCoE to own
4417 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004418 */
John Fastabende901acd2011-04-26 07:26:08 +00004419 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
John Fastabendcdf485b2012-02-11 06:26:00 +00004420 u8 prio_tc[MAX_USER_PRIORITY] = {0};
John Fastabende901acd2011-04-26 07:26:08 +00004421 int tc;
4422 struct ixgbe_ring_feature *f =
4423 &adapter->ring_feature[RING_F_FCOE];
4424
John Fastabendcdf485b2012-02-11 06:26:00 +00004425 ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc);
4426 tc = prio_tc[adapter->fcoe.up];
John Fastabende901acd2011-04-26 07:26:08 +00004427 f->indices = dev->tc_to_txq[tc].count;
4428 f->mask = dev->tc_to_txq[tc].offset;
4429 }
John Fastabende5b64632011-03-08 03:44:52 +00004430#endif
4431
John Fastabende901acd2011-04-26 07:26:08 +00004432 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004433}
John Fastabende5b64632011-03-08 03:44:52 +00004434#endif
Yi Zou0331a832009-05-17 12:33:52 +00004435
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004436/**
4437 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4438 * @adapter: board private structure to initialize
4439 *
4440 * IOV doesn't actually use anything, so just NAK the
4441 * request for now and let the other queue routines
4442 * figure out what to do.
4443 */
4444static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4445{
4446 return false;
4447}
4448
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004449/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004450 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004451 * @adapter: board private structure to initialize
4452 *
4453 * This is the top level queue allocation routine. The order here is very
4454 * important, starting with the "most" number of features turned on at once,
4455 * and ending with the smallest set of features. This way large combinations
4456 * can be allocated if they're turned on, and smaller combinations are the
4457 * fallthrough conditions.
4458 *
4459 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004460static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004461{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004462 /* Start with base case */
4463 adapter->num_rx_queues = 1;
4464 adapter->num_tx_queues = 1;
4465 adapter->num_rx_pools = adapter->num_rx_queues;
4466 adapter->num_rx_queues_per_pool = 1;
4467
4468 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004469 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004470
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004471#ifdef CONFIG_IXGBE_DCB
4472 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004473 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004474
4475#endif
John Fastabende5b64632011-03-08 03:44:52 +00004476#ifdef IXGBE_FCOE
4477 if (ixgbe_set_fcoe_queues(adapter))
4478 goto done;
4479
4480#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004481 if (ixgbe_set_fdir_queues(adapter))
4482 goto done;
4483
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004484 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004485 goto done;
4486
4487 /* fallback to base case */
4488 adapter->num_rx_queues = 1;
4489 adapter->num_tx_queues = 1;
4490
4491done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004492 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4493 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4494 return 0;
4495
Ben Hutchings847f53f2010-09-27 08:28:56 +00004496 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004497 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004498 return netif_set_real_num_rx_queues(adapter->netdev,
4499 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004500}
4501
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004502static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004503 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004504{
4505 int err, vector_threshold;
4506
Alexander Duyck8f154862012-02-10 02:08:37 +00004507 /* We'll want at least 2 (vector_threshold):
4508 * 1) TxQ[0] + RxQ[0] handler
4509 * 2) Other (Link Status Change, etc.)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004510 */
4511 vector_threshold = MIN_MSIX_COUNT;
4512
Alexander Duyck24ddd962012-02-10 02:08:32 +00004513 /*
4514 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004515 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4516 * Right now, we simply care about how many we'll get; we'll
4517 * set them up later while requesting irq's.
4518 */
4519 while (vectors >= vector_threshold) {
4520 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004521 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004522 if (!err) /* Success in acquiring all requested vectors. */
4523 break;
4524 else if (err < 0)
4525 vectors = 0; /* Nasty failure, quit now */
4526 else /* err == number of vectors we should try again with */
4527 vectors = err;
4528 }
4529
4530 if (vectors < vector_threshold) {
4531 /* Can't allocate enough MSI-X interrupts? Oh well.
4532 * This just means we'll go with either a single MSI
4533 * vector or fall back to legacy interrupts.
4534 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004535 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4536 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004537 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4538 kfree(adapter->msix_entries);
4539 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004540 } else {
4541 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004542 /*
4543 * Adjust for only the vectors we'll use, which is minimum
4544 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4545 * vectors we were allocated.
4546 */
4547 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004548 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004549 }
4550}
4551
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004552/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004553 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004554 * @adapter: board private structure to initialize
4555 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004556 * Cache the descriptor ring offsets for RSS to the assigned rings.
4557 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004558 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004559static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004560{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004561 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004562
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004563 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4564 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004565
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004566 for (i = 0; i < adapter->num_rx_queues; i++)
4567 adapter->rx_ring[i]->reg_idx = i;
4568 for (i = 0; i < adapter->num_tx_queues; i++)
4569 adapter->tx_ring[i]->reg_idx = i;
4570
4571 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004572}
4573
4574#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004575
4576/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004577static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4578 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004579{
4580 struct net_device *dev = adapter->netdev;
4581 struct ixgbe_hw *hw = &adapter->hw;
4582 u8 num_tcs = netdev_get_num_tc(dev);
4583
4584 *tx = 0;
4585 *rx = 0;
4586
4587 switch (hw->mac.type) {
4588 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004589 *tx = tc << 2;
4590 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004591 break;
4592 case ixgbe_mac_82599EB:
4593 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004594 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004595 if (tc < 3) {
4596 *tx = tc << 5;
4597 *rx = tc << 4;
4598 } else if (tc < 5) {
4599 *tx = ((tc + 2) << 4);
4600 *rx = tc << 4;
4601 } else if (tc < num_tcs) {
4602 *tx = ((tc + 8) << 3);
4603 *rx = tc << 4;
4604 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004605 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004606 *rx = tc << 5;
4607 switch (tc) {
4608 case 0:
4609 *tx = 0;
4610 break;
4611 case 1:
4612 *tx = 64;
4613 break;
4614 case 2:
4615 *tx = 96;
4616 break;
4617 case 3:
4618 *tx = 112;
4619 break;
4620 default:
4621 break;
4622 }
4623 }
4624 break;
4625 default:
4626 break;
4627 }
4628}
4629
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004630/**
4631 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4632 * @adapter: board private structure to initialize
4633 *
4634 * Cache the descriptor ring offsets for DCB to the assigned rings.
4635 *
4636 **/
4637static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4638{
John Fastabende5b64632011-03-08 03:44:52 +00004639 struct net_device *dev = adapter->netdev;
4640 int i, j, k;
4641 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004642
John Fastabend8b1c0b22011-05-03 02:26:48 +00004643 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004644 return false;
4645
John Fastabende5b64632011-03-08 03:44:52 +00004646 for (i = 0, k = 0; i < num_tcs; i++) {
4647 unsigned int tx_s, rx_s;
4648 u16 count = dev->tc_to_txq[i].count;
4649
4650 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4651 for (j = 0; j < count; j++, k++) {
4652 adapter->tx_ring[k]->reg_idx = tx_s + j;
4653 adapter->rx_ring[k]->reg_idx = rx_s + j;
4654 adapter->tx_ring[k]->dcb_tc = i;
4655 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004656 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004657 }
John Fastabende5b64632011-03-08 03:44:52 +00004658
4659 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004660}
4661#endif
4662
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004663/**
4664 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4665 * @adapter: board private structure to initialize
4666 *
4667 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4668 *
4669 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004670static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004671{
4672 int i;
4673 bool ret = false;
4674
Alexander Duyck03ecf912011-05-20 07:36:17 +00004675 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4676 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004677 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004678 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004679 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004680 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004681 ret = true;
4682 }
4683
4684 return ret;
4685}
4686
Yi Zou0331a832009-05-17 12:33:52 +00004687#ifdef IXGBE_FCOE
4688/**
4689 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4690 * @adapter: board private structure to initialize
4691 *
4692 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4693 *
4694 */
4695static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4696{
Yi Zou0331a832009-05-17 12:33:52 +00004697 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004698 int i;
4699 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004700
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004701 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4702 return false;
4703
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004704 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004705 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004706 ixgbe_cache_ring_fdir(adapter);
4707 else
4708 ixgbe_cache_ring_rss(adapter);
4709
4710 fcoe_rx_i = f->mask;
4711 fcoe_tx_i = f->mask;
4712 }
4713 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4714 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4715 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4716 }
4717 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004718}
4719
4720#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004721/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004722 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4723 * @adapter: board private structure to initialize
4724 *
4725 * SR-IOV doesn't use any descriptor rings but changes the default if
4726 * no other mapping is used.
4727 *
4728 */
4729static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4730{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004731 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4732 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004733 if (adapter->num_vfs)
4734 return true;
4735 else
4736 return false;
4737}
4738
4739/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004740 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4741 * @adapter: board private structure to initialize
4742 *
4743 * Once we know the feature-set enabled for the device, we'll cache
4744 * the register offset the descriptor ring is assigned to.
4745 *
4746 * Note, the order the various feature calls is important. It must start with
4747 * the "most" features enabled at the same time, then trickle down to the
4748 * least amount of features turned on at once.
4749 **/
4750static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4751{
4752 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004753 adapter->rx_ring[0]->reg_idx = 0;
4754 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004755
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004756 if (ixgbe_cache_ring_sriov(adapter))
4757 return;
4758
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004759#ifdef CONFIG_IXGBE_DCB
4760 if (ixgbe_cache_ring_dcb(adapter))
4761 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004762#endif
John Fastabende5b64632011-03-08 03:44:52 +00004763
4764#ifdef IXGBE_FCOE
4765 if (ixgbe_cache_ring_fcoe(adapter))
4766 return;
4767#endif /* IXGBE_FCOE */
4768
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004769 if (ixgbe_cache_ring_fdir(adapter))
4770 return;
4771
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004772 if (ixgbe_cache_ring_rss(adapter))
4773 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004774}
4775
Auke Kok9a799d72007-09-15 14:07:45 -07004776/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004777 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4778 * @adapter: board private structure to initialize
4779 *
4780 * Attempt to configure the interrupts using the best available
4781 * capabilities of the hardware and the kernel.
4782 **/
Al Virofeea6a52008-11-27 15:34:07 -08004783static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004784{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004785 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004786 int err = 0;
4787 int vector, v_budget;
4788
4789 /*
4790 * It's easy to be greedy for MSI-X vectors, but it really
4791 * doesn't do us much good if we have a lot more vectors
4792 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004793 * (roughly) the same number of vectors as there are CPU's.
Alexander Duyck8f154862012-02-10 02:08:37 +00004794 * The default is to use pairs of vectors.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004795 */
Alexander Duyck8f154862012-02-10 02:08:37 +00004796 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
4797 v_budget = min_t(int, v_budget, num_online_cpus());
4798 v_budget += NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004799
4800 /*
4801 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004802 * hw.mac->max_msix_vectors vectors. With features
4803 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4804 * descriptor queues supported by our device. Thus, we cap it off in
4805 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004806 */
Alexander Duyckde88eee2012-02-08 07:49:59 +00004807 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004808
4809 /* A failure in MSI-X entry allocation isn't fatal, but it does
4810 * mean we disable MSI-X capabilities of the adapter. */
4811 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004812 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004813 if (adapter->msix_entries) {
4814 for (vector = 0; vector < v_budget; vector++)
4815 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004816
Alexander Duyck7a921c92009-05-06 10:43:28 +00004817 ixgbe_acquire_msix_vectors(adapter, v_budget);
4818
4819 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4820 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004821 }
David S. Miller26d27842010-05-03 15:18:22 -07004822
Alexander Duyck7a921c92009-05-06 10:43:28 +00004823 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4824 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004825 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004826 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004827 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004828 "queues are disabled. Disabling Flow Director\n");
4829 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004830 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004831 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004832 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4833 ixgbe_disable_sriov(adapter);
4834
Ben Hutchings847f53f2010-09-27 08:28:56 +00004835 err = ixgbe_set_num_queues(adapter);
4836 if (err)
4837 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004838
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839 err = pci_enable_msi(adapter->pdev);
4840 if (!err) {
4841 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4842 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004843 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4844 "Unable to allocate MSI interrupt, "
4845 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004846 /* reset err */
4847 err = 0;
4848 }
4849
4850out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004851 return err;
4852}
4853
Alexander Duyckde88eee2012-02-08 07:49:59 +00004854static void ixgbe_add_ring(struct ixgbe_ring *ring,
4855 struct ixgbe_ring_container *head)
4856{
4857 ring->next = head->ring;
4858 head->ring = ring;
4859 head->count++;
4860}
4861
4862/**
4863 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
4864 * @adapter: board private structure to initialize
4865 * @v_idx: index of vector in adapter struct
4866 *
4867 * We allocate one q_vector. If allocation fails we return -ENOMEM.
4868 **/
4869static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
4870 int txr_count, int txr_idx,
4871 int rxr_count, int rxr_idx)
4872{
4873 struct ixgbe_q_vector *q_vector;
4874 struct ixgbe_ring *ring;
4875 int node = -1;
4876 int cpu = -1;
4877 int ring_count, size;
4878
4879 ring_count = txr_count + rxr_count;
4880 size = sizeof(struct ixgbe_q_vector) +
4881 (sizeof(struct ixgbe_ring) * ring_count);
4882
4883 /* customize cpu for Flow Director mapping */
4884 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4885 if (cpu_online(v_idx)) {
4886 cpu = v_idx;
4887 node = cpu_to_node(cpu);
4888 }
4889 }
4890
4891 /* allocate q_vector and rings */
4892 q_vector = kzalloc_node(size, GFP_KERNEL, node);
4893 if (!q_vector)
4894 q_vector = kzalloc(size, GFP_KERNEL);
4895 if (!q_vector)
4896 return -ENOMEM;
4897
4898 /* setup affinity mask and node */
4899 if (cpu != -1)
4900 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
4901 else
4902 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
4903 q_vector->numa_node = node;
4904
4905 /* initialize NAPI */
4906 netif_napi_add(adapter->netdev, &q_vector->napi,
4907 ixgbe_poll, 64);
4908
4909 /* tie q_vector and adapter together */
4910 adapter->q_vector[v_idx] = q_vector;
4911 q_vector->adapter = adapter;
4912 q_vector->v_idx = v_idx;
4913
4914 /* initialize work limits */
4915 q_vector->tx.work_limit = adapter->tx_work_limit;
4916
4917 /* initialize pointer to rings */
4918 ring = q_vector->ring;
4919
4920 while (txr_count) {
4921 /* assign generic ring traits */
4922 ring->dev = &adapter->pdev->dev;
4923 ring->netdev = adapter->netdev;
4924
4925 /* configure backlink on ring */
4926 ring->q_vector = q_vector;
4927
4928 /* update q_vector Tx values */
4929 ixgbe_add_ring(ring, &q_vector->tx);
4930
4931 /* apply Tx specific ring traits */
4932 ring->count = adapter->tx_ring_count;
4933 ring->queue_index = txr_idx;
4934
4935 /* assign ring to adapter */
4936 adapter->tx_ring[txr_idx] = ring;
4937
4938 /* update count and index */
4939 txr_count--;
4940 txr_idx++;
4941
4942 /* push pointer to next ring */
4943 ring++;
4944 }
4945
4946 while (rxr_count) {
4947 /* assign generic ring traits */
4948 ring->dev = &adapter->pdev->dev;
4949 ring->netdev = adapter->netdev;
4950
4951 /* configure backlink on ring */
4952 ring->q_vector = q_vector;
4953
4954 /* update q_vector Rx values */
4955 ixgbe_add_ring(ring, &q_vector->rx);
4956
4957 /*
4958 * 82599 errata, UDP frames with a 0 checksum
4959 * can be marked as checksum errors.
4960 */
4961 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4962 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4963
4964 /* apply Rx specific ring traits */
4965 ring->count = adapter->rx_ring_count;
4966 ring->queue_index = rxr_idx;
4967
4968 /* assign ring to adapter */
4969 adapter->rx_ring[rxr_idx] = ring;
4970
4971 /* update count and index */
4972 rxr_count--;
4973 rxr_idx++;
4974
4975 /* push pointer to next ring */
4976 ring++;
4977 }
4978
4979 return 0;
4980}
4981
4982/**
4983 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
4984 * @adapter: board private structure to initialize
4985 * @v_idx: Index of vector to be freed
4986 *
4987 * This function frees the memory allocated to the q_vector. In addition if
4988 * NAPI is enabled it will delete any references to the NAPI struct prior
4989 * to freeing the q_vector.
4990 **/
4991static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
4992{
4993 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4994 struct ixgbe_ring *ring;
4995
Alexander Duycka5579282012-02-08 07:50:04 +00004996 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004997 adapter->tx_ring[ring->queue_index] = NULL;
4998
Alexander Duycka5579282012-02-08 07:50:04 +00004999 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005000 adapter->rx_ring[ring->queue_index] = NULL;
5001
5002 adapter->q_vector[v_idx] = NULL;
5003 netif_napi_del(&q_vector->napi);
5004
5005 /*
5006 * ixgbe_get_stats64() might access the rings on this vector,
5007 * we must wait a grace period before freeing it.
5008 */
5009 kfree_rcu(q_vector, rcu);
5010}
5011
Alexander Duyck7a921c92009-05-06 10:43:28 +00005012/**
5013 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
5014 * @adapter: board private structure to initialize
5015 *
5016 * We allocate one q_vector per queue interrupt. If allocation fails we
5017 * return -ENOMEM.
5018 **/
5019static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5020{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005021 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5022 int rxr_remaining = adapter->num_rx_queues;
5023 int txr_remaining = adapter->num_tx_queues;
5024 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
5025 int err;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005026
Alexander Duyckde88eee2012-02-08 07:49:59 +00005027 /* only one q_vector if MSI-X is disabled. */
5028 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
5029 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005030
Alexander Duyckde88eee2012-02-08 07:49:59 +00005031 if (q_vectors >= (rxr_remaining + txr_remaining)) {
5032 for (; rxr_remaining; v_idx++, q_vectors--) {
5033 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5034 err = ixgbe_alloc_q_vector(adapter, v_idx,
5035 0, 0, rqpv, rxr_idx);
5036
5037 if (err)
5038 goto err_out;
5039
5040 /* update counts and index */
5041 rxr_remaining -= rqpv;
5042 rxr_idx += rqpv;
5043 }
5044 }
5045
5046 for (; q_vectors; v_idx++, q_vectors--) {
5047 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5048 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors);
5049 err = ixgbe_alloc_q_vector(adapter, v_idx,
5050 tqpv, txr_idx,
5051 rqpv, rxr_idx);
5052
5053 if (err)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005054 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005055
Alexander Duyckde88eee2012-02-08 07:49:59 +00005056 /* update counts and index */
5057 rxr_remaining -= rqpv;
5058 rxr_idx += rqpv;
5059 txr_remaining -= tqpv;
5060 txr_idx += tqpv;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005061 }
5062
5063 return 0;
5064
5065err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005066 while (v_idx) {
5067 v_idx--;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005068 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005069 }
Alexander Duyckde88eee2012-02-08 07:49:59 +00005070
Alexander Duyck7a921c92009-05-06 10:43:28 +00005071 return -ENOMEM;
5072}
5073
5074/**
5075 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5076 * @adapter: board private structure to initialize
5077 *
5078 * This function frees the memory allocated to the q_vectors. In addition if
5079 * NAPI is enabled it will delete any references to the NAPI struct prior
5080 * to freeing the q_vector.
5081 **/
5082static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5083{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005084 int v_idx, q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005085
Alexander Duyck91281fd2009-06-04 16:00:27 +00005086 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005087 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005088 else
Alexander Duyckde88eee2012-02-08 07:49:59 +00005089 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005090
Alexander Duyckde88eee2012-02-08 07:49:59 +00005091 for (v_idx = 0; v_idx < q_vectors; v_idx++)
5092 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005093}
5094
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005095static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005096{
5097 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5098 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5099 pci_disable_msix(adapter->pdev);
5100 kfree(adapter->msix_entries);
5101 adapter->msix_entries = NULL;
5102 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5103 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5104 pci_disable_msi(adapter->pdev);
5105 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005106}
5107
5108/**
5109 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5110 * @adapter: board private structure to initialize
5111 *
5112 * We determine which interrupt scheme to use based on...
5113 * - Kernel support (MSI, MSI-X)
5114 * - which can be user-defined (via MODULE_PARAM)
5115 * - Hardware queue count (num_*_queues)
5116 * - defined by miscellaneous hardware support/features (RSS, etc.)
5117 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005118int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005119{
5120 int err;
5121
5122 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005123 err = ixgbe_set_num_queues(adapter);
5124 if (err)
5125 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005126
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005127 err = ixgbe_set_interrupt_capability(adapter);
5128 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005129 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005130 goto err_set_interrupt;
5131 }
5132
Alexander Duyck7a921c92009-05-06 10:43:28 +00005133 err = ixgbe_alloc_q_vectors(adapter);
5134 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005135 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005136 goto err_alloc_q_vectors;
5137 }
5138
Alexander Duyckde88eee2012-02-08 07:49:59 +00005139 ixgbe_cache_ring_register(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005140
Emil Tantilov849c4542010-06-03 16:53:41 +00005141 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005142 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5143 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005144
5145 set_bit(__IXGBE_DOWN, &adapter->state);
5146
5147 return 0;
5148
Alexander Duyck7a921c92009-05-06 10:43:28 +00005149err_alloc_q_vectors:
5150 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005151err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005152 return err;
5153}
5154
5155/**
5156 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5157 * @adapter: board private structure to clear interrupt scheme on
5158 *
5159 * We go through and clear interrupt specific resources and reset the structure
5160 * to pre-load conditions
5161 **/
5162void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5163{
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005164 adapter->num_tx_queues = 0;
5165 adapter->num_rx_queues = 0;
5166
Alexander Duyck7a921c92009-05-06 10:43:28 +00005167 ixgbe_free_q_vectors(adapter);
5168 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005169}
5170
5171/**
5172 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5173 * @adapter: board private structure to initialize
5174 *
5175 * ixgbe_sw_init initializes the Adapter private data structure.
5176 * Fields are initialized based on PCI device information and
5177 * OS network device settings (MTU size).
5178 **/
5179static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5180{
5181 struct ixgbe_hw *hw = &adapter->hw;
5182 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005183 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005184#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005185 int j;
5186 struct tc_configuration *tc;
5187#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005188
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005189 /* PCI config space info */
5190
5191 hw->vendor_id = pdev->vendor;
5192 hw->device_id = pdev->device;
5193 hw->revision_id = pdev->revision;
5194 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5195 hw->subsystem_device_id = pdev->subsystem_device;
5196
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005197 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005198 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005199 adapter->ring_feature[RING_F_RSS].indices = rss;
5200 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005201 switch (hw->mac.type) {
5202 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005203 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5204 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005205 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005206 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005207 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005208 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5209 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005210 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005211 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5212 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005213 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5214 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005215 /* Flow Director hash filters enabled */
5216 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5217 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005218 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005219 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005220 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005221#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005222 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5223 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5224 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005225#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005226 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005227 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005228#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005229#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005230 break;
5231 default:
5232 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005233 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005234
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005235 /* n-tuple support exists, always init our spinlock */
5236 spin_lock_init(&adapter->fdir_perfect_lock);
5237
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005238#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005239 switch (hw->mac.type) {
5240 case ixgbe_mac_X540:
5241 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5242 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5243 break;
5244 default:
5245 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5246 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5247 break;
5248 }
5249
Alexander Duyck2f90b862008-11-20 20:52:10 -08005250 /* Configure DCB traffic classes */
5251 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5252 tc = &adapter->dcb_cfg.tc_config[j];
5253 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5254 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5255 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5256 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5257 tc->dcb_pfc = pfc_disabled;
5258 }
John Fastabend4de2a022011-09-27 03:52:01 +00005259
5260 /* Initialize default user to priority mapping, UPx->TC0 */
5261 tc = &adapter->dcb_cfg.tc_config[0];
5262 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5263 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5264
Alexander Duyck2f90b862008-11-20 20:52:10 -08005265 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5266 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005267 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005268 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005269 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005270 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005271 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005272
5273#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005274
5275 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005276 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005277 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005278#ifdef CONFIG_DCB
5279 adapter->last_lfc_mode = hw->fc.current_mode;
5280#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005281 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005282 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5283 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005284 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005285
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005286 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005287 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005288 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005289
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005290 /* set default ring sizes */
5291 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5292 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5293
Alexander Duyckbd198052011-06-11 01:45:08 +00005294 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005295 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005296
Auke Kok9a799d72007-09-15 14:07:45 -07005297 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005298 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005299 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005300 return -EIO;
5301 }
5302
Auke Kok9a799d72007-09-15 14:07:45 -07005303 set_bit(__IXGBE_DOWN, &adapter->state);
5304
5305 return 0;
5306}
5307
5308/**
5309 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005310 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005311 *
5312 * Return 0 on success, negative on failure
5313 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005314int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005315{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005316 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005317 int orig_node = dev_to_node(dev);
5318 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005319 int size;
5320
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005321 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005322
5323 if (tx_ring->q_vector)
5324 numa_node = tx_ring->q_vector->numa_node;
5325
5326 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005327 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005328 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005329 if (!tx_ring->tx_buffer_info)
5330 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005331
5332 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005333 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005334 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005335
Alexander Duyckde88eee2012-02-08 07:49:59 +00005336 set_dev_node(dev, numa_node);
5337 tx_ring->desc = dma_alloc_coherent(dev,
5338 tx_ring->size,
5339 &tx_ring->dma,
5340 GFP_KERNEL);
5341 set_dev_node(dev, orig_node);
5342 if (!tx_ring->desc)
5343 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5344 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005345 if (!tx_ring->desc)
5346 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005347
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005348 tx_ring->next_to_use = 0;
5349 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005350 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005351
5352err:
5353 vfree(tx_ring->tx_buffer_info);
5354 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005355 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005356 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005357}
5358
5359/**
Alexander Duyck69888672008-09-11 20:05:39 -07005360 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5361 * @adapter: board private structure
5362 *
5363 * If this function returns with an error, then it's possible one or
5364 * more of the rings is populated (while the rest are not). It is the
5365 * callers duty to clean those orphaned rings.
5366 *
5367 * Return 0 on success, negative on failure
5368 **/
5369static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5370{
5371 int i, err = 0;
5372
5373 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005374 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005375 if (!err)
5376 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005377 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005378 break;
5379 }
5380
5381 return err;
5382}
5383
5384/**
Auke Kok9a799d72007-09-15 14:07:45 -07005385 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005386 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005387 *
5388 * Returns 0 on success, negative on failure
5389 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005390int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005391{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005392 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005393 int orig_node = dev_to_node(dev);
5394 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005395 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005396
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005397 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005398
5399 if (rx_ring->q_vector)
5400 numa_node = rx_ring->q_vector->numa_node;
5401
5402 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005403 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005404 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005405 if (!rx_ring->rx_buffer_info)
5406 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005407
Auke Kok9a799d72007-09-15 14:07:45 -07005408 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005409 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5410 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005411
Alexander Duyckde88eee2012-02-08 07:49:59 +00005412 set_dev_node(dev, numa_node);
5413 rx_ring->desc = dma_alloc_coherent(dev,
5414 rx_ring->size,
5415 &rx_ring->dma,
5416 GFP_KERNEL);
5417 set_dev_node(dev, orig_node);
5418 if (!rx_ring->desc)
5419 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5420 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005421 if (!rx_ring->desc)
5422 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005423
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005424 rx_ring->next_to_clean = 0;
5425 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005426
Alexander Duyckf8003262012-03-03 02:35:52 +00005427 ixgbe_init_rx_page_offset(rx_ring);
5428
Auke Kok9a799d72007-09-15 14:07:45 -07005429 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005430err:
5431 vfree(rx_ring->rx_buffer_info);
5432 rx_ring->rx_buffer_info = NULL;
5433 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005434 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005435}
5436
5437/**
Alexander Duyck69888672008-09-11 20:05:39 -07005438 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5439 * @adapter: board private structure
5440 *
5441 * If this function returns with an error, then it's possible one or
5442 * more of the rings is populated (while the rest are not). It is the
5443 * callers duty to clean those orphaned rings.
5444 *
5445 * Return 0 on success, negative on failure
5446 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005447static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5448{
5449 int i, err = 0;
5450
5451 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005452 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005453 if (!err)
5454 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005455 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005456 break;
5457 }
5458
5459 return err;
5460}
5461
5462/**
Auke Kok9a799d72007-09-15 14:07:45 -07005463 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005464 * @tx_ring: Tx descriptor ring for a specific queue
5465 *
5466 * Free all transmit software resources
5467 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005468void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005469{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005470 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005471
5472 vfree(tx_ring->tx_buffer_info);
5473 tx_ring->tx_buffer_info = NULL;
5474
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005475 /* if not set, then don't free */
5476 if (!tx_ring->desc)
5477 return;
5478
5479 dma_free_coherent(tx_ring->dev, tx_ring->size,
5480 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005481
5482 tx_ring->desc = NULL;
5483}
5484
5485/**
5486 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5487 * @adapter: board private structure
5488 *
5489 * Free all transmit software resources
5490 **/
5491static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5492{
5493 int i;
5494
5495 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005496 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005497 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005498}
5499
5500/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005501 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005502 * @rx_ring: ring to clean the resources from
5503 *
5504 * Free all receive software resources
5505 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005506void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005507{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005508 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005509
5510 vfree(rx_ring->rx_buffer_info);
5511 rx_ring->rx_buffer_info = NULL;
5512
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005513 /* if not set, then don't free */
5514 if (!rx_ring->desc)
5515 return;
5516
5517 dma_free_coherent(rx_ring->dev, rx_ring->size,
5518 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005519
5520 rx_ring->desc = NULL;
5521}
5522
5523/**
5524 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5525 * @adapter: board private structure
5526 *
5527 * Free all receive software resources
5528 **/
5529static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5530{
5531 int i;
5532
5533 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005534 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005535 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005536}
5537
5538/**
Auke Kok9a799d72007-09-15 14:07:45 -07005539 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5540 * @netdev: network interface device structure
5541 * @new_mtu: new value for maximum frame size
5542 *
5543 * Returns 0 on success, negative on failure
5544 **/
5545static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5546{
5547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5548 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5549
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005550 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005551 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5552 return -EINVAL;
5553
5554 /*
5555 * For 82599EB we cannot allow PF to change MTU greater than 1500
5556 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
5557 * don't allocate and chain buffers correctly.
5558 */
5559 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5560 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
5561 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00005562 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07005563
Emil Tantilov396e7992010-07-01 20:05:12 +00005564 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005565
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005566 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005567 netdev->mtu = new_mtu;
5568
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005569 if (netif_running(netdev))
5570 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005571
5572 return 0;
5573}
5574
5575/**
5576 * ixgbe_open - Called when a network interface is made active
5577 * @netdev: network interface device structure
5578 *
5579 * Returns 0 on success, negative value on failure
5580 *
5581 * The open entry point is called when a network interface is made
5582 * active by the system (IFF_UP). At this point all resources needed
5583 * for transmit and receive operations are allocated, the interrupt
5584 * handler is registered with the OS, the watchdog timer is started,
5585 * and the stack is notified that the interface is ready.
5586 **/
5587static int ixgbe_open(struct net_device *netdev)
5588{
5589 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5590 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005591
Auke Kok4bebfaa2008-02-11 09:26:01 -08005592 /* disallow open during test */
5593 if (test_bit(__IXGBE_TESTING, &adapter->state))
5594 return -EBUSY;
5595
Jesse Brandeburg54386462009-04-17 20:44:27 +00005596 netif_carrier_off(netdev);
5597
Auke Kok9a799d72007-09-15 14:07:45 -07005598 /* allocate transmit descriptors */
5599 err = ixgbe_setup_all_tx_resources(adapter);
5600 if (err)
5601 goto err_setup_tx;
5602
Auke Kok9a799d72007-09-15 14:07:45 -07005603 /* allocate receive descriptors */
5604 err = ixgbe_setup_all_rx_resources(adapter);
5605 if (err)
5606 goto err_setup_rx;
5607
5608 ixgbe_configure(adapter);
5609
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005610 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005611 if (err)
5612 goto err_req_irq;
5613
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005614 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005615
5616 return 0;
5617
Auke Kok9a799d72007-09-15 14:07:45 -07005618err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005619err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005620 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005621err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005622 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005623 ixgbe_reset(adapter);
5624
5625 return err;
5626}
5627
5628/**
5629 * ixgbe_close - Disables a network interface
5630 * @netdev: network interface device structure
5631 *
5632 * Returns 0, this is not allowed to fail
5633 *
5634 * The close entry point is called when an interface is de-activated
5635 * by the OS. The hardware is still under the drivers control, but
5636 * needs to be disabled. A global MAC reset is issued to stop the
5637 * hardware, and all transmit and receive resources are freed.
5638 **/
5639static int ixgbe_close(struct net_device *netdev)
5640{
5641 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005642
5643 ixgbe_down(adapter);
5644 ixgbe_free_irq(adapter);
5645
Alexander Duycke4911d52011-05-11 07:18:52 +00005646 ixgbe_fdir_filter_exit(adapter);
5647
Auke Kok9a799d72007-09-15 14:07:45 -07005648 ixgbe_free_all_tx_resources(adapter);
5649 ixgbe_free_all_rx_resources(adapter);
5650
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005651 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005652
5653 return 0;
5654}
5655
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005656#ifdef CONFIG_PM
5657static int ixgbe_resume(struct pci_dev *pdev)
5658{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005659 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5660 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005661 u32 err;
5662
5663 pci_set_power_state(pdev, PCI_D0);
5664 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005665 /*
5666 * pci_restore_state clears dev->state_saved so call
5667 * pci_save_state to restore it.
5668 */
5669 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005670
5671 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005672 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005673 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005674 return err;
5675 }
5676 pci_set_master(pdev);
5677
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005678 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005679
5680 err = ixgbe_init_interrupt_scheme(adapter);
5681 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005682 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005683 return err;
5684 }
5685
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005686 ixgbe_reset(adapter);
5687
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005688 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5689
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005690 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005691 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005692 if (err)
5693 return err;
5694 }
5695
5696 netif_device_attach(netdev);
5697
5698 return 0;
5699}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005700#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005701
5702static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005703{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005704 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5705 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005706 struct ixgbe_hw *hw = &adapter->hw;
5707 u32 ctrl, fctrl;
5708 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005709#ifdef CONFIG_PM
5710 int retval = 0;
5711#endif
5712
5713 netif_device_detach(netdev);
5714
5715 if (netif_running(netdev)) {
5716 ixgbe_down(adapter);
5717 ixgbe_free_irq(adapter);
5718 ixgbe_free_all_tx_resources(adapter);
5719 ixgbe_free_all_rx_resources(adapter);
5720 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005721
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005722 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005723#ifdef CONFIG_DCB
5724 kfree(adapter->ixgbe_ieee_pfc);
5725 kfree(adapter->ixgbe_ieee_ets);
5726#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005727
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005728#ifdef CONFIG_PM
5729 retval = pci_save_state(pdev);
5730 if (retval)
5731 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005732
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005733#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005734 if (wufc) {
5735 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005736
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005737 /* turn on all-multi mode if wake on multicast is enabled */
5738 if (wufc & IXGBE_WUFC_MC) {
5739 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5740 fctrl |= IXGBE_FCTRL_MPE;
5741 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5742 }
5743
5744 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5745 ctrl |= IXGBE_CTRL_GIO_DIS;
5746 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5747
5748 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5749 } else {
5750 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5751 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5752 }
5753
Alexander Duyckbd508172010-11-16 19:27:03 -08005754 switch (hw->mac.type) {
5755 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005756 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005757 break;
5758 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005759 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005760 pci_wake_from_d3(pdev, !!wufc);
5761 break;
5762 default:
5763 break;
5764 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005765
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005766 *enable_wake = !!wufc;
5767
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005768 ixgbe_release_hw_control(adapter);
5769
5770 pci_disable_device(pdev);
5771
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005772 return 0;
5773}
5774
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005775#ifdef CONFIG_PM
5776static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5777{
5778 int retval;
5779 bool wake;
5780
5781 retval = __ixgbe_shutdown(pdev, &wake);
5782 if (retval)
5783 return retval;
5784
5785 if (wake) {
5786 pci_prepare_to_sleep(pdev);
5787 } else {
5788 pci_wake_from_d3(pdev, false);
5789 pci_set_power_state(pdev, PCI_D3hot);
5790 }
5791
5792 return 0;
5793}
5794#endif /* CONFIG_PM */
5795
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005796static void ixgbe_shutdown(struct pci_dev *pdev)
5797{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005798 bool wake;
5799
5800 __ixgbe_shutdown(pdev, &wake);
5801
5802 if (system_state == SYSTEM_POWER_OFF) {
5803 pci_wake_from_d3(pdev, wake);
5804 pci_set_power_state(pdev, PCI_D3hot);
5805 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005806}
5807
5808/**
Auke Kok9a799d72007-09-15 14:07:45 -07005809 * ixgbe_update_stats - Update the board statistics counters.
5810 * @adapter: board private structure
5811 **/
5812void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5813{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005814 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005815 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005816 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005817 u64 total_mpc = 0;
5818 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005819 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5820 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005821 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005822#ifdef IXGBE_FCOE
5823 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5824 unsigned int cpu;
5825 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5826#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005827
Don Skidmored08935c2010-06-11 13:20:29 +00005828 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5829 test_bit(__IXGBE_RESETTING, &adapter->state))
5830 return;
5831
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005832 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005833 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005834 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005835 for (i = 0; i < 16; i++)
5836 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005837 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005838 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005839 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5840 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005841 }
5842 adapter->rsc_total_count = rsc_count;
5843 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005844 }
5845
Alexander Duyck5b7da512010-11-16 19:26:50 -08005846 for (i = 0; i < adapter->num_rx_queues; i++) {
5847 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5848 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5849 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5850 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005851 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005852 bytes += rx_ring->stats.bytes;
5853 packets += rx_ring->stats.packets;
5854 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005855 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005856 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5857 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005858 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005859 netdev->stats.rx_bytes = bytes;
5860 netdev->stats.rx_packets = packets;
5861
5862 bytes = 0;
5863 packets = 0;
5864 /* gather some stats to the adapter struct that are per queue */
5865 for (i = 0; i < adapter->num_tx_queues; i++) {
5866 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5867 restart_queue += tx_ring->tx_stats.restart_queue;
5868 tx_busy += tx_ring->tx_stats.tx_busy;
5869 bytes += tx_ring->stats.bytes;
5870 packets += tx_ring->stats.packets;
5871 }
5872 adapter->restart_queue = restart_queue;
5873 adapter->tx_busy = tx_busy;
5874 netdev->stats.tx_bytes = bytes;
5875 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005876
Joe Perches7ca647b2010-09-07 21:35:40 +00005877 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005878
5879 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005880 for (i = 0; i < 8; i++) {
5881 /* for packet buffers not used, the register should read 0 */
5882 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5883 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005884 hwstats->mpc[i] += mpc;
5885 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005886 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5887 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005888 switch (hw->mac.type) {
5889 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005890 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5891 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5892 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005893 hwstats->pxonrxc[i] +=
5894 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005895 break;
5896 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005897 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005898 hwstats->pxonrxc[i] +=
5899 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005900 break;
5901 default:
5902 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005903 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005904 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005905
5906 /*16 register reads */
5907 for (i = 0; i < 16; i++) {
5908 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5909 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5910 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5911 (hw->mac.type == ixgbe_mac_X540)) {
5912 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5913 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5914 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5915 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5916 }
5917 }
5918
Joe Perches7ca647b2010-09-07 21:35:40 +00005919 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005920 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005921 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005922
John Fastabendc84d3242010-11-16 19:27:12 -08005923 ixgbe_update_xoff_received(adapter);
5924
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005925 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005926 switch (hw->mac.type) {
5927 case ixgbe_mac_82598EB:
5928 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005929 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5930 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5931 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5932 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005933 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005934 /* OS2BMC stats are X540 only*/
5935 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5936 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5937 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5938 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5939 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005940 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005941 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005942 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005943 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005944 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005945 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005946 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005947 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5948 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005949#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005950 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5951 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5952 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5953 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5954 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5955 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005956 /* Add up per cpu counters for total ddp aloc fail */
5957 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5958 for_each_possible_cpu(cpu) {
5959 fcoe_noddp_counts_sum +=
5960 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5961 fcoe_noddp_ext_buff_counts_sum +=
5962 *per_cpu_ptr(fcoe->
5963 pcpu_noddp_ext_buff, cpu);
5964 }
5965 }
5966 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5967 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005968#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005969 break;
5970 default:
5971 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005972 }
Auke Kok9a799d72007-09-15 14:07:45 -07005973 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005974 hwstats->bprc += bprc;
5975 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005976 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005977 hwstats->mprc -= bprc;
5978 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5979 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5980 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5981 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5982 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5983 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5984 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5985 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005986 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005987 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005988 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005989 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005990 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5991 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005992 /*
5993 * 82598 errata - tx of flow control packets is included in tx counters
5994 */
5995 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005996 hwstats->gptc -= xon_off_tot;
5997 hwstats->mptc -= xon_off_tot;
5998 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5999 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6000 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6001 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6002 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6003 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6004 hwstats->ptc64 -= xon_off_tot;
6005 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6006 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6007 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6008 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6009 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6010 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006011
6012 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006013 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006014
6015 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006016 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006017 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006018 netdev->stats.rx_length_errors = hwstats->rlec;
6019 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006020 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006021}
6022
6023/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006024 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6025 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006026 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006027static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006028{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006029 struct ixgbe_hw *hw = &adapter->hw;
6030 int i;
6031
Alexander Duyckd034acf2011-04-27 09:25:34 +00006032 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6033 return;
6034
6035 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6036
6037 /* if interface is down do nothing */
6038 if (test_bit(__IXGBE_DOWN, &adapter->state))
6039 return;
6040
6041 /* do nothing if we are not using signature filters */
6042 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6043 return;
6044
6045 adapter->fdir_overflow++;
6046
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006047 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6048 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006049 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006050 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006051 /* re-enable flow director interrupts */
6052 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006053 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006054 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006055 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006056 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006057}
6058
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006059/**
6060 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6061 * @adapter - pointer to the device adapter structure
6062 *
6063 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006064 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006065 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006066 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006067 */
6068static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6069{
Auke Kok9a799d72007-09-15 14:07:45 -07006070 struct ixgbe_hw *hw = &adapter->hw;
6071 u64 eics = 0;
6072 int i;
6073
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006074 /* If we're down or resetting, just bail */
6075 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6076 test_bit(__IXGBE_RESETTING, &adapter->state))
6077 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006078
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006079 /* Force detection of hung controller */
6080 if (netif_carrier_ok(adapter->netdev)) {
6081 for (i = 0; i < adapter->num_tx_queues; i++)
6082 set_check_for_tx_hang(adapter->tx_ring[i]);
6083 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006084
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006085 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006086 /*
6087 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006088 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006089 * would set *both* EIMS and EICS for any bit in EIAM
6090 */
6091 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6092 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006093 } else {
6094 /* get one bit for every active tx/rx interrupt vector */
6095 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6096 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006097 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006098 eics |= ((u64)1 << i);
6099 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006100 }
6101
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006102 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006103 ixgbe_irq_rearm_queues(adapter, eics);
6104
Alexander Duyckfe49f042009-06-04 16:00:09 +00006105}
6106
6107/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006108 * ixgbe_watchdog_update_link - update the link status
6109 * @adapter - pointer to the device adapter structure
6110 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006111 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006112static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006113{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006114 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006115 u32 link_speed = adapter->link_speed;
6116 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006117 int i;
6118
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006119 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6120 return;
6121
6122 if (hw->mac.ops.check_link) {
6123 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006124 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006125 /* always assume link is up, if no check link function */
6126 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6127 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006128 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006129 if (link_up) {
6130 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6131 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6132 hw->mac.ops.fc_enable(hw, i);
6133 } else {
6134 hw->mac.ops.fc_enable(hw, 0);
6135 }
6136 }
6137
6138 if (link_up ||
6139 time_after(jiffies, (adapter->link_check_timeout +
6140 IXGBE_TRY_LINK_TIMEOUT))) {
6141 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6142 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6143 IXGBE_WRITE_FLUSH(hw);
6144 }
6145
6146 adapter->link_up = link_up;
6147 adapter->link_speed = link_speed;
6148}
6149
6150/**
6151 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6152 * print link up message
6153 * @adapter - pointer to the device adapter structure
6154 **/
6155static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6156{
6157 struct net_device *netdev = adapter->netdev;
6158 struct ixgbe_hw *hw = &adapter->hw;
6159 u32 link_speed = adapter->link_speed;
6160 bool flow_rx, flow_tx;
6161
6162 /* only continue if link was previously down */
6163 if (netif_carrier_ok(netdev))
6164 return;
6165
6166 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6167
6168 switch (hw->mac.type) {
6169 case ixgbe_mac_82598EB: {
6170 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6171 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6172 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6173 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6174 }
6175 break;
6176 case ixgbe_mac_X540:
6177 case ixgbe_mac_82599EB: {
6178 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6179 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6180 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6181 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6182 }
6183 break;
6184 default:
6185 flow_tx = false;
6186 flow_rx = false;
6187 break;
6188 }
6189 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6190 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6191 "10 Gbps" :
6192 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6193 "1 Gbps" :
6194 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6195 "100 Mbps" :
6196 "unknown speed"))),
6197 ((flow_rx && flow_tx) ? "RX/TX" :
6198 (flow_rx ? "RX" :
6199 (flow_tx ? "TX" : "None"))));
6200
6201 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006202 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006203}
6204
6205/**
6206 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6207 * print link down message
6208 * @adapter - pointer to the adapter structure
6209 **/
6210static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6211{
6212 struct net_device *netdev = adapter->netdev;
6213 struct ixgbe_hw *hw = &adapter->hw;
6214
6215 adapter->link_up = false;
6216 adapter->link_speed = 0;
6217
6218 /* only continue if link was up previously */
6219 if (!netif_carrier_ok(netdev))
6220 return;
6221
6222 /* poll for SFP+ cable when link is down */
6223 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6224 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6225
6226 e_info(drv, "NIC Link is Down\n");
6227 netif_carrier_off(netdev);
6228}
6229
6230/**
6231 * ixgbe_watchdog_flush_tx - flush queues on link down
6232 * @adapter - pointer to the device adapter structure
6233 **/
6234static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6235{
6236 int i;
6237 int some_tx_pending = 0;
6238
6239 if (!netif_carrier_ok(adapter->netdev)) {
6240 for (i = 0; i < adapter->num_tx_queues; i++) {
6241 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6242 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6243 some_tx_pending = 1;
6244 break;
6245 }
6246 }
6247
6248 if (some_tx_pending) {
6249 /* We've lost link, so the controller stops DMA,
6250 * but we've got queued Tx work that's never going
6251 * to get done, so reset controller to flush Tx.
6252 * (Do the reset outside of interrupt context).
6253 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006254 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006255 }
6256 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006257}
6258
Greg Rosea985b6c32010-11-18 03:02:52 +00006259static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6260{
6261 u32 ssvpc;
6262
6263 /* Do not perform spoof check for 82598 */
6264 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6265 return;
6266
6267 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6268
6269 /*
6270 * ssvpc register is cleared on read, if zero then no
6271 * spoofed packets in the last interval.
6272 */
6273 if (!ssvpc)
6274 return;
6275
6276 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6277}
6278
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006279/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006280 * ixgbe_watchdog_subtask - check and bring link up
6281 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006282 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006283static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006284{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006285 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006286 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6287 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006288 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006289
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006290 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006291
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006292 if (adapter->link_up)
6293 ixgbe_watchdog_link_is_up(adapter);
6294 else
6295 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006296
Greg Rosea985b6c32010-11-18 03:02:52 +00006297 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006298 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006299
6300 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006301}
6302
Alexander Duyck70864002011-04-27 09:13:56 +00006303/**
6304 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6305 * @adapter - the ixgbe adapter structure
6306 **/
6307static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6308{
6309 struct ixgbe_hw *hw = &adapter->hw;
6310 s32 err;
6311
6312 /* not searching for SFP so there is nothing to do here */
6313 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6314 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6315 return;
6316
6317 /* someone else is in init, wait until next service event */
6318 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6319 return;
6320
6321 err = hw->phy.ops.identify_sfp(hw);
6322 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6323 goto sfp_out;
6324
6325 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6326 /* If no cable is present, then we need to reset
6327 * the next time we find a good cable. */
6328 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6329 }
6330
6331 /* exit on error */
6332 if (err)
6333 goto sfp_out;
6334
6335 /* exit if reset not needed */
6336 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6337 goto sfp_out;
6338
6339 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6340
6341 /*
6342 * A module may be identified correctly, but the EEPROM may not have
6343 * support for that module. setup_sfp() will fail in that case, so
6344 * we should not allow that module to load.
6345 */
6346 if (hw->mac.type == ixgbe_mac_82598EB)
6347 err = hw->phy.ops.reset(hw);
6348 else
6349 err = hw->mac.ops.setup_sfp(hw);
6350
6351 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6352 goto sfp_out;
6353
6354 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6355 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6356
6357sfp_out:
6358 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6359
6360 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6361 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6362 e_dev_err("failed to initialize because an unsupported "
6363 "SFP+ module type was detected.\n");
6364 e_dev_err("Reload the driver after installing a "
6365 "supported module.\n");
6366 unregister_netdev(adapter->netdev);
6367 }
6368}
6369
6370/**
6371 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6372 * @adapter - the ixgbe adapter structure
6373 **/
6374static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6375{
6376 struct ixgbe_hw *hw = &adapter->hw;
6377 u32 autoneg;
6378 bool negotiation;
6379
6380 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6381 return;
6382
6383 /* someone else is in init, wait until next service event */
6384 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6385 return;
6386
6387 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6388
6389 autoneg = hw->phy.autoneg_advertised;
6390 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6391 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006392 if (hw->mac.ops.setup_link)
6393 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6394
6395 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6396 adapter->link_check_timeout = jiffies;
6397 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6398}
6399
Greg Rose83c61fa2011-09-07 05:59:35 +00006400#ifdef CONFIG_PCI_IOV
6401static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6402{
6403 int vf;
6404 struct ixgbe_hw *hw = &adapter->hw;
6405 struct net_device *netdev = adapter->netdev;
6406 u32 gpc;
6407 u32 ciaa, ciad;
6408
6409 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6410 if (gpc) /* If incrementing then no need for the check below */
6411 return;
6412 /*
6413 * Check to see if a bad DMA write target from an errant or
6414 * malicious VF has caused a PCIe error. If so then we can
6415 * issue a VFLR to the offending VF(s) and then resume without
6416 * requesting a full slot reset.
6417 */
6418
6419 for (vf = 0; vf < adapter->num_vfs; vf++) {
6420 ciaa = (vf << 16) | 0x80000000;
6421 /* 32 bit read so align, we really want status at offset 6 */
6422 ciaa |= PCI_COMMAND;
6423 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6424 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6425 ciaa &= 0x7FFFFFFF;
6426 /* disable debug mode asap after reading data */
6427 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6428 /* Get the upper 16 bits which will be the PCI status reg */
6429 ciad >>= 16;
6430 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6431 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6432 /* Issue VFLR */
6433 ciaa = (vf << 16) | 0x80000000;
6434 ciaa |= 0xA8;
6435 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6436 ciad = 0x00008000; /* VFLR */
6437 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6438 ciaa &= 0x7FFFFFFF;
6439 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6440 }
6441 }
6442}
6443
6444#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006445/**
6446 * ixgbe_service_timer - Timer Call-back
6447 * @data: pointer to adapter cast into an unsigned long
6448 **/
6449static void ixgbe_service_timer(unsigned long data)
6450{
6451 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6452 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006453 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006454
Greg Rose83c61fa2011-09-07 05:59:35 +00006455#ifdef CONFIG_PCI_IOV
6456 ready = false;
6457
6458 /*
6459 * don't bother with SR-IOV VF DMA hang check if there are
6460 * no VFs or the link is down
6461 */
6462 if (!adapter->num_vfs ||
6463 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6464 ready = true;
6465 goto normal_timer_service;
6466 }
6467
6468 /* If we have VFs allocated then we must check for DMA hangs */
6469 ixgbe_check_for_bad_vf(adapter);
6470 next_event_offset = HZ / 50;
6471 adapter->timer_event_accumulator++;
6472
6473 if (adapter->timer_event_accumulator >= 100) {
6474 ready = true;
6475 adapter->timer_event_accumulator = 0;
6476 }
6477
6478 goto schedule_event;
6479
6480normal_timer_service:
6481#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006482 /* poll faster when waiting for link */
6483 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6484 next_event_offset = HZ / 10;
6485 else
6486 next_event_offset = HZ * 2;
6487
Greg Rose83c61fa2011-09-07 05:59:35 +00006488#ifdef CONFIG_PCI_IOV
6489schedule_event:
6490#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006491 /* Reset the timer */
6492 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6493
Greg Rose83c61fa2011-09-07 05:59:35 +00006494 if (ready)
6495 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006496}
6497
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006498static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6499{
6500 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6501 return;
6502
6503 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6504
6505 /* If we're already down or resetting, just bail */
6506 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6507 test_bit(__IXGBE_RESETTING, &adapter->state))
6508 return;
6509
6510 ixgbe_dump(adapter);
6511 netdev_err(adapter->netdev, "Reset adapter\n");
6512 adapter->tx_timeout_count++;
6513
6514 ixgbe_reinit_locked(adapter);
6515}
6516
Alexander Duyck70864002011-04-27 09:13:56 +00006517/**
6518 * ixgbe_service_task - manages and runs subtasks
6519 * @work: pointer to work_struct containing our data
6520 **/
6521static void ixgbe_service_task(struct work_struct *work)
6522{
6523 struct ixgbe_adapter *adapter = container_of(work,
6524 struct ixgbe_adapter,
6525 service_task);
6526
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006527 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006528 ixgbe_sfp_detection_subtask(adapter);
6529 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006530 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006531 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006532 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006533 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006534
6535 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006536}
6537
Alexander Duyck897ab152011-05-27 05:31:47 +00006538void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6539 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006540{
6541 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006542 u16 i = tx_ring->next_to_use;
6543
Alexander Duycke4f74022012-01-31 02:59:44 +00006544 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006545
6546 i++;
6547 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6548
6549 /* set bits to identify this as an advanced context descriptor */
6550 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6551
6552 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6553 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6554 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6555 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6556}
6557
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006558static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6559 struct ixgbe_tx_buffer *first,
Alexander Duyck897ab152011-05-27 05:31:47 +00006560 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6561{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006562 struct sk_buff *skb = first->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006563 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006564 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006565 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006566
Alexander Duyck897ab152011-05-27 05:31:47 +00006567 if (!skb_is_gso(skb))
6568 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006569
Alexander Duyck897ab152011-05-27 05:31:47 +00006570 if (skb_header_cloned(skb)) {
6571 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6572 if (err)
6573 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006574 }
6575
Alexander Duyck897ab152011-05-27 05:31:47 +00006576 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6577 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6578
6579 if (protocol == __constant_htons(ETH_P_IP)) {
6580 struct iphdr *iph = ip_hdr(skb);
6581 iph->tot_len = 0;
6582 iph->check = 0;
6583 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6584 iph->daddr, 0,
6585 IPPROTO_TCP,
6586 0);
6587 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6588 } else if (skb_is_gso_v6(skb)) {
6589 ipv6_hdr(skb)->payload_len = 0;
6590 tcp_hdr(skb)->check =
6591 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6592 &ipv6_hdr(skb)->daddr,
6593 0, IPPROTO_TCP, 0);
6594 }
6595
Alexander Duyck091a6242012-02-08 07:51:01 +00006596 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006597 l4len = tcp_hdrlen(skb);
6598 *hdr_len = skb_transport_offset(skb) + l4len;
6599
Alexander Duyck091a6242012-02-08 07:51:01 +00006600 /* update gso size and bytecount with header size */
6601 first->gso_segs = skb_shinfo(skb)->gso_segs;
6602 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6603
Alexander Duyck897ab152011-05-27 05:31:47 +00006604 /* mss_l4len_id: use 1 as index for TSO */
6605 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6606 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6607 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6608
6609 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6610 vlan_macip_lens = skb_network_header_len(skb);
6611 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6612 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6613
6614 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6615 mss_l4len_idx);
6616
6617 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006618}
6619
Alexander Duyck897ab152011-05-27 05:31:47 +00006620static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006621 struct ixgbe_tx_buffer *first,
6622 u32 tx_flags, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006623{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006624 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006625 u32 vlan_macip_lens = 0;
6626 u32 mss_l4len_idx = 0;
6627 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006628
Alexander Duyck897ab152011-05-27 05:31:47 +00006629 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006630 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6631 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006632 return false;
6633 } else {
6634 u8 l4_hdr = 0;
6635 switch (protocol) {
6636 case __constant_htons(ETH_P_IP):
6637 vlan_macip_lens |= skb_network_header_len(skb);
6638 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6639 l4_hdr = ip_hdr(skb)->protocol;
6640 break;
6641 case __constant_htons(ETH_P_IPV6):
6642 vlan_macip_lens |= skb_network_header_len(skb);
6643 l4_hdr = ipv6_hdr(skb)->nexthdr;
6644 break;
6645 default:
6646 if (unlikely(net_ratelimit())) {
6647 dev_warn(tx_ring->dev,
6648 "partial checksum but proto=%x!\n",
6649 skb->protocol);
6650 }
6651 break;
6652 }
Auke Kok9a799d72007-09-15 14:07:45 -07006653
Alexander Duyck897ab152011-05-27 05:31:47 +00006654 switch (l4_hdr) {
6655 case IPPROTO_TCP:
6656 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6657 mss_l4len_idx = tcp_hdrlen(skb) <<
6658 IXGBE_ADVTXD_L4LEN_SHIFT;
6659 break;
6660 case IPPROTO_SCTP:
6661 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6662 mss_l4len_idx = sizeof(struct sctphdr) <<
6663 IXGBE_ADVTXD_L4LEN_SHIFT;
6664 break;
6665 case IPPROTO_UDP:
6666 mss_l4len_idx = sizeof(struct udphdr) <<
6667 IXGBE_ADVTXD_L4LEN_SHIFT;
6668 break;
6669 default:
6670 if (unlikely(net_ratelimit())) {
6671 dev_warn(tx_ring->dev,
6672 "partial checksum but l4 proto=%x!\n",
6673 skb->protocol);
6674 }
6675 break;
6676 }
Auke Kok9a799d72007-09-15 14:07:45 -07006677 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006678
Alexander Duyck897ab152011-05-27 05:31:47 +00006679 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6680 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6681
6682 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6683 type_tucmd, mss_l4len_idx);
6684
6685 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006686}
6687
Alexander Duyckd3d00232011-07-15 02:31:25 +00006688static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6689{
6690 /* set type for advanced descriptor with frame checksum insertion */
6691 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6692 IXGBE_ADVTXD_DCMD_IFCS |
6693 IXGBE_ADVTXD_DCMD_DEXT);
6694
6695 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006696 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006697 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6698
6699 /* set segmentation enable bits for TSO/FSO */
6700#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006701 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006702#else
6703 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6704#endif
6705 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6706
6707 return cmd_type;
6708}
6709
6710static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6711{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006712 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006713
6714 /* enable L4 checksum for TSO and TX checksum offload */
6715 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6716 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6717
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006718 /* enble IPv4 checksum for TSO */
6719 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6720 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006721
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006722 /* use index 1 context for TSO/FSO/FCOE */
6723#ifdef IXGBE_FCOE
6724 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6725#else
6726 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006727#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006728 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6729
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006730 /*
6731 * Check Context must be set if Tx switch is enabled, which it
6732 * always is for case where virtual functions are running
6733 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006734#ifdef IXGBE_FCOE
6735 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6736#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006737 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006738#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006739 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6740
Alexander Duyckd3d00232011-07-15 02:31:25 +00006741 return olinfo_status;
6742}
6743
6744#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6745 IXGBE_TXD_CMD_RS)
6746
6747static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006748 struct ixgbe_tx_buffer *first,
6749 u32 tx_flags,
6750 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006751{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006752 struct sk_buff *skb = first->skb;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006753 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006754 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006755 union ixgbe_adv_tx_desc *tx_desc;
6756 dma_addr_t dma;
6757 __le32 cmd_type, olinfo_status;
6758 struct skb_frag_struct *frag;
6759 unsigned int f = 0;
6760 unsigned int data_len = skb->data_len;
6761 unsigned int size = skb_headlen(skb);
6762 u32 offset = 0;
6763 u32 paylen = skb->len - hdr_len;
6764 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006765
Alexander Duyckd3d00232011-07-15 02:31:25 +00006766#ifdef IXGBE_FCOE
6767 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6768 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6769 data_len -= sizeof(struct fcoe_crc_eof);
6770 } else {
6771 size -= sizeof(struct fcoe_crc_eof) - data_len;
6772 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006773 }
Auke Kok9a799d72007-09-15 14:07:45 -07006774 }
6775
Alexander Duyckd3d00232011-07-15 02:31:25 +00006776#endif
6777 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6778 if (dma_mapping_error(dev, dma))
6779 goto dma_error;
6780
6781 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6782 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6783
Alexander Duycke4f74022012-01-31 02:59:44 +00006784 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006785
6786 for (;;) {
6787 while (size > IXGBE_MAX_DATA_PER_TXD) {
6788 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6789 tx_desc->read.cmd_type_len =
6790 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6791 tx_desc->read.olinfo_status = olinfo_status;
6792
6793 offset += IXGBE_MAX_DATA_PER_TXD;
6794 size -= IXGBE_MAX_DATA_PER_TXD;
6795
6796 tx_desc++;
6797 i++;
6798 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006799 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006800 i = 0;
6801 }
6802 }
6803
6804 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6805 tx_buffer_info->length = offset + size;
6806 tx_buffer_info->tx_flags = tx_flags;
6807 tx_buffer_info->dma = dma;
6808
6809 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
Ben Greearf43f3132012-03-06 09:42:04 +00006810 if (unlikely(skb->no_fcs))
6811 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006812 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6813 tx_desc->read.olinfo_status = olinfo_status;
6814
6815 if (!data_len)
6816 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006817
6818 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006819#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006820 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006821#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006822 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006823#endif
6824 data_len -= size;
6825 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006826
Alexander Duyckd3d00232011-07-15 02:31:25 +00006827 offset = 0;
6828 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006829
Ian Campbell877749b2011-08-29 23:18:26 +00006830 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006831 if (dma_mapping_error(dev, dma))
6832 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006833
Alexander Duyckd3d00232011-07-15 02:31:25 +00006834 tx_desc++;
6835 i++;
6836 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006837 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006838 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006839 }
6840 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006841
Alexander Duyckd3d00232011-07-15 02:31:25 +00006842 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6843
6844 i++;
6845 if (i == tx_ring->count)
6846 i = 0;
6847
6848 tx_ring->next_to_use = i;
6849
Alexander Duyck091a6242012-02-08 07:51:01 +00006850 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006851
Alexander Duyckd3d00232011-07-15 02:31:25 +00006852 /* set the timestamp */
6853 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006854
6855 /*
6856 * Force memory writes to complete before letting h/w
6857 * know there are new descriptors to fetch. (Only
6858 * applicable for weak-ordered memory model archs,
6859 * such as IA-64).
6860 */
6861 wmb();
6862
Alexander Duyckd3d00232011-07-15 02:31:25 +00006863 /* set next_to_watch value indicating a packet is present */
6864 first->next_to_watch = tx_desc;
6865
6866 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006867 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006868
6869 return;
6870dma_error:
6871 dev_err(dev, "TX DMA map failed\n");
6872
6873 /* clear dma mappings for failed tx_buffer_info map */
6874 for (;;) {
6875 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006876 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006877 if (tx_buffer_info == first)
6878 break;
6879 if (i == 0)
6880 i = tx_ring->count;
6881 i--;
6882 }
6883
Alexander Duyckd3d00232011-07-15 02:31:25 +00006884 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006885}
6886
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006887static void ixgbe_atr(struct ixgbe_ring *ring,
6888 struct ixgbe_tx_buffer *first,
Alexander Duyck69830522011-01-06 14:29:58 +00006889 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006890{
Alexander Duyck69830522011-01-06 14:29:58 +00006891 struct ixgbe_q_vector *q_vector = ring->q_vector;
6892 union ixgbe_atr_hash_dword input = { .dword = 0 };
6893 union ixgbe_atr_hash_dword common = { .dword = 0 };
6894 union {
6895 unsigned char *network;
6896 struct iphdr *ipv4;
6897 struct ipv6hdr *ipv6;
6898 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006899 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006900 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006901
Alexander Duyck69830522011-01-06 14:29:58 +00006902 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6903 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006904 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006905
Alexander Duyck69830522011-01-06 14:29:58 +00006906 /* do nothing if sampling is disabled */
6907 if (!ring->atr_sample_rate)
6908 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006909
Alexander Duyck69830522011-01-06 14:29:58 +00006910 ring->atr_count++;
6911
6912 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006913 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006914
6915 /* Currently only IPv4/IPv6 with TCP is supported */
6916 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6917 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6918 (protocol != __constant_htons(ETH_P_IP) ||
6919 hdr.ipv4->protocol != IPPROTO_TCP))
6920 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006921
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006922 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006923
Alexander Duyck66f32a82011-06-29 05:43:22 +00006924 /* skip this packet since it is invalid or the socket is closing */
6925 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006926 return;
6927
6928 /* sample on all syn packets or once every atr sample count */
6929 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6930 return;
6931
6932 /* reset sample count */
6933 ring->atr_count = 0;
6934
6935 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6936
6937 /*
6938 * src and dst are inverted, think how the receiver sees them
6939 *
6940 * The input is broken into two sections, a non-compressed section
6941 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6942 * is XORed together and stored in the compressed dword.
6943 */
6944 input.formatted.vlan_id = vlan_id;
6945
6946 /*
6947 * since src port and flex bytes occupy the same word XOR them together
6948 * and write the value to source port portion of compressed dword
6949 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006950 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006951 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6952 else
6953 common.port.src ^= th->dest ^ protocol;
6954 common.port.dst ^= th->source;
6955
6956 if (protocol == __constant_htons(ETH_P_IP)) {
6957 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6958 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6959 } else {
6960 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6961 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6962 hdr.ipv6->saddr.s6_addr32[1] ^
6963 hdr.ipv6->saddr.s6_addr32[2] ^
6964 hdr.ipv6->saddr.s6_addr32[3] ^
6965 hdr.ipv6->daddr.s6_addr32[0] ^
6966 hdr.ipv6->daddr.s6_addr32[1] ^
6967 hdr.ipv6->daddr.s6_addr32[2] ^
6968 hdr.ipv6->daddr.s6_addr32[3];
6969 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006970
6971 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006972 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6973 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006974}
6975
Alexander Duyck63544e92011-05-27 05:31:42 +00006976static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006977{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006978 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006979 /* Herbert's original patch had:
6980 * smp_mb__after_netif_stop_queue();
6981 * but since that doesn't exist yet, just open code it. */
6982 smp_mb();
6983
6984 /* We need to check again in a case another CPU has just
6985 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006986 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006987 return -EBUSY;
6988
6989 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006990 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006991 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006992 return 0;
6993}
6994
Alexander Duyck82d4e462011-06-11 01:44:58 +00006995static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006996{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006997 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006998 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006999 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007000}
7001
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007002static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
7003{
7004 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00007005 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7006 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00007007#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00007008 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00007009
John Fastabende5b64632011-03-08 03:44:52 +00007010 if (((protocol == htons(ETH_P_FCOE)) ||
7011 (protocol == htons(ETH_P_FIP))) &&
7012 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
7013 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
7014 txq += adapter->ring_feature[RING_F_FCOE].mask;
7015 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00007016 }
7017#endif
7018
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007019 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
7020 while (unlikely(txq >= dev->real_num_tx_queues))
7021 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00007022 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007023 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007024
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007025 return skb_tx_hash(dev, skb);
7026}
7027
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007028netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007029 struct ixgbe_adapter *adapter,
7030 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007031{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007032 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007033 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007034 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007035#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7036 unsigned short f;
7037#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007038 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007039 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007040 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007041
Alexander Duycka535c302011-05-27 05:31:52 +00007042 /*
7043 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007044 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007045 * + 2 desc gap to keep tail from touching head,
7046 * + 1 desc for context descriptor,
7047 * otherwise try next time
7048 */
7049#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7050 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7051 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7052#else
7053 count += skb_shinfo(skb)->nr_frags;
7054#endif
7055 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7056 tx_ring->tx_stats.tx_busy++;
7057 return NETDEV_TX_BUSY;
7058 }
7059
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007060 /* record the location of the first descriptor for this packet */
7061 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7062 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007063 first->bytecount = skb->len;
7064 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007065
Alexander Duyck66f32a82011-06-29 05:43:22 +00007066 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007067 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007068 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7069 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7070 /* else if it is a SW VLAN check the next protocol and store the tag */
7071 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7072 struct vlan_hdr *vhdr, _vhdr;
7073 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7074 if (!vhdr)
7075 goto out_drop;
7076
7077 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007078 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7079 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007080 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007081 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007082
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007083#ifdef CONFIG_PCI_IOV
7084 /*
7085 * Use the l2switch_enable flag - would be false if the DMA
7086 * Tx switch had been disabled.
7087 */
7088 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7089 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7090
7091#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007092 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007093 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007094 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7095 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007096 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007097 tx_flags |= (skb->priority & 0x7) <<
7098 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007099 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7100 struct vlan_ethhdr *vhdr;
7101 if (skb_header_cloned(skb) &&
7102 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7103 goto out_drop;
7104 vhdr = (struct vlan_ethhdr *)skb->data;
7105 vhdr->h_vlan_TCI = htons(tx_flags >>
7106 IXGBE_TX_FLAGS_VLAN_SHIFT);
7107 } else {
7108 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7109 }
7110 }
Alexander Duycka535c302011-05-27 05:31:52 +00007111
Yi Zoueacd73f2009-05-13 13:11:06 +00007112#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007113 /* setup tx offload for FCoE */
7114 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7115 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007116 tso = ixgbe_fso(tx_ring, first, tx_flags, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007117 if (tso < 0)
7118 goto out_drop;
7119 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007120 tx_flags |= IXGBE_TX_FLAGS_FSO |
7121 IXGBE_TX_FLAGS_FCOE;
7122 else
7123 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007124
Alexander Duyck66f32a82011-06-29 05:43:22 +00007125 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007126 }
Auke Kok9a799d72007-09-15 14:07:45 -07007127
Auke Kok9a799d72007-09-15 14:07:45 -07007128#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007129 /* setup IPv4/IPv6 offloads */
7130 if (protocol == __constant_htons(ETH_P_IP))
7131 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007132
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007133 tso = ixgbe_tso(tx_ring, first, tx_flags, protocol, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007134 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007135 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007136 else if (tso)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007137 tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007138 else if (ixgbe_tx_csum(tx_ring, first, tx_flags, protocol))
Alexander Duyck66f32a82011-06-29 05:43:22 +00007139 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7140
7141 /* add the ATR filter if ATR is on */
7142 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007143 ixgbe_atr(tx_ring, first, tx_flags, protocol);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007144
7145#ifdef IXGBE_FCOE
7146xmit_fcoe:
7147#endif /* IXGBE_FCOE */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007148 ixgbe_tx_map(tx_ring, first, tx_flags, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007149
7150 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007151
7152 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007153
7154out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007155 dev_kfree_skb_any(first->skb);
7156 first->skb = NULL;
7157
Alexander Duyck897ab152011-05-27 05:31:47 +00007158 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007159}
7160
Alexander Duycka50c29d2012-02-08 07:50:40 +00007161static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7162 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007163{
7164 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7165 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007166
Alexander Duycka50c29d2012-02-08 07:50:40 +00007167 if (skb->len <= 0) {
7168 dev_kfree_skb_any(skb);
7169 return NETDEV_TX_OK;
7170 }
7171
7172 /*
7173 * The minimum packet size for olinfo paylen is 17 so pad the skb
7174 * in order to meet this minimum size requirement.
7175 */
7176 if (skb->len < 17) {
7177 if (skb_padto(skb, 17))
7178 return NETDEV_TX_OK;
7179 skb->len = 17;
7180 }
7181
Auke Kok9a799d72007-09-15 14:07:45 -07007182 tx_ring = adapter->tx_ring[skb->queue_mapping];
7183 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7184}
7185
7186/**
7187 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007188 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007189 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007190 *
Auke Kok9a799d72007-09-15 14:07:45 -07007191 * Returns 0 on success, negative on failure
7192 **/
7193static int ixgbe_set_mac(struct net_device *netdev, void *p)
7194{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007195 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7196 struct ixgbe_hw *hw = &adapter->hw;
7197 struct sockaddr *addr = p;
7198
7199 if (!is_valid_ether_addr(addr->sa_data))
7200 return -EADDRNOTAVAIL;
7201
7202 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7203 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7204
7205 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7206 IXGBE_RAH_AV);
7207
7208 return 0;
7209}
7210
7211static int
7212ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7213{
7214 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7215 struct ixgbe_hw *hw = &adapter->hw;
7216 u16 value;
7217 int rc;
7218
7219 if (prtad != hw->phy.mdio.prtad)
7220 return -EINVAL;
7221 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7222 if (!rc)
7223 rc = value;
7224 return rc;
7225}
7226
7227static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7228 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007229{
7230 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007231 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007232
7233 if (prtad != hw->phy.mdio.prtad)
7234 return -EINVAL;
7235 return hw->phy.ops.write_reg(hw, addr, devad, value);
7236}
7237
7238static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7239{
7240 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7241
7242 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7243}
7244
7245/**
7246 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7247 * netdev->dev_addrs
7248 * @netdev: network interface device structure
7249 *
7250 * Returns non-zero on failure
7251 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007252static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007253{
7254 int err = 0;
7255 struct ixgbe_adapter *adapter = netdev_priv(dev);
7256 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7257
7258 if (is_valid_ether_addr(mac->san_addr)) {
7259 rtnl_lock();
7260 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7261 rtnl_unlock();
7262 }
7263 return err;
7264}
7265
7266/**
7267 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7268 * netdev->dev_addrs
7269 * @netdev: network interface device structure
7270 *
Auke Kok9a799d72007-09-15 14:07:45 -07007271 * Returns non-zero on failure
7272 **/
7273static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7274{
7275 int err = 0;
7276 struct ixgbe_adapter *adapter = netdev_priv(dev);
7277 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7278
7279 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007280 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007281 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007282 rtnl_unlock();
7283 }
7284 return err;
7285}
Auke Kok9a799d72007-09-15 14:07:45 -07007286
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007287#ifdef CONFIG_NET_POLL_CONTROLLER
7288/*
7289 * Polling 'interrupt' - used by things like netconsole to send skbs
7290 * without having to re-enable interrupts. It's not called while
7291 * the interrupt routine is executing.
7292 */
7293static void ixgbe_netpoll(struct net_device *netdev)
7294{
7295 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007296 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007297
7298 /* if interface is down do nothing */
7299 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007300 return;
7301
7302 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007303 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007304 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007305 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007306 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007307 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007308 }
7309 } else {
7310 ixgbe_intr(adapter->pdev->irq, netdev);
7311 }
7312 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7313}
7314#endif
7315
Eric Dumazetde1036b2010-10-20 23:00:04 +00007316static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7317 struct rtnl_link_stats64 *stats)
7318{
7319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7320 int i;
7321
Eric Dumazet1a515022010-11-16 19:26:42 -08007322 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007323 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007324 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007325 u64 bytes, packets;
7326 unsigned int start;
7327
Eric Dumazet1a515022010-11-16 19:26:42 -08007328 if (ring) {
7329 do {
7330 start = u64_stats_fetch_begin_bh(&ring->syncp);
7331 packets = ring->stats.packets;
7332 bytes = ring->stats.bytes;
7333 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7334 stats->rx_packets += packets;
7335 stats->rx_bytes += bytes;
7336 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007337 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007338
7339 for (i = 0; i < adapter->num_tx_queues; i++) {
7340 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7341 u64 bytes, packets;
7342 unsigned int start;
7343
7344 if (ring) {
7345 do {
7346 start = u64_stats_fetch_begin_bh(&ring->syncp);
7347 packets = ring->stats.packets;
7348 bytes = ring->stats.bytes;
7349 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7350 stats->tx_packets += packets;
7351 stats->tx_bytes += bytes;
7352 }
7353 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007354 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007355 /* following stats updated by ixgbe_watchdog_task() */
7356 stats->multicast = netdev->stats.multicast;
7357 stats->rx_errors = netdev->stats.rx_errors;
7358 stats->rx_length_errors = netdev->stats.rx_length_errors;
7359 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7360 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7361 return stats;
7362}
7363
John Fastabend8b1c0b22011-05-03 02:26:48 +00007364/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7365 * #adapter: pointer to ixgbe_adapter
7366 * @tc: number of traffic classes currently enabled
7367 *
7368 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7369 * 802.1Q priority maps to a packet buffer that exists.
7370 */
7371static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7372{
7373 struct ixgbe_hw *hw = &adapter->hw;
7374 u32 reg, rsave;
7375 int i;
7376
7377 /* 82598 have a static priority to TC mapping that can not
7378 * be changed so no validation is needed.
7379 */
7380 if (hw->mac.type == ixgbe_mac_82598EB)
7381 return;
7382
7383 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7384 rsave = reg;
7385
7386 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7387 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7388
7389 /* If up2tc is out of bounds default to zero */
7390 if (up2tc > tc)
7391 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7392 }
7393
7394 if (reg != rsave)
7395 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7396
7397 return;
7398}
7399
7400
7401/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7402 * classes.
7403 *
7404 * @netdev: net device to configure
7405 * @tc: number of traffic classes to enable
7406 */
7407int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7408{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007409 struct ixgbe_adapter *adapter = netdev_priv(dev);
7410 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007411
John Fastabende7589ea2011-07-18 22:38:36 +00007412 /* Multiple traffic classes requires multiple queues */
7413 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7414 e_err(drv, "Enable failed, needs MSI-X\n");
7415 return -EINVAL;
7416 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007417
7418 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007419 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007420 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7421 return -EINVAL;
7422
7423 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007424 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007425 * hardware is not flexible enough to do this dynamically.
7426 */
7427 if (netif_running(dev))
7428 ixgbe_close(dev);
7429 ixgbe_clear_interrupt_scheme(adapter);
7430
John Fastabende7589ea2011-07-18 22:38:36 +00007431 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007432 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007433 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7434
7435 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7436 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7437
7438 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7439 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7440 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007441 netdev_reset_tc(dev);
7442
John Fastabende7589ea2011-07-18 22:38:36 +00007443 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7444
7445 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7446 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7447
7448 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7449 adapter->dcb_cfg.pfc_mode_enable = false;
7450 }
7451
John Fastabend8b1c0b22011-05-03 02:26:48 +00007452 ixgbe_init_interrupt_scheme(adapter);
7453 ixgbe_validate_rtr(adapter, tc);
7454 if (netif_running(dev))
7455 ixgbe_open(dev);
7456
7457 return 0;
7458}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007459
Don Skidmore082757a2011-07-21 05:55:00 +00007460void ixgbe_do_reset(struct net_device *netdev)
7461{
7462 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7463
7464 if (netif_running(netdev))
7465 ixgbe_reinit_locked(adapter);
7466 else
7467 ixgbe_reset(adapter);
7468}
7469
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007470static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7471 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007472{
7473 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7474
7475#ifdef CONFIG_DCB
7476 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7477 data &= ~NETIF_F_HW_VLAN_RX;
7478#endif
7479
7480 /* return error if RXHASH is being enabled when RSS is not supported */
7481 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7482 data &= ~NETIF_F_RXHASH;
7483
7484 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7485 if (!(data & NETIF_F_RXCSUM))
7486 data &= ~NETIF_F_LRO;
7487
7488 /* Turn off LRO if not RSC capable or invalid ITR settings */
7489 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7490 data &= ~NETIF_F_LRO;
7491 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7492 (adapter->rx_itr_setting != 1 &&
7493 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7494 data &= ~NETIF_F_LRO;
7495 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7496 }
7497
7498 return data;
7499}
7500
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007501static int ixgbe_set_features(struct net_device *netdev,
7502 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007503{
7504 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ben Greear3f2d1c02012-03-08 08:28:41 +00007505 netdev_features_t changed = netdev->features ^ data;
Don Skidmore082757a2011-07-21 05:55:00 +00007506 bool need_reset = false;
7507
Don Skidmore082757a2011-07-21 05:55:00 +00007508 /* Make sure RSC matches LRO, reset if change */
7509 if (!!(data & NETIF_F_LRO) !=
7510 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7511 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7512 switch (adapter->hw.mac.type) {
7513 case ixgbe_mac_X540:
7514 case ixgbe_mac_82599EB:
7515 need_reset = true;
7516 break;
7517 default:
7518 break;
7519 }
7520 }
7521
7522 /*
7523 * Check if Flow Director n-tuple support was enabled or disabled. If
7524 * the state changed, we need to reset.
7525 */
7526 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7527 /* turn off ATR, enable perfect filters and reset */
7528 if (data & NETIF_F_NTUPLE) {
7529 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7530 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7531 need_reset = true;
7532 }
7533 } else if (!(data & NETIF_F_NTUPLE)) {
7534 /* turn off Flow Director, set ATR and reset */
7535 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7536 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7537 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7538 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7539 need_reset = true;
7540 }
7541
Ben Greear3f2d1c02012-03-08 08:28:41 +00007542 if (changed & NETIF_F_RXALL)
7543 need_reset = true;
7544
7545 netdev->features = data;
Don Skidmore082757a2011-07-21 05:55:00 +00007546 if (need_reset)
7547 ixgbe_do_reset(netdev);
7548
7549 return 0;
7550
7551}
7552
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007553static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007554 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007555 .ndo_stop = ixgbe_close,
7556 .ndo_start_xmit = ixgbe_xmit_frame,
7557 .ndo_select_queue = ixgbe_select_queue,
7558 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007559 .ndo_validate_addr = eth_validate_addr,
7560 .ndo_set_mac_address = ixgbe_set_mac,
7561 .ndo_change_mtu = ixgbe_change_mtu,
7562 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007563 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7564 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007565 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007566 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7567 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7568 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007569 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007570 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007571 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007572 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007573#ifdef CONFIG_NET_POLL_CONTROLLER
7574 .ndo_poll_controller = ixgbe_netpoll,
7575#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007576#ifdef IXGBE_FCOE
7577 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007578 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007579 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007580 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7581 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007582 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007583 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007584#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007585 .ndo_set_features = ixgbe_set_features,
7586 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007587};
7588
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007589static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7590 const struct ixgbe_info *ii)
7591{
7592#ifdef CONFIG_PCI_IOV
7593 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007594
Greg Rosec6bda302011-08-24 02:37:55 +00007595 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007596 return;
7597
7598 /* The 82599 supports up to 64 VFs per physical function
7599 * but this implementation limits allocation to 63 so that
7600 * basic networking resources are still available to the
7601 * physical function
7602 */
7603 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007604 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007605#endif /* CONFIG_PCI_IOV */
7606}
7607
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007608/**
Auke Kok9a799d72007-09-15 14:07:45 -07007609 * ixgbe_probe - Device Initialization Routine
7610 * @pdev: PCI device information struct
7611 * @ent: entry in ixgbe_pci_tbl
7612 *
7613 * Returns 0 on success, negative on failure
7614 *
7615 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7616 * The OS initialization, configuring of the adapter private structure,
7617 * and a hardware reset occur.
7618 **/
7619static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007620 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007621{
7622 struct net_device *netdev;
7623 struct ixgbe_adapter *adapter = NULL;
7624 struct ixgbe_hw *hw;
7625 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007626 static int cards_found;
7627 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007628 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007629 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007630#ifdef IXGBE_FCOE
7631 u16 device_caps;
7632#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007633 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007634 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007635
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007636 /* Catch broken hardware that put the wrong VF device ID in
7637 * the PCIe SR-IOV capability.
7638 */
7639 if (pdev->is_virtfn) {
7640 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7641 pci_name(pdev), pdev->vendor, pdev->device);
7642 return -EINVAL;
7643 }
7644
gouji-new9ce77662009-05-06 10:44:45 +00007645 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007646 if (err)
7647 return err;
7648
Nick Nunley1b507732010-04-27 13:10:27 +00007649 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7650 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007651 pci_using_dac = 1;
7652 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007653 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007654 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007655 err = dma_set_coherent_mask(&pdev->dev,
7656 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007657 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007658 dev_err(&pdev->dev,
7659 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007660 goto err_dma;
7661 }
7662 }
7663 pci_using_dac = 0;
7664 }
7665
gouji-new9ce77662009-05-06 10:44:45 +00007666 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007667 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007668 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007669 dev_err(&pdev->dev,
7670 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007671 goto err_pci_reg;
7672 }
7673
Frans Pop19d5afd2009-10-02 10:04:12 -07007674 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007675
Auke Kok9a799d72007-09-15 14:07:45 -07007676 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007677 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007678
John Fastabende901acd2011-04-26 07:26:08 +00007679#ifdef CONFIG_IXGBE_DCB
7680 indices *= MAX_TRAFFIC_CLASS;
7681#endif
7682
John Fastabendc85a2612010-02-25 23:15:21 +00007683 if (ii->mac == ixgbe_mac_82598EB)
7684 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7685 else
7686 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7687
John Fastabende901acd2011-04-26 07:26:08 +00007688#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007689 indices += min_t(unsigned int, num_possible_cpus(),
7690 IXGBE_MAX_FCOE_INDICES);
7691#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007692 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007693 if (!netdev) {
7694 err = -ENOMEM;
7695 goto err_alloc_etherdev;
7696 }
7697
Auke Kok9a799d72007-09-15 14:07:45 -07007698 SET_NETDEV_DEV(netdev, &pdev->dev);
7699
Auke Kok9a799d72007-09-15 14:07:45 -07007700 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007701 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007702
7703 adapter->netdev = netdev;
7704 adapter->pdev = pdev;
7705 hw = &adapter->hw;
7706 hw->back = adapter;
7707 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7708
Jeff Kirsher05857982008-09-11 19:57:00 -07007709 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007710 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007711 if (!hw->hw_addr) {
7712 err = -EIO;
7713 goto err_ioremap;
7714 }
7715
7716 for (i = 1; i <= 5; i++) {
7717 if (pci_resource_len(pdev, i) == 0)
7718 continue;
7719 }
7720
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007721 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007722 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007723 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007724 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007725
Auke Kok9a799d72007-09-15 14:07:45 -07007726 adapter->bd_number = cards_found;
7727
Auke Kok9a799d72007-09-15 14:07:45 -07007728 /* Setup hw api */
7729 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007730 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007731
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007732 /* EEPROM */
7733 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7734 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7735 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7736 if (!(eec & (1 << 8)))
7737 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7738
7739 /* PHY */
7740 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007741 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007742 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7743 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7744 hw->phy.mdio.mmds = 0;
7745 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7746 hw->phy.mdio.dev = netdev;
7747 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7748 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007749
Don Skidmore8ca783a2009-05-26 20:40:47 -07007750 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007751
7752 /* setup the private structure */
7753 err = ixgbe_sw_init(adapter);
7754 if (err)
7755 goto err_sw_init;
7756
Don Skidmoree86bff02010-02-11 04:14:08 +00007757 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007758 switch (adapter->hw.mac.type) {
7759 case ixgbe_mac_82599EB:
7760 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007761 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007762 break;
7763 default:
7764 break;
7765 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007766
Don Skidmorebf069c92009-05-07 10:39:54 +00007767 /*
7768 * If there is a fan on this device and it has failed log the
7769 * failure.
7770 */
7771 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7772 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7773 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007774 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007775 }
7776
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007777 if (allow_unsupported_sfp)
7778 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7779
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007780 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007781 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007782 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007783 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007784 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7785 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007786 err = 0;
7787 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007788 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007789 "module type was detected.\n");
7790 e_dev_err("Reload the driver after installing a supported "
7791 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007792 goto err_sw_init;
7793 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007794 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007795 goto err_sw_init;
7796 }
7797
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007798 ixgbe_probe_vf(adapter, ii);
7799
Emil Tantilov396e7992010-07-01 20:05:12 +00007800 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007801 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007802 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007803 NETIF_F_HW_VLAN_TX |
7804 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007805 NETIF_F_HW_VLAN_FILTER |
7806 NETIF_F_TSO |
7807 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007808 NETIF_F_RXHASH |
7809 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007810
Don Skidmore082757a2011-07-21 05:55:00 +00007811 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007812
Don Skidmore58be7662011-04-12 09:42:11 +00007813 switch (adapter->hw.mac.type) {
7814 case ixgbe_mac_82599EB:
7815 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007816 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007817 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7818 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007819 break;
7820 default:
7821 break;
7822 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007823
Ben Greear3f2d1c02012-03-08 08:28:41 +00007824 netdev->hw_features |= NETIF_F_RXALL;
7825
Jeff Kirsherad31c402008-06-05 04:05:30 -07007826 netdev->vlan_features |= NETIF_F_TSO;
7827 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007828 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007829 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007830 netdev->vlan_features |= NETIF_F_SG;
7831
Jiri Pirko01789342011-08-16 06:29:00 +00007832 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007833 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007834
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007835 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7836 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7837 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007838
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007839#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007840 netdev->dcbnl_ops = &dcbnl_ops;
7841#endif
7842
Yi Zoueacd73f2009-05-13 13:11:06 +00007843#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007844 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007845 if (hw->mac.ops.get_device_caps) {
7846 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007847 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7848 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007849 }
7850 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007851 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7852 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7853 netdev->vlan_features |= NETIF_F_FSO;
7854 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7855 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007856#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007857 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007858 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007859 netdev->vlan_features |= NETIF_F_HIGHDMA;
7860 }
Auke Kok9a799d72007-09-15 14:07:45 -07007861
Don Skidmore082757a2011-07-21 05:55:00 +00007862 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7863 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007864 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007865 netdev->features |= NETIF_F_LRO;
7866
Auke Kok9a799d72007-09-15 14:07:45 -07007867 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007868 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007869 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007870 err = -EIO;
7871 goto err_eeprom;
7872 }
7873
7874 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7875 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7876
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007877 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007878 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007879 err = -EIO;
7880 goto err_eeprom;
7881 }
7882
Alexander Duyck70864002011-04-27 09:13:56 +00007883 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7884 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007885
Alexander Duyck70864002011-04-27 09:13:56 +00007886 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7887 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007888
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007889 err = ixgbe_init_interrupt_scheme(adapter);
7890 if (err)
7891 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007892
Don Skidmore082757a2011-07-21 05:55:00 +00007893 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7894 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007895 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007896 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007897
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007898 /* WOL not supported for all but the following */
7899 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007900 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007901 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007902 /* Only these subdevice supports WOL */
7903 switch (pdev->subsystem_device) {
7904 case IXGBE_SUBDEV_ID_82599_560FLR:
7905 /* only support first port */
7906 if (hw->bus.func != 0)
7907 break;
7908 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007909 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007910 break;
7911 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007912 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007913 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7914 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007915 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007916 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007917 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007918 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007919 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007920 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007921 case IXGBE_DEV_ID_X540T:
7922 /* Check eeprom to see if it is enabled */
7923 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7924 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7925
7926 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7927 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7928 (hw->bus.func == 0)))
7929 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007930 break;
7931 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007932 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7933
Emil Tantilov15e52092011-09-29 05:01:29 +00007934 /* save off EEPROM version number */
7935 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7936 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7937
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007938 /* pick up the PCI bus settings for reporting later */
7939 hw->mac.ops.get_bus_info(hw);
7940
Auke Kok9a799d72007-09-15 14:07:45 -07007941 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007942 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007943 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7944 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007945 "Unknown"),
7946 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7947 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7948 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7949 "Unknown"),
7950 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007951
7952 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7953 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007954 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007955 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007956 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007957 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007958 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007959 else
Don Skidmore289700db2010-12-03 03:32:58 +00007960 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7961 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007962
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007963 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007964 e_dev_warn("PCI-Express bandwidth available for this card is "
7965 "not sufficient for optimal performance.\n");
7966 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7967 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007968 }
7969
Auke Kok9a799d72007-09-15 14:07:45 -07007970 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007971 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007972
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007973 if (err == IXGBE_ERR_EEPROM_VERSION) {
7974 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007975 e_dev_warn("This device is a pre-production adapter/LOM. "
7976 "Please be aware there may be issues associated "
7977 "with your hardware. If you are experiencing "
7978 "problems please contact your Intel or hardware "
7979 "representative who provided you with this "
7980 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007981 }
Auke Kok9a799d72007-09-15 14:07:45 -07007982 strcpy(netdev->name, "eth%d");
7983 err = register_netdev(netdev);
7984 if (err)
7985 goto err_register;
7986
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007987 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7988 if (hw->mac.ops.disable_tx_laser &&
7989 ((hw->phy.multispeed_fiber) ||
7990 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7991 (hw->mac.type == ixgbe_mac_82599EB))))
7992 hw->mac.ops.disable_tx_laser(hw);
7993
Jesse Brandeburg54386462009-04-17 20:44:27 +00007994 /* carrier off reporting is important to ethtool even BEFORE open */
7995 netif_carrier_off(netdev);
7996
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007997#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007998 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007999 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008000 ixgbe_setup_dca(adapter);
8001 }
8002#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008003 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008004 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008005 for (i = 0; i < adapter->num_vfs; i++)
8006 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8007 }
8008
Jacob Keller2466dd92011-09-08 03:50:54 +00008009 /* firmware requires driver version to be 0xFFFFFFFF
8010 * since os does not support feature
8011 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008012 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008013 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8014 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008015
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008016 /* add san mac addr to netdev */
8017 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008018
Neerav Parikhea818752012-01-04 20:23:40 +00008019 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07008020 cards_found++;
8021 return 0;
8022
8023err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008024 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008025 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008026err_sw_init:
8027err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008028 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
8029 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008030 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07008031 iounmap(hw->hw_addr);
8032err_ioremap:
8033 free_netdev(netdev);
8034err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008035 pci_release_selected_regions(pdev,
8036 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008037err_pci_reg:
8038err_dma:
8039 pci_disable_device(pdev);
8040 return err;
8041}
8042
8043/**
8044 * ixgbe_remove - Device Removal Routine
8045 * @pdev: PCI device information struct
8046 *
8047 * ixgbe_remove is called by the PCI subsystem to alert the driver
8048 * that it should release a PCI device. The could be caused by a
8049 * Hot-Plug event, or because the driver is going to be removed from
8050 * memory.
8051 **/
8052static void __devexit ixgbe_remove(struct pci_dev *pdev)
8053{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008054 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8055 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008056
8057 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008058 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008059
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008060#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008061 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8062 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8063 dca_remove_requester(&pdev->dev);
8064 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8065 }
8066
8067#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008068#ifdef IXGBE_FCOE
8069 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8070 ixgbe_cleanup_fcoe(adapter);
8071
8072#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008073
8074 /* remove the added san mac */
8075 ixgbe_del_sanmac_netdev(netdev);
8076
Donald Skidmorec4900be2008-11-20 21:11:42 -08008077 if (netdev->reg_state == NETREG_REGISTERED)
8078 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008079
Greg Rosec6bda302011-08-24 02:37:55 +00008080 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8081 if (!(ixgbe_check_vf_assignment(adapter)))
8082 ixgbe_disable_sriov(adapter);
8083 else
8084 e_dev_warn("Unloading driver while VFs are assigned "
8085 "- VFs will not be deallocated\n");
8086 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008087
Alexander Duyck7a921c92009-05-06 10:43:28 +00008088 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008089
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008090 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008091
8092 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008093 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008094 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008095
Emil Tantilov849c4542010-06-03 16:53:41 +00008096 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008097
Auke Kok9a799d72007-09-15 14:07:45 -07008098 free_netdev(netdev);
8099
Frans Pop19d5afd2009-10-02 10:04:12 -07008100 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008101
Auke Kok9a799d72007-09-15 14:07:45 -07008102 pci_disable_device(pdev);
8103}
8104
8105/**
8106 * ixgbe_io_error_detected - called when PCI error is detected
8107 * @pdev: Pointer to PCI device
8108 * @state: The current pci connection state
8109 *
8110 * This function is called after a PCI bus error affecting
8111 * this device has been detected.
8112 */
8113static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008114 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008115{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008116 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8117 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008118
Greg Rose83c61fa2011-09-07 05:59:35 +00008119#ifdef CONFIG_PCI_IOV
8120 struct pci_dev *bdev, *vfdev;
8121 u32 dw0, dw1, dw2, dw3;
8122 int vf, pos;
8123 u16 req_id, pf_func;
8124
8125 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8126 adapter->num_vfs == 0)
8127 goto skip_bad_vf_detection;
8128
8129 bdev = pdev->bus->self;
8130 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8131 bdev = bdev->bus->self;
8132
8133 if (!bdev)
8134 goto skip_bad_vf_detection;
8135
8136 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8137 if (!pos)
8138 goto skip_bad_vf_detection;
8139
8140 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8141 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8142 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8143 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8144
8145 req_id = dw1 >> 16;
8146 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8147 if (!(req_id & 0x0080))
8148 goto skip_bad_vf_detection;
8149
8150 pf_func = req_id & 0x01;
8151 if ((pf_func & 1) == (pdev->devfn & 1)) {
8152 unsigned int device_id;
8153
8154 vf = (req_id & 0x7F) >> 1;
8155 e_dev_err("VF %d has caused a PCIe error\n", vf);
8156 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8157 "%8.8x\tdw3: %8.8x\n",
8158 dw0, dw1, dw2, dw3);
8159 switch (adapter->hw.mac.type) {
8160 case ixgbe_mac_82599EB:
8161 device_id = IXGBE_82599_VF_DEVICE_ID;
8162 break;
8163 case ixgbe_mac_X540:
8164 device_id = IXGBE_X540_VF_DEVICE_ID;
8165 break;
8166 default:
8167 device_id = 0;
8168 break;
8169 }
8170
8171 /* Find the pci device of the offending VF */
8172 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8173 while (vfdev) {
8174 if (vfdev->devfn == (req_id & 0xFF))
8175 break;
8176 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8177 device_id, vfdev);
8178 }
8179 /*
8180 * There's a slim chance the VF could have been hot plugged,
8181 * so if it is no longer present we don't need to issue the
8182 * VFLR. Just clean up the AER in that case.
8183 */
8184 if (vfdev) {
8185 e_dev_err("Issuing VFLR to VF %d\n", vf);
8186 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8187 }
8188
8189 pci_cleanup_aer_uncorrect_error_status(pdev);
8190 }
8191
8192 /*
8193 * Even though the error may have occurred on the other port
8194 * we still need to increment the vf error reference count for
8195 * both ports because the I/O resume function will be called
8196 * for both of them.
8197 */
8198 adapter->vferr_refcount++;
8199
8200 return PCI_ERS_RESULT_RECOVERED;
8201
8202skip_bad_vf_detection:
8203#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008204 netif_device_detach(netdev);
8205
Breno Leitao3044b8d2009-05-06 10:44:26 +00008206 if (state == pci_channel_io_perm_failure)
8207 return PCI_ERS_RESULT_DISCONNECT;
8208
Auke Kok9a799d72007-09-15 14:07:45 -07008209 if (netif_running(netdev))
8210 ixgbe_down(adapter);
8211 pci_disable_device(pdev);
8212
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008213 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008214 return PCI_ERS_RESULT_NEED_RESET;
8215}
8216
8217/**
8218 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8219 * @pdev: Pointer to PCI device
8220 *
8221 * Restart the card from scratch, as if from a cold-boot.
8222 */
8223static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8224{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008225 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008226 pci_ers_result_t result;
8227 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008228
gouji-new9ce77662009-05-06 10:44:45 +00008229 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008230 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008231 result = PCI_ERS_RESULT_DISCONNECT;
8232 } else {
8233 pci_set_master(pdev);
8234 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008235 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008236
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008237 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008238
8239 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008240 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008241 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008242 }
Auke Kok9a799d72007-09-15 14:07:45 -07008243
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008244 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8245 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008246 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8247 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008248 /* non-fatal, continue */
8249 }
Auke Kok9a799d72007-09-15 14:07:45 -07008250
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008251 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008252}
8253
8254/**
8255 * ixgbe_io_resume - called when traffic can start flowing again.
8256 * @pdev: Pointer to PCI device
8257 *
8258 * This callback is called when the error recovery driver tells us that
8259 * its OK to resume normal operation.
8260 */
8261static void ixgbe_io_resume(struct pci_dev *pdev)
8262{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008263 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8264 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008265
Greg Rose83c61fa2011-09-07 05:59:35 +00008266#ifdef CONFIG_PCI_IOV
8267 if (adapter->vferr_refcount) {
8268 e_info(drv, "Resuming after VF err\n");
8269 adapter->vferr_refcount--;
8270 return;
8271 }
8272
8273#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008274 if (netif_running(netdev))
8275 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008276
8277 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008278}
8279
8280static struct pci_error_handlers ixgbe_err_handler = {
8281 .error_detected = ixgbe_io_error_detected,
8282 .slot_reset = ixgbe_io_slot_reset,
8283 .resume = ixgbe_io_resume,
8284};
8285
8286static struct pci_driver ixgbe_driver = {
8287 .name = ixgbe_driver_name,
8288 .id_table = ixgbe_pci_tbl,
8289 .probe = ixgbe_probe,
8290 .remove = __devexit_p(ixgbe_remove),
8291#ifdef CONFIG_PM
8292 .suspend = ixgbe_suspend,
8293 .resume = ixgbe_resume,
8294#endif
8295 .shutdown = ixgbe_shutdown,
8296 .err_handler = &ixgbe_err_handler
8297};
8298
8299/**
8300 * ixgbe_init_module - Driver Registration Routine
8301 *
8302 * ixgbe_init_module is the first routine called when the driver is
8303 * loaded. All it does is register with the PCI subsystem.
8304 **/
8305static int __init ixgbe_init_module(void)
8306{
8307 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008308 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008309 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008310
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008311#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008312 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008313#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008314
Auke Kok9a799d72007-09-15 14:07:45 -07008315 ret = pci_register_driver(&ixgbe_driver);
8316 return ret;
8317}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008318
Auke Kok9a799d72007-09-15 14:07:45 -07008319module_init(ixgbe_init_module);
8320
8321/**
8322 * ixgbe_exit_module - Driver Exit Cleanup Routine
8323 *
8324 * ixgbe_exit_module is called just before the driver is removed
8325 * from memory.
8326 **/
8327static void __exit ixgbe_exit_module(void)
8328{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008329#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008330 dca_unregister_notify(&dca_notifier);
8331#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008332 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008333 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008334}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008335
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008336#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008337static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008338 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008339{
8340 int ret_val;
8341
8342 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008343 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008344
8345 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8346}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008347
Alexander Duyckb4533682009-03-31 21:32:42 +00008348#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008349
Auke Kok9a799d72007-09-15 14:07:45 -07008350module_exit(ixgbe_exit_module);
8351
8352/* ixgbe_main.c */