blob: efce423586d496ed9a689e4c548c921ebfa20aca [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{
664 return ring->tx_stats.completed;
665}
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
763 /* count the packet as being completed */
764 tx_ring->tx_stats.completed++;
765
766 /* clear next_to_watch to prevent false hangs */
767 tx_buffer->next_to_watch = NULL;
768
Alexander Duyckd3d00232011-07-15 02:31:25 +0000769 do {
770 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000771 if (likely(tx_desc == eop_desc)) {
772 eop_desc = NULL;
773 dev_kfree_skb_any(tx_buffer->skb);
774 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800775
Alexander Duyckd3d00232011-07-15 02:31:25 +0000776 total_bytes += tx_buffer->bytecount;
777 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800778 }
779
Alexander Duyckd3d00232011-07-15 02:31:25 +0000780 tx_buffer++;
781 tx_desc++;
782 i++;
783 if (unlikely(i == tx_ring->count)) {
784 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700785
Alexander Duyckd3d00232011-07-15 02:31:25 +0000786 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000787 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000788 }
789
790 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800791 }
792
Auke Kok9a799d72007-09-15 14:07:45 -0700793 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000794 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800795 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000796 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000797 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000798 q_vector->tx.total_bytes += total_bytes;
799 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800800
John Fastabendc84d3242010-11-16 19:27:12 -0800801 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800802 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800803 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycke4f74022012-01-31 02:59:44 +0000804 tx_desc = IXGBE_TX_DESC(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800805 e_err(drv, "Detected Tx Unit Hang\n"
806 " Tx Queue <%d>\n"
807 " TDH, TDT <%x>, <%x>\n"
808 " next_to_use <%x>\n"
809 " next_to_clean <%x>\n"
810 "tx_buffer_info[next_to_clean]\n"
811 " time_stamp <%lx>\n"
812 " jiffies <%lx>\n",
813 tx_ring->queue_index,
814 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
815 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000816 tx_ring->next_to_use, i,
817 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800818
819 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
820
821 e_info(probe,
822 "tx hang %d detected on queue %d, resetting adapter\n",
823 adapter->tx_timeout_count + 1, tx_ring->queue_index);
824
825 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000826 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800827
828 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000829 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800830 }
Auke Kok9a799d72007-09-15 14:07:45 -0700831
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000832 netdev_tx_completed_queue(txring_txq(tx_ring),
833 total_packets, total_bytes);
834
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800835#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000836 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000837 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800838 /* Make sure that anybody stopping the queue after this
839 * sees the new next_to_clean.
840 */
841 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800842 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800843 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800844 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800845 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800846 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800847 }
Auke Kok9a799d72007-09-15 14:07:45 -0700848
Alexander Duyck59224552011-08-31 00:01:06 +0000849 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700850}
851
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400852#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800853static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800854 struct ixgbe_ring *tx_ring,
855 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800856{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000857 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000858 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
859 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800860
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800861 switch (hw->mac.type) {
862 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000863 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800864 break;
865 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800866 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000867 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
868 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
869 break;
870 default:
871 /* for unknown hardware do not write register */
872 return;
873 }
874
875 /*
876 * We can enable relaxed ordering for reads, but not writes when
877 * DCA is enabled. This is due to a known issue in some chipsets
878 * which will cause the DCA tag to be cleared.
879 */
880 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
881 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
882 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
883
884 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
885}
886
887static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
888 struct ixgbe_ring *rx_ring,
889 int cpu)
890{
891 struct ixgbe_hw *hw = &adapter->hw;
892 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
893 u8 reg_idx = rx_ring->reg_idx;
894
895
896 switch (hw->mac.type) {
897 case ixgbe_mac_82599EB:
898 case ixgbe_mac_X540:
899 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800900 break;
901 default:
902 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800903 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000904
905 /*
906 * We can enable relaxed ordering for reads, but not writes when
907 * DCA is enabled. This is due to a known issue in some chipsets
908 * which will cause the DCA tag to be cleared.
909 */
910 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
911 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
912 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
913
914 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800915}
916
917static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
918{
919 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000920 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800921 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800922
923 if (q_vector->cpu == cpu)
924 goto out_no_update;
925
Alexander Duycka5579282012-02-08 07:50:04 +0000926 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000927 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800928
Alexander Duycka5579282012-02-08 07:50:04 +0000929 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000930 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931
932 q_vector->cpu = cpu;
933out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800934 put_cpu();
935}
936
937static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
938{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800939 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800940 int i;
941
942 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
943 return;
944
Alexander Duycke35ec122009-05-21 13:07:12 +0000945 /* always use CB2 mode, difference is masked in the CB driver */
946 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
947
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800948 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
949 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
950 else
951 num_q_vectors = 1;
952
953 for (i = 0; i < num_q_vectors; i++) {
954 adapter->q_vector[i]->cpu = -1;
955 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800956 }
957}
958
959static int __ixgbe_notify_dca(struct device *dev, void *data)
960{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800961 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800962 unsigned long event = *(unsigned long *)data;
963
Don Skidmore2a72c312011-07-20 02:27:05 +0000964 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800965 return 0;
966
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800967 switch (event) {
968 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700969 /* if we're already enabled, don't do it again */
970 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
971 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300972 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700973 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800974 ixgbe_setup_dca(adapter);
975 break;
976 }
977 /* Fall Through since DCA is disabled. */
978 case DCA_PROVIDER_REMOVE:
979 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
980 dca_remove_requester(dev);
981 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
982 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
983 }
984 break;
985 }
986
Denis V. Lunev652f0932008-03-27 14:39:17 +0300987 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800988}
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000989
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000990#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +0000991static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
992 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000993 struct sk_buff *skb)
994{
Alexander Duyck8a0da212012-01-31 02:59:49 +0000995 if (ring->netdev->features & NETIF_F_RXHASH)
996 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000997}
998
Alexander Duyckf8003262012-03-03 02:35:52 +0000999#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001000/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001001 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1002 * @adapter: address of board private structure
1003 * @rx_desc: advanced rx descriptor
1004 *
1005 * Returns : true if it is FCoE pkt
1006 */
1007static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1008 union ixgbe_adv_rx_desc *rx_desc)
1009{
1010 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1011
1012 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1013 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1014 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1015 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1016}
1017
Alexander Duyckf8003262012-03-03 02:35:52 +00001018#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001019/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001020 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001021 * @ring: structure containing ring specific data
1022 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001023 * @skb: skb currently being received and modified
1024 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001025static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001026 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001027 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001028{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001029 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001030
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001031 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001032 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001033 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001034
1035 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001036 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1037 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001038 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001039 return;
1040 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001041
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001042 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001043 return;
1044
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001045 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001046 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001047
1048 /*
1049 * 82599 errata, UDP frames with a 0 checksum can be marked as
1050 * checksum errors.
1051 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001052 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1053 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001054 return;
1055
Alexander Duyck8a0da212012-01-31 02:59:49 +00001056 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001057 return;
1058 }
1059
Auke Kok9a799d72007-09-15 14:07:45 -07001060 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001061 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001062}
1063
Alexander Duyck84ea2592010-11-16 19:26:49 -08001064static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001065{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001066 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001067
1068 /* update next to alloc since we have filled the ring */
1069 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001070 /*
1071 * Force memory writes to complete before letting h/w
1072 * know there are new descriptors to fetch. (Only
1073 * applicable for weak-ordered memory model archs,
1074 * such as IA-64).
1075 */
1076 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001077 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001078}
1079
Alexander Duyckf990b792012-01-31 02:59:34 +00001080static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1081 struct ixgbe_rx_buffer *bi)
1082{
1083 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001084 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001085
Alexander Duyckf8003262012-03-03 02:35:52 +00001086 /* since we are recycling buffers we should seldom need to alloc */
1087 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001088 return true;
1089
Alexander Duyckf8003262012-03-03 02:35:52 +00001090 /* alloc new page for storage */
1091 if (likely(!page)) {
1092 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1093 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001094 if (unlikely(!page)) {
1095 rx_ring->rx_stats.alloc_rx_page_failed++;
1096 return false;
1097 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001098 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001099 }
1100
Alexander Duyckf8003262012-03-03 02:35:52 +00001101 /* map page for use */
1102 dma = dma_map_page(rx_ring->dev, page, 0,
1103 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001104
Alexander Duyckf8003262012-03-03 02:35:52 +00001105 /*
1106 * if mapping failed free memory back to system since
1107 * there isn't much point in holding memory we can't use
1108 */
1109 if (dma_mapping_error(rx_ring->dev, dma)) {
1110 put_page(page);
1111 bi->page = NULL;
1112
Alexander Duyckf990b792012-01-31 02:59:34 +00001113 rx_ring->rx_stats.alloc_rx_page_failed++;
1114 return false;
1115 }
1116
Alexander Duyckf8003262012-03-03 02:35:52 +00001117 bi->dma = dma;
1118 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1119
Alexander Duyckf990b792012-01-31 02:59:34 +00001120 return true;
1121}
1122
Auke Kok9a799d72007-09-15 14:07:45 -07001123/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001124 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001125 * @rx_ring: ring to place buffers on
1126 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001127 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001128void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001129{
Auke Kok9a799d72007-09-15 14:07:45 -07001130 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001131 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001132 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001133
Alexander Duyckf8003262012-03-03 02:35:52 +00001134 /* nothing to do */
1135 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001136 return;
1137
Alexander Duycke4f74022012-01-31 02:59:44 +00001138 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001139 bi = &rx_ring->rx_buffer_info[i];
1140 i -= rx_ring->count;
1141
Alexander Duyckf8003262012-03-03 02:35:52 +00001142 do {
1143 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001144 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001145
Alexander Duyckf8003262012-03-03 02:35:52 +00001146 /*
1147 * Refresh the desc even if buffer_addrs didn't change
1148 * because each write-back erases this info.
1149 */
1150 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001151
Alexander Duyckf990b792012-01-31 02:59:34 +00001152 rx_desc++;
1153 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001154 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001155 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001156 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001157 bi = rx_ring->rx_buffer_info;
1158 i -= rx_ring->count;
1159 }
1160
1161 /* clear the hdr_addr for the next_to_use descriptor */
1162 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001163
1164 cleaned_count--;
1165 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001166
Alexander Duyckf990b792012-01-31 02:59:34 +00001167 i += rx_ring->count;
1168
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001169 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001170 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001171}
1172
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001173/**
1174 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1175 * @data: pointer to the start of the headers
1176 * @max_len: total length of section to find headers in
1177 *
1178 * This function is meant to determine the length of headers that will
1179 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1180 * motivation of doing this is to only perform one pull for IPv4 TCP
1181 * packets so that we can do basic things like calculating the gso_size
1182 * based on the average data per packet.
1183 **/
1184static unsigned int ixgbe_get_headlen(unsigned char *data,
1185 unsigned int max_len)
1186{
1187 union {
1188 unsigned char *network;
1189 /* l2 headers */
1190 struct ethhdr *eth;
1191 struct vlan_hdr *vlan;
1192 /* l3 headers */
1193 struct iphdr *ipv4;
1194 } hdr;
1195 __be16 protocol;
1196 u8 nexthdr = 0; /* default to not TCP */
1197 u8 hlen;
1198
1199 /* this should never happen, but better safe than sorry */
1200 if (max_len < ETH_HLEN)
1201 return max_len;
1202
1203 /* initialize network frame pointer */
1204 hdr.network = data;
1205
1206 /* set first protocol and move network header forward */
1207 protocol = hdr.eth->h_proto;
1208 hdr.network += ETH_HLEN;
1209
1210 /* handle any vlan tag if present */
1211 if (protocol == __constant_htons(ETH_P_8021Q)) {
1212 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1213 return max_len;
1214
1215 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1216 hdr.network += VLAN_HLEN;
1217 }
1218
1219 /* handle L3 protocols */
1220 if (protocol == __constant_htons(ETH_P_IP)) {
1221 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1222 return max_len;
1223
1224 /* access ihl as a u8 to avoid unaligned access on ia64 */
1225 hlen = (hdr.network[0] & 0x0F) << 2;
1226
1227 /* verify hlen meets minimum size requirements */
1228 if (hlen < sizeof(struct iphdr))
1229 return hdr.network - data;
1230
1231 /* record next protocol */
1232 nexthdr = hdr.ipv4->protocol;
1233 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001234#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001235 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1236 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1237 return max_len;
1238 hdr.network += FCOE_HEADER_LEN;
1239#endif
1240 } else {
1241 return hdr.network - data;
1242 }
1243
1244 /* finally sort out TCP */
1245 if (nexthdr == IPPROTO_TCP) {
1246 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1247 return max_len;
1248
1249 /* access doff as a u8 to avoid unaligned access on ia64 */
1250 hlen = (hdr.network[12] & 0xF0) >> 2;
1251
1252 /* verify hlen meets minimum size requirements */
1253 if (hlen < sizeof(struct tcphdr))
1254 return hdr.network - data;
1255
1256 hdr.network += hlen;
1257 }
1258
1259 /*
1260 * If everything has gone correctly hdr.network should be the
1261 * data section of the packet and will be the end of the header.
1262 * If not then it probably represents the end of the last recognized
1263 * header.
1264 */
1265 if ((hdr.network - data) < max_len)
1266 return hdr.network - data;
1267 else
1268 return max_len;
1269}
1270
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001271static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1272 union ixgbe_adv_rx_desc *rx_desc,
1273 struct sk_buff *skb)
1274{
1275 __le32 rsc_enabled;
1276 u32 rsc_cnt;
1277
1278 if (!ring_is_rsc_enabled(rx_ring))
1279 return;
1280
1281 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1282 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1283
1284 /* If this is an RSC frame rsc_cnt should be non-zero */
1285 if (!rsc_enabled)
1286 return;
1287
1288 rsc_cnt = le32_to_cpu(rsc_enabled);
1289 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1290
1291 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001292}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001293
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001294static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1295 struct sk_buff *skb)
1296{
Alexander Duyckf8003262012-03-03 02:35:52 +00001297 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001298
1299 /* set gso_size to avoid messing up TCP MSS */
1300 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1301 IXGBE_CB(skb)->append_cnt);
1302}
1303
1304static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1305 struct sk_buff *skb)
1306{
1307 /* if append_cnt is 0 then frame is not RSC */
1308 if (!IXGBE_CB(skb)->append_cnt)
1309 return;
1310
1311 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1312 rx_ring->rx_stats.rsc_flush++;
1313
1314 ixgbe_set_rsc_gso_size(rx_ring, skb);
1315
1316 /* gso_size is computed using append_cnt so always clear it last */
1317 IXGBE_CB(skb)->append_cnt = 0;
1318}
1319
Alexander Duyck8a0da212012-01-31 02:59:49 +00001320/**
1321 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1322 * @rx_ring: rx descriptor ring packet is being transacted on
1323 * @rx_desc: pointer to the EOP Rx descriptor
1324 * @skb: pointer to current skb being populated
1325 *
1326 * This function checks the ring, descriptor, and packet information in
1327 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1328 * other fields within the skb.
1329 **/
1330static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1331 union ixgbe_adv_rx_desc *rx_desc,
1332 struct sk_buff *skb)
1333{
1334 ixgbe_update_rsc_stats(rx_ring, skb);
1335
1336 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1337
1338 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1339
1340 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1341 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1342 __vlan_hwaccel_put_tag(skb, vid);
1343 }
1344
1345 skb_record_rx_queue(skb, rx_ring->queue_index);
1346
1347 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1348}
1349
1350static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1351 struct sk_buff *skb)
1352{
1353 struct ixgbe_adapter *adapter = q_vector->adapter;
1354
1355 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1356 napi_gro_receive(&q_vector->napi, skb);
1357 else
1358 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001359}
1360
Alexander Duyckf8003262012-03-03 02:35:52 +00001361/**
1362 * ixgbe_is_non_eop - process handling of non-EOP buffers
1363 * @rx_ring: Rx ring being processed
1364 * @rx_desc: Rx descriptor for current buffer
1365 * @skb: Current socket buffer containing buffer in progress
1366 *
1367 * This function updates next to clean. If the buffer is an EOP buffer
1368 * this function exits returning false, otherwise it will place the
1369 * sk_buff in the next buffer to be chained and return true indicating
1370 * that this is in fact a non-EOP buffer.
1371 **/
1372static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1373 union ixgbe_adv_rx_desc *rx_desc,
1374 struct sk_buff *skb)
1375{
1376 u32 ntc = rx_ring->next_to_clean + 1;
1377
1378 /* fetch, update, and store next to clean */
1379 ntc = (ntc < rx_ring->count) ? ntc : 0;
1380 rx_ring->next_to_clean = ntc;
1381
1382 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1383
1384 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1385 return false;
1386
1387 /* append_cnt indicates packet is RSC, if so fetch nextp */
1388 if (IXGBE_CB(skb)->append_cnt) {
1389 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1390 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1391 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1392 }
1393
1394 /* place skb in next buffer to be received */
1395 rx_ring->rx_buffer_info[ntc].skb = skb;
1396 rx_ring->rx_stats.non_eop_descs++;
1397
1398 return true;
1399}
1400
1401/**
1402 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1403 * @rx_ring: rx descriptor ring packet is being transacted on
1404 * @rx_desc: pointer to the EOP Rx descriptor
1405 * @skb: pointer to current skb being fixed
1406 *
1407 * Check for corrupted packet headers caused by senders on the local L2
1408 * embedded NIC switch not setting up their Tx Descriptors right. These
1409 * should be very rare.
1410 *
1411 * Also address the case where we are pulling data in on pages only
1412 * and as such no data is present in the skb header.
1413 *
1414 * In addition if skb is not at least 60 bytes we need to pad it so that
1415 * it is large enough to qualify as a valid Ethernet frame.
1416 *
1417 * Returns true if an error was encountered and skb was freed.
1418 **/
1419static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1420 union ixgbe_adv_rx_desc *rx_desc,
1421 struct sk_buff *skb)
1422{
1423 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1424 struct net_device *netdev = rx_ring->netdev;
1425 unsigned char *va;
1426 unsigned int pull_len;
1427
1428 /* if the page was released unmap it, else just sync our portion */
1429 if (unlikely(IXGBE_CB(skb)->page_released)) {
1430 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1431 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1432 IXGBE_CB(skb)->page_released = false;
1433 } else {
1434 dma_sync_single_range_for_cpu(rx_ring->dev,
1435 IXGBE_CB(skb)->dma,
1436 frag->page_offset,
1437 ixgbe_rx_bufsz(rx_ring),
1438 DMA_FROM_DEVICE);
1439 }
1440 IXGBE_CB(skb)->dma = 0;
1441
1442 /* verify that the packet does not have any known errors */
1443 if (unlikely(ixgbe_test_staterr(rx_desc,
1444 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1445 !(netdev->features & NETIF_F_RXALL))) {
1446 dev_kfree_skb_any(skb);
1447 return true;
1448 }
1449
1450 /*
1451 * it is valid to use page_address instead of kmap since we are
1452 * working with pages allocated out of the lomem pool per
1453 * alloc_page(GFP_ATOMIC)
1454 */
1455 va = skb_frag_address(frag);
1456
1457 /*
1458 * we need the header to contain the greater of either ETH_HLEN or
1459 * 60 bytes if the skb->len is less than 60 for skb_pad.
1460 */
1461 pull_len = skb_frag_size(frag);
1462 if (pull_len > 256)
1463 pull_len = ixgbe_get_headlen(va, pull_len);
1464
1465 /* align pull length to size of long to optimize memcpy performance */
1466 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1467
1468 /* update all of the pointers */
1469 skb_frag_size_sub(frag, pull_len);
1470 frag->page_offset += pull_len;
1471 skb->data_len -= pull_len;
1472 skb->tail += pull_len;
1473
1474 /*
1475 * if we sucked the frag empty then we should free it,
1476 * if there are other frags here something is screwed up in hardware
1477 */
1478 if (skb_frag_size(frag) == 0) {
1479 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1480 skb_shinfo(skb)->nr_frags = 0;
1481 __skb_frag_unref(frag);
1482 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1483 }
1484
1485 /* if skb_pad returns an error the skb was freed */
1486 if (unlikely(skb->len < 60)) {
1487 int pad_len = 60 - skb->len;
1488
1489 if (skb_pad(skb, pad_len))
1490 return true;
1491 __skb_put(skb, pad_len);
1492 }
1493
1494 return false;
1495}
1496
1497/**
1498 * ixgbe_can_reuse_page - determine if we can reuse a page
1499 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1500 *
1501 * Returns true if page can be reused in another Rx buffer
1502 **/
1503static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1504{
1505 struct page *page = rx_buffer->page;
1506
1507 /* if we are only owner of page and it is local we can reuse it */
1508 return likely(page_count(page) == 1) &&
1509 likely(page_to_nid(page) == numa_node_id());
1510}
1511
1512/**
1513 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1514 * @rx_ring: rx descriptor ring to store buffers on
1515 * @old_buff: donor buffer to have page reused
1516 *
1517 * Syncronizes page for reuse by the adapter
1518 **/
1519static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1520 struct ixgbe_rx_buffer *old_buff)
1521{
1522 struct ixgbe_rx_buffer *new_buff;
1523 u16 nta = rx_ring->next_to_alloc;
1524 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1525
1526 new_buff = &rx_ring->rx_buffer_info[nta];
1527
1528 /* update, and store next to alloc */
1529 nta++;
1530 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1531
1532 /* transfer page from old buffer to new buffer */
1533 new_buff->page = old_buff->page;
1534 new_buff->dma = old_buff->dma;
1535
1536 /* flip page offset to other buffer and store to new_buff */
1537 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1538
1539 /* sync the buffer for use by the device */
1540 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1541 new_buff->page_offset, bufsz,
1542 DMA_FROM_DEVICE);
1543
1544 /* bump ref count on page before it is given to the stack */
1545 get_page(new_buff->page);
1546}
1547
1548/**
1549 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1550 * @rx_ring: rx descriptor ring to transact packets on
1551 * @rx_buffer: buffer containing page to add
1552 * @rx_desc: descriptor containing length of buffer written by hardware
1553 * @skb: sk_buff to place the data into
1554 *
1555 * This function is based on skb_add_rx_frag. I would have used that
1556 * function however it doesn't handle the truesize case correctly since we
1557 * are allocating more memory than might be used for a single receive.
1558 **/
1559static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1560 struct ixgbe_rx_buffer *rx_buffer,
1561 struct sk_buff *skb, int size)
1562{
1563 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1564 rx_buffer->page, rx_buffer->page_offset,
1565 size);
1566 skb->len += size;
1567 skb->data_len += size;
1568 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1569}
1570
1571/**
1572 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1573 * @q_vector: structure containing interrupt and ring information
1574 * @rx_ring: rx descriptor ring to transact packets on
1575 * @budget: Total limit on number of packets to process
1576 *
1577 * This function provides a "bounce buffer" approach to Rx interrupt
1578 * processing. The advantage to this is that on systems that have
1579 * expensive overhead for IOMMU access this provides a means of avoiding
1580 * it by maintaining the mapping of the page to the syste.
1581 *
1582 * Returns true if all work is completed without reaching budget
1583 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001584static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001585 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001586 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001587{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001588 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001589#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001590 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001591 int ddp_bytes = 0;
1592#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001593 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001594
Alexander Duyckf8003262012-03-03 02:35:52 +00001595 do {
1596 struct ixgbe_rx_buffer *rx_buffer;
1597 union ixgbe_adv_rx_desc *rx_desc;
1598 struct sk_buff *skb;
1599 struct page *page;
1600 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001601
Alexander Duyckf8003262012-03-03 02:35:52 +00001602 /* return some buffers to hardware, one at a time is too slow */
1603 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1604 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1605 cleaned_count = 0;
1606 }
Auke Kok9a799d72007-09-15 14:07:45 -07001607
Alexander Duyckf8003262012-03-03 02:35:52 +00001608 ntc = rx_ring->next_to_clean;
1609 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1610 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001611
Alexander Duyckf8003262012-03-03 02:35:52 +00001612 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1613 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001614
Alexander Duyckf8003262012-03-03 02:35:52 +00001615 /*
1616 * This memory barrier is needed to keep us from reading
1617 * any other fields out of the rx_desc until we know the
1618 * RXD_STAT_DD bit is set
1619 */
1620 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001621
Alexander Duyckf8003262012-03-03 02:35:52 +00001622 page = rx_buffer->page;
1623 prefetchw(page);
1624
1625 skb = rx_buffer->skb;
1626
1627 if (likely(!skb)) {
1628 void *page_addr = page_address(page) +
1629 rx_buffer->page_offset;
1630
1631 /* prefetch first cache line of first page */
1632 prefetch(page_addr);
1633#if L1_CACHE_BYTES < 128
1634 prefetch(page_addr + L1_CACHE_BYTES);
1635#endif
1636
1637 /* allocate a skb to store the frags */
1638 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1639 IXGBE_RX_HDR_SIZE);
1640 if (unlikely(!skb)) {
1641 rx_ring->rx_stats.alloc_rx_buff_failed++;
1642 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001643 }
1644
Alexander Duyckf8003262012-03-03 02:35:52 +00001645 /*
1646 * we will be copying header into skb->data in
1647 * pskb_may_pull so it is in our interest to prefetch
1648 * it now to avoid a possible cache miss
1649 */
1650 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001651
1652 /*
1653 * Delay unmapping of the first packet. It carries the
1654 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001655 * after the writeback. Only unmap it when EOP is
1656 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001657 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001658 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001659 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001660 /* we are reusing so sync this buffer for CPU use */
1661 dma_sync_single_range_for_cpu(rx_ring->dev,
1662 rx_buffer->dma,
1663 rx_buffer->page_offset,
1664 ixgbe_rx_bufsz(rx_ring),
1665 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001666 }
1667
Alexander Duyckf8003262012-03-03 02:35:52 +00001668 /* pull page into skb */
1669 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1670 le16_to_cpu(rx_desc->wb.upper.length));
1671
1672 if (ixgbe_can_reuse_page(rx_buffer)) {
1673 /* hand second half of page back to the ring */
1674 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1675 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1676 /* the page has been released from the ring */
1677 IXGBE_CB(skb)->page_released = true;
1678 } else {
1679 /* we are not reusing the buffer so unmap it */
1680 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1681 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001682 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001683 }
1684
Alexander Duyckf8003262012-03-03 02:35:52 +00001685 /* clear contents of buffer_info */
1686 rx_buffer->skb = NULL;
1687 rx_buffer->dma = 0;
1688 rx_buffer->page = NULL;
1689
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001690 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1691
Auke Kok9a799d72007-09-15 14:07:45 -07001692 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001693
Alexander Duyckf8003262012-03-03 02:35:52 +00001694 /* place incomplete frames back on ring for completion */
1695 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1696 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001697
Alexander Duyckf8003262012-03-03 02:35:52 +00001698 /* verify the packet layout is correct */
1699 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1700 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001701
1702 /* probably a little skewed due to removing CRC */
1703 total_rx_bytes += skb->len;
1704 total_rx_packets++;
1705
Alexander Duyck8a0da212012-01-31 02:59:49 +00001706 /* populate checksum, timestamp, VLAN, and protocol */
1707 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1708
Yi Zou332d4a72009-05-13 13:11:53 +00001709#ifdef IXGBE_FCOE
1710 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001711 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001712 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001713 if (!ddp_bytes) {
1714 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001715 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001716 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001717 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001718
Yi Zou332d4a72009-05-13 13:11:53 +00001719#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001720 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001721
Alexander Duyckf8003262012-03-03 02:35:52 +00001722 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001723 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001724 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001725
Yi Zou3d8fd382009-06-08 14:38:44 +00001726#ifdef IXGBE_FCOE
1727 /* include DDPed FCoE data */
1728 if (ddp_bytes > 0) {
1729 unsigned int mss;
1730
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001731 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001732 sizeof(struct fc_frame_header) -
1733 sizeof(struct fcoe_crc_eof);
1734 if (mss > 512)
1735 mss &= ~511;
1736 total_rx_bytes += ddp_bytes;
1737 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1738 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001739
Alexander Duyckf8003262012-03-03 02:35:52 +00001740#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001741 u64_stats_update_begin(&rx_ring->syncp);
1742 rx_ring->stats.packets += total_rx_packets;
1743 rx_ring->stats.bytes += total_rx_bytes;
1744 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001745 q_vector->rx.total_packets += total_rx_packets;
1746 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001747
Alexander Duyckf8003262012-03-03 02:35:52 +00001748 if (cleaned_count)
1749 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1750
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001751 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001752}
1753
Auke Kok9a799d72007-09-15 14:07:45 -07001754/**
1755 * ixgbe_configure_msix - Configure MSI-X hardware
1756 * @adapter: board private structure
1757 *
1758 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1759 * interrupts.
1760 **/
1761static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1762{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001763 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001764 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001765 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001766
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001767 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1768
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001769 /* Populate MSIX to EITR Select */
1770 if (adapter->num_vfs > 32) {
1771 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1772 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1773 }
1774
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001775 /*
1776 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001777 * corresponding register.
1778 */
1779 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001780 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001781 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001782
Alexander Duycka5579282012-02-08 07:50:04 +00001783 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001784 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001785
Alexander Duycka5579282012-02-08 07:50:04 +00001786 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001787 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001788
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001789 if (q_vector->tx.ring && !q_vector->rx.ring) {
1790 /* tx only vector */
1791 if (adapter->tx_itr_setting == 1)
1792 q_vector->itr = IXGBE_10K_ITR;
1793 else
1794 q_vector->itr = adapter->tx_itr_setting;
1795 } else {
1796 /* rx or rx/tx vector */
1797 if (adapter->rx_itr_setting == 1)
1798 q_vector->itr = IXGBE_20K_ITR;
1799 else
1800 q_vector->itr = adapter->rx_itr_setting;
1801 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001802
Alexander Duyckfe49f042009-06-04 16:00:09 +00001803 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001804 }
1805
Alexander Duyckbd508172010-11-16 19:27:03 -08001806 switch (adapter->hw.mac.type) {
1807 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001808 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001809 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001810 break;
1811 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001812 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001813 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001814 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001815 default:
1816 break;
1817 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001818 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001819
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001820 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001821 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001822 mask &= ~(IXGBE_EIMS_OTHER |
1823 IXGBE_EIMS_MAILBOX |
1824 IXGBE_EIMS_LSC);
1825
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001827}
1828
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001829enum latency_range {
1830 lowest_latency = 0,
1831 low_latency = 1,
1832 bulk_latency = 2,
1833 latency_invalid = 255
1834};
1835
1836/**
1837 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001838 * @q_vector: structure containing interrupt and ring information
1839 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001840 *
1841 * Stores a new ITR value based on packets and byte
1842 * counts during the last interrupt. The advantage of per interrupt
1843 * computation is faster updates and more accurate ITR for the current
1844 * traffic pattern. Constants in this function were computed
1845 * based on theoretical maximum wire speed and thresholds were set based
1846 * on testing data as well as attempting to minimize response time
1847 * while increasing bulk throughput.
1848 * this functionality is controlled by the InterruptThrottleRate module
1849 * parameter (see ixgbe_param.c)
1850 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001851static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1852 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001853{
Alexander Duyckbd198052011-06-11 01:45:08 +00001854 int bytes = ring_container->total_bytes;
1855 int packets = ring_container->total_packets;
1856 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001857 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001858 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001859
1860 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001861 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001862
1863 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001864 * 0-10MB/s lowest (100000 ints/s)
1865 * 10-20MB/s low (20000 ints/s)
1866 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001867 */
1868 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001869 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001870 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1871
1872 switch (itr_setting) {
1873 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001874 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001875 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001876 break;
1877 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001878 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001879 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001880 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001881 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001882 break;
1883 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001884 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001885 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001886 break;
1887 }
1888
Alexander Duyckbd198052011-06-11 01:45:08 +00001889 /* clear work counters since we have the values we need */
1890 ring_container->total_bytes = 0;
1891 ring_container->total_packets = 0;
1892
1893 /* write updated itr to ring container */
1894 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001895}
1896
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001897/**
1898 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001899 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001900 *
1901 * This function is made to be called by ethtool and by the driver
1902 * when it needs to update EITR registers at runtime. Hardware
1903 * specific quirks/differences are taken care of here.
1904 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001905void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001906{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001907 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001908 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001909 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001910 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001911
Alexander Duyckbd508172010-11-16 19:27:03 -08001912 switch (adapter->hw.mac.type) {
1913 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001914 /* must write high and low 16 bits to reset counter */
1915 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001916 break;
1917 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001918 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001919 /*
1920 * set the WDIS bit to not clear the timer bits and cause an
1921 * immediate assertion of the interrupt
1922 */
1923 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001924 break;
1925 default:
1926 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001927 }
1928 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1929}
1930
Alexander Duyckbd198052011-06-11 01:45:08 +00001931static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001932{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001933 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001934 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001935
Alexander Duyckbd198052011-06-11 01:45:08 +00001936 ixgbe_update_itr(q_vector, &q_vector->tx);
1937 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001938
Alexander Duyck08c88332011-06-11 01:45:03 +00001939 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001940
1941 switch (current_itr) {
1942 /* counts and packets in update_itr are dependent on these numbers */
1943 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001944 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001945 break;
1946 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001947 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001948 break;
1949 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001950 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001951 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001952 default:
1953 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001954 }
1955
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001956 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001957 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001958 new_itr = (10 * new_itr * q_vector->itr) /
1959 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001960
Alexander Duyckbd198052011-06-11 01:45:08 +00001961 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001962 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001963
1964 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001965 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001966}
1967
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001968/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00001969 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00001970 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001971 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001972static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001973{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001974 struct ixgbe_hw *hw = &adapter->hw;
1975 u32 eicr = adapter->interrupt_event;
1976
Alexander Duyckf0f97782011-04-22 04:08:09 +00001977 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001978 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001979
Alexander Duyckf0f97782011-04-22 04:08:09 +00001980 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1981 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1982 return;
1983
1984 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1985
Joe Perches7ca647b2010-09-07 21:35:40 +00001986 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001987 case IXGBE_DEV_ID_82599_T3_LOM:
1988 /*
1989 * Since the warning interrupt is for both ports
1990 * we don't have to check if:
1991 * - This interrupt wasn't for our port.
1992 * - We may have missed the interrupt so always have to
1993 * check if we got a LSC
1994 */
1995 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1996 !(eicr & IXGBE_EICR_LSC))
1997 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001998
Alexander Duyckf0f97782011-04-22 04:08:09 +00001999 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2000 u32 autoneg;
2001 bool link_up = false;
2002
Joe Perches7ca647b2010-09-07 21:35:40 +00002003 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2004
Alexander Duyckf0f97782011-04-22 04:08:09 +00002005 if (link_up)
2006 return;
2007 }
2008
2009 /* Check if this is not due to overtemp */
2010 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2011 return;
2012
2013 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002014 default:
2015 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2016 return;
2017 break;
2018 }
2019 e_crit(drv,
2020 "Network adapter has been stopped because it has over heated. "
2021 "Restart the computer. If the problem persists, "
2022 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002023
2024 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002025}
2026
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002027static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2028{
2029 struct ixgbe_hw *hw = &adapter->hw;
2030
2031 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2032 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002033 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002034 /* write to clear the interrupt */
2035 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2036 }
2037}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002038
Jacob Keller4f51bf72011-08-20 04:49:45 +00002039static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2040{
2041 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2042 return;
2043
2044 switch (adapter->hw.mac.type) {
2045 case ixgbe_mac_82599EB:
2046 /*
2047 * Need to check link state so complete overtemp check
2048 * on service task
2049 */
2050 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2051 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2052 adapter->interrupt_event = eicr;
2053 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2054 ixgbe_service_event_schedule(adapter);
2055 return;
2056 }
2057 return;
2058 case ixgbe_mac_X540:
2059 if (!(eicr & IXGBE_EICR_TS))
2060 return;
2061 break;
2062 default:
2063 return;
2064 }
2065
2066 e_crit(drv,
2067 "Network adapter has been stopped because it has over heated. "
2068 "Restart the computer. If the problem persists, "
2069 "power off the system and replace the adapter\n");
2070}
2071
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002072static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2073{
2074 struct ixgbe_hw *hw = &adapter->hw;
2075
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002076 if (eicr & IXGBE_EICR_GPI_SDP2) {
2077 /* Clear the interrupt */
2078 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002079 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2080 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2081 ixgbe_service_event_schedule(adapter);
2082 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002083 }
2084
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002085 if (eicr & IXGBE_EICR_GPI_SDP1) {
2086 /* Clear the interrupt */
2087 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002088 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2089 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2090 ixgbe_service_event_schedule(adapter);
2091 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002092 }
2093}
2094
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002095static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2096{
2097 struct ixgbe_hw *hw = &adapter->hw;
2098
2099 adapter->lsc_int++;
2100 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2101 adapter->link_check_timeout = jiffies;
2102 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2103 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002104 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002105 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002106 }
2107}
2108
Alexander Duyckfe49f042009-06-04 16:00:09 +00002109static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2110 u64 qmask)
2111{
2112 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002113 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002114
Alexander Duyckbd508172010-11-16 19:27:03 -08002115 switch (hw->mac.type) {
2116 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002117 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002118 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2119 break;
2120 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002121 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002122 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002123 if (mask)
2124 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002125 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002126 if (mask)
2127 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2128 break;
2129 default:
2130 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002131 }
2132 /* skip the flush */
2133}
2134
2135static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002136 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002137{
2138 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002139 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002140
Alexander Duyckbd508172010-11-16 19:27:03 -08002141 switch (hw->mac.type) {
2142 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002143 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002144 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2145 break;
2146 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002147 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002148 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002149 if (mask)
2150 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002151 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002152 if (mask)
2153 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2154 break;
2155 default:
2156 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002157 }
2158 /* skip the flush */
2159}
2160
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002161/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002162 * ixgbe_irq_enable - Enable default interrupt generation settings
2163 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002164 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002165static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2166 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002167{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002168 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002169
Alexander Duyck2c4af692011-07-15 07:29:55 +00002170 /* don't reenable LSC while waiting for link */
2171 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2172 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002173
Alexander Duyck2c4af692011-07-15 07:29:55 +00002174 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002175 switch (adapter->hw.mac.type) {
2176 case ixgbe_mac_82599EB:
2177 mask |= IXGBE_EIMS_GPI_SDP0;
2178 break;
2179 case ixgbe_mac_X540:
2180 mask |= IXGBE_EIMS_TS;
2181 break;
2182 default:
2183 break;
2184 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002185 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2186 mask |= IXGBE_EIMS_GPI_SDP1;
2187 switch (adapter->hw.mac.type) {
2188 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002189 mask |= IXGBE_EIMS_GPI_SDP1;
2190 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002191 case ixgbe_mac_X540:
2192 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002193 mask |= IXGBE_EIMS_MAILBOX;
2194 break;
2195 default:
2196 break;
2197 }
2198 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2199 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2200 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002201
Alexander Duyck2c4af692011-07-15 07:29:55 +00002202 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2203 if (queues)
2204 ixgbe_irq_enable_queues(adapter, ~0);
2205 if (flush)
2206 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002207}
2208
Alexander Duyck2c4af692011-07-15 07:29:55 +00002209static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002210{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002211 struct ixgbe_adapter *adapter = data;
2212 struct ixgbe_hw *hw = &adapter->hw;
2213 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002214
Alexander Duyck2c4af692011-07-15 07:29:55 +00002215 /*
2216 * Workaround for Silicon errata. Use clear-by-write instead
2217 * of clear-by-read. Reading with EICS will return the
2218 * interrupt causes without clearing, which later be done
2219 * with the write to EICR.
2220 */
2221 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2222 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002223
Alexander Duyck2c4af692011-07-15 07:29:55 +00002224 if (eicr & IXGBE_EICR_LSC)
2225 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226
Alexander Duyck2c4af692011-07-15 07:29:55 +00002227 if (eicr & IXGBE_EICR_MAILBOX)
2228 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002229
Alexander Duyck2c4af692011-07-15 07:29:55 +00002230 switch (hw->mac.type) {
2231 case ixgbe_mac_82599EB:
2232 case ixgbe_mac_X540:
2233 if (eicr & IXGBE_EICR_ECC)
2234 e_info(link, "Received unrecoverable ECC Err, please "
2235 "reboot\n");
2236 /* Handle Flow Director Full threshold interrupt */
2237 if (eicr & IXGBE_EICR_FLOW_DIR) {
2238 int reinit_count = 0;
2239 int i;
2240 for (i = 0; i < adapter->num_tx_queues; i++) {
2241 struct ixgbe_ring *ring = adapter->tx_ring[i];
2242 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2243 &ring->state))
2244 reinit_count++;
2245 }
2246 if (reinit_count) {
2247 /* no more flow director interrupts until after init */
2248 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2249 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2250 ixgbe_service_event_schedule(adapter);
2251 }
2252 }
2253 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002254 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002255 break;
2256 default:
2257 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002258 }
2259
Alexander Duyck2c4af692011-07-15 07:29:55 +00002260 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002261
Alexander Duyck2c4af692011-07-15 07:29:55 +00002262 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002263 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002264 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002265
Alexander Duyck2c4af692011-07-15 07:29:55 +00002266 return IRQ_HANDLED;
2267}
2268
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002269static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002270{
2271 struct ixgbe_q_vector *q_vector = data;
2272
Auke Kok9a799d72007-09-15 14:07:45 -07002273 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002274
2275 if (q_vector->rx.ring || q_vector->tx.ring)
2276 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002277
2278 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002279}
2280
Auke Kok9a799d72007-09-15 14:07:45 -07002281/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002282 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2283 * @adapter: board private structure
2284 *
2285 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2286 * interrupts from the kernel.
2287 **/
2288static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2289{
2290 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002291 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2292 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002293 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002295 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002296 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002297 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002298
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002299 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002300 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002301 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002302 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002303 } else if (q_vector->rx.ring) {
2304 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2305 "%s-%s-%d", netdev->name, "rx", ri++);
2306 } else if (q_vector->tx.ring) {
2307 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2308 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002309 } else {
2310 /* skip this unused q_vector */
2311 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002312 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002313 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2314 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002316 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002317 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002318 goto free_queue_irqs;
2319 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002320 /* If Flow Director is enabled, set interrupt affinity */
2321 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2322 /* assign the mask for this irq */
2323 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002324 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002325 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002326 }
2327
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002328 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002329 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002330 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002331 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002332 goto free_queue_irqs;
2333 }
2334
2335 return 0;
2336
2337free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002338 while (vector) {
2339 vector--;
2340 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2341 NULL);
2342 free_irq(adapter->msix_entries[vector].vector,
2343 adapter->q_vector[vector]);
2344 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002345 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2346 pci_disable_msix(adapter->pdev);
2347 kfree(adapter->msix_entries);
2348 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002349 return err;
2350}
2351
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002352/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002353 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002354 * @irq: interrupt number
2355 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002356 **/
2357static irqreturn_t ixgbe_intr(int irq, void *data)
2358{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002359 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002360 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002361 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002362 u32 eicr;
2363
Don Skidmore54037502009-02-21 15:42:56 -08002364 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002365 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002366 * before the read of EICR.
2367 */
2368 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2369
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002370 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002371 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002372 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002373 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002374 /*
2375 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002376 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002377 * have disabled interrupts due to EIAM
2378 * finish the workaround of silicon errata on 82598. Unmask
2379 * the interrupt that we masked before the EICR read.
2380 */
2381 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2382 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002383 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002384 }
Auke Kok9a799d72007-09-15 14:07:45 -07002385
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002386 if (eicr & IXGBE_EICR_LSC)
2387 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002388
Alexander Duyckbd508172010-11-16 19:27:03 -08002389 switch (hw->mac.type) {
2390 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002391 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002392 /* Fall through */
2393 case ixgbe_mac_X540:
2394 if (eicr & IXGBE_EICR_ECC)
2395 e_info(link, "Received unrecoverable ECC err, please "
2396 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002397 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002398 break;
2399 default:
2400 break;
2401 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002402
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002403 ixgbe_check_fan_failure(adapter, eicr);
2404
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002405 /* would disable interrupts here but EIAM disabled it */
2406 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002407
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002408 /*
2409 * re-enable link(maybe) and non-queue interrupts, no flush.
2410 * ixgbe_poll will re-enable the queue interrupts
2411 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002412 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2413 ixgbe_irq_enable(adapter, false, false);
2414
Auke Kok9a799d72007-09-15 14:07:45 -07002415 return IRQ_HANDLED;
2416}
2417
2418/**
2419 * ixgbe_request_irq - initialize interrupts
2420 * @adapter: board private structure
2421 *
2422 * Attempts to configure interrupts using the best available
2423 * capabilities of the hardware and kernel.
2424 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002425static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002426{
2427 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002428 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002429
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002430 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002431 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002432 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002433 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002434 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002435 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002436 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002437 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002438
Alexander Duyckde88eee2012-02-08 07:49:59 +00002439 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002440 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002441
Auke Kok9a799d72007-09-15 14:07:45 -07002442 return err;
2443}
2444
2445static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2446{
Auke Kok9a799d72007-09-15 14:07:45 -07002447 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002449
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002452 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002453 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002454
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002455 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002456 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002457 if (!adapter->q_vector[i]->rx.ring &&
2458 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002459 continue;
2460
Alexander Duyck207867f2011-07-15 03:05:37 +00002461 /* clear the affinity_mask in the IRQ descriptor */
2462 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2463 NULL);
2464
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002465 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002466 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002467 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002468 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002469 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002470 }
2471}
2472
2473/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002474 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2475 * @adapter: board private structure
2476 **/
2477static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2478{
Alexander Duyckbd508172010-11-16 19:27:03 -08002479 switch (adapter->hw.mac.type) {
2480 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002481 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002482 break;
2483 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002484 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002485 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2486 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002487 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002488 break;
2489 default:
2490 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002491 }
2492 IXGBE_WRITE_FLUSH(&adapter->hw);
2493 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2494 int i;
2495 for (i = 0; i < adapter->num_msix_vectors; i++)
2496 synchronize_irq(adapter->msix_entries[i].vector);
2497 } else {
2498 synchronize_irq(adapter->pdev->irq);
2499 }
2500}
2501
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002502/**
Auke Kok9a799d72007-09-15 14:07:45 -07002503 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2504 *
2505 **/
2506static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2507{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002508 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002509
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002510 /* rx/tx vector */
2511 if (adapter->rx_itr_setting == 1)
2512 q_vector->itr = IXGBE_20K_ITR;
2513 else
2514 q_vector->itr = adapter->rx_itr_setting;
2515
2516 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002517
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002518 ixgbe_set_ivar(adapter, 0, 0, 0);
2519 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520
Emil Tantilov396e7992010-07-01 20:05:12 +00002521 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002522}
2523
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002524/**
2525 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2526 * @adapter: board private structure
2527 * @ring: structure containing ring specific data
2528 *
2529 * Configure the Tx descriptor ring after a reset.
2530 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002531void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2532 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002533{
2534 struct ixgbe_hw *hw = &adapter->hw;
2535 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002536 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002537 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002538 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002539
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002540 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002541 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002542 IXGBE_WRITE_FLUSH(hw);
2543
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002544 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002545 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002546 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2547 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2548 ring->count * sizeof(union ixgbe_adv_tx_desc));
2549 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2550 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002551 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002552
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002553 /*
2554 * set WTHRESH to encourage burst writeback, it should not be set
2555 * higher than 1 when ITR is 0 as it could cause false TX hangs
2556 *
2557 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2558 * to or less than the number of on chip descriptors, which is
2559 * currently 40.
2560 */
Alexander Duycke954b372012-02-08 07:49:38 +00002561 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002562 txdctl |= (1 << 16); /* WTHRESH = 1 */
2563 else
2564 txdctl |= (8 << 16); /* WTHRESH = 8 */
2565
Alexander Duycke954b372012-02-08 07:49:38 +00002566 /*
2567 * Setting PTHRESH to 32 both improves performance
2568 * and avoids a TX hang with DFP enabled
2569 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002570 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2571 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002572
2573 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002574 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2575 adapter->atr_sample_rate) {
2576 ring->atr_sample_rate = adapter->atr_sample_rate;
2577 ring->atr_count = 0;
2578 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2579 } else {
2580 ring->atr_sample_rate = 0;
2581 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002582
John Fastabendc84d3242010-11-16 19:27:12 -08002583 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2584
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002585 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002586 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2587
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002588 netdev_tx_reset_queue(txring_txq(ring));
2589
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002590 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2591 if (hw->mac.type == ixgbe_mac_82598EB &&
2592 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2593 return;
2594
2595 /* poll to verify queue is enabled */
2596 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002597 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002598 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2599 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2600 if (!wait_loop)
2601 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002602}
2603
Alexander Duyck120ff942010-08-19 13:34:50 +00002604static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2605{
2606 struct ixgbe_hw *hw = &adapter->hw;
2607 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002608 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002609 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002610
2611 if (hw->mac.type == ixgbe_mac_82598EB)
2612 return;
2613
2614 /* disable the arbiter while setting MTQC */
2615 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2616 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2617 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2618
2619 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002620 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002621 case (IXGBE_FLAG_SRIOV_ENABLED):
2622 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2623 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2624 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002625 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002626 if (!tcs)
2627 reg = IXGBE_MTQC_64Q_1PB;
2628 else if (tcs <= 4)
2629 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2630 else
2631 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2632
2633 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2634
2635 /* Enable Security TX Buffer IFG for multiple pb */
2636 if (tcs) {
2637 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2638 reg |= IXGBE_SECTX_DCB;
2639 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2640 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002641 break;
2642 }
2643
2644 /* re-enable the arbiter */
2645 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2646 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2647}
2648
Auke Kok9a799d72007-09-15 14:07:45 -07002649/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002650 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002651 * @adapter: board private structure
2652 *
2653 * Configure the Tx unit of the MAC after a reset.
2654 **/
2655static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2656{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002657 struct ixgbe_hw *hw = &adapter->hw;
2658 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002659 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002660
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002661 ixgbe_setup_mtqc(adapter);
2662
2663 if (hw->mac.type != ixgbe_mac_82598EB) {
2664 /* DMATXCTL.EN must be before Tx queues are enabled */
2665 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2666 dmatxctl |= IXGBE_DMATXCTL_TE;
2667 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2668 }
2669
Auke Kok9a799d72007-09-15 14:07:45 -07002670 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002671 for (i = 0; i < adapter->num_tx_queues; i++)
2672 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002673}
2674
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002675#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002676
Yi Zoua6616b42009-08-06 13:05:23 +00002677static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002678 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002679{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002680 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002681 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002682
Alexander Duyckbd508172010-11-16 19:27:03 -08002683 switch (adapter->hw.mac.type) {
2684 case ixgbe_mac_82598EB: {
2685 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2686 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002687 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002688 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002689 break;
2690 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002691 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002692 default:
2693 break;
2694 }
2695
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002696 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002697
2698 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2699 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002700 if (adapter->num_vfs)
2701 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002702
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002703 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2704 IXGBE_SRRCTL_BSIZEHDR_MASK;
2705
Alexander Duyckf8003262012-03-03 02:35:52 +00002706#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2707 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002708#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002709 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002710#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002711 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002712
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002713 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002714}
2715
Alexander Duyck05abb122010-08-19 13:35:41 +00002716static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002717{
Alexander Duyck05abb122010-08-19 13:35:41 +00002718 struct ixgbe_hw *hw = &adapter->hw;
2719 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002720 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2721 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002722 u32 mrqc = 0, reta = 0;
2723 u32 rxcsum;
2724 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002725 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002726 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2727
2728 if (tcs)
2729 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002730
Alexander Duyck05abb122010-08-19 13:35:41 +00002731 /* Fill out hash function seeds */
2732 for (i = 0; i < 10; i++)
2733 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002734
Alexander Duyck05abb122010-08-19 13:35:41 +00002735 /* Fill out redirection table */
2736 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002737 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002738 j = 0;
2739 /* reta = 4-byte sliding window of
2740 * 0x00..(indices-1)(indices-1)00..etc. */
2741 reta = (reta << 8) | (j * 0x11);
2742 if ((i & 3) == 3)
2743 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2744 }
2745
2746 /* Disable indicating checksum in descriptor, enables RSS hash */
2747 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2748 rxcsum |= IXGBE_RXCSUM_PCSD;
2749 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2750
John Fastabend8b1c0b22011-05-03 02:26:48 +00002751 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2752 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002753 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002754 } else {
2755 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2756 | IXGBE_FLAG_SRIOV_ENABLED);
2757
2758 switch (mask) {
2759 case (IXGBE_FLAG_RSS_ENABLED):
2760 if (!tcs)
2761 mrqc = IXGBE_MRQC_RSSEN;
2762 else if (tcs <= 4)
2763 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2764 else
2765 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2766 break;
2767 case (IXGBE_FLAG_SRIOV_ENABLED):
2768 mrqc = IXGBE_MRQC_VMDQEN;
2769 break;
2770 default:
2771 break;
2772 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002773 }
2774
Alexander Duyck05abb122010-08-19 13:35:41 +00002775 /* Perform hash on these packet types */
2776 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2777 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2778 | IXGBE_MRQC_RSS_FIELD_IPV6
2779 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2780
2781 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002782}
2783
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002784/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002785 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2786 * @adapter: address of board private structure
2787 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002788 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002789static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002790 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002791{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002792 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002793 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002794 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002795
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002796 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002797 return;
2798
Alexander Duyck73670962010-08-19 13:38:34 +00002799 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002800 rscctrl |= IXGBE_RSCCTL_RSCEN;
2801 /*
2802 * we must limit the number of descriptors so that the
2803 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002804 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002805 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002806#if (PAGE_SIZE <= 8192)
2807 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2808#elif (PAGE_SIZE <= 16384)
2809 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002810#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002811 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002812#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002813 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002814}
2815
Alexander Duyck9e10e042010-08-19 13:40:06 +00002816/**
2817 * ixgbe_set_uta - Set unicast filter table address
2818 * @adapter: board private structure
2819 *
2820 * The unicast table address is a register array of 32-bit registers.
2821 * The table is meant to be used in a way similar to how the MTA is used
2822 * however due to certain limitations in the hardware it is necessary to
2823 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2824 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2825 **/
2826static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2827{
2828 struct ixgbe_hw *hw = &adapter->hw;
2829 int i;
2830
2831 /* The UTA table only exists on 82599 hardware and newer */
2832 if (hw->mac.type < ixgbe_mac_82599EB)
2833 return;
2834
2835 /* we only need to do this if VMDq is enabled */
2836 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2837 return;
2838
2839 for (i = 0; i < 128; i++)
2840 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2841}
2842
2843#define IXGBE_MAX_RX_DESC_POLL 10
2844static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2845 struct ixgbe_ring *ring)
2846{
2847 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002848 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2849 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002850 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002851
2852 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2853 if (hw->mac.type == ixgbe_mac_82598EB &&
2854 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2855 return;
2856
2857 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002858 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002859 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2860 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2861
2862 if (!wait_loop) {
2863 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2864 "the polling period\n", reg_idx);
2865 }
2866}
2867
Yi Zou2d39d572011-01-06 14:29:56 +00002868void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2869 struct ixgbe_ring *ring)
2870{
2871 struct ixgbe_hw *hw = &adapter->hw;
2872 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2873 u32 rxdctl;
2874 u8 reg_idx = ring->reg_idx;
2875
2876 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2877 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2878
2879 /* write value back with RXDCTL.ENABLE bit cleared */
2880 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2881
2882 if (hw->mac.type == ixgbe_mac_82598EB &&
2883 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2884 return;
2885
2886 /* the hardware may take up to 100us to really disable the rx queue */
2887 do {
2888 udelay(10);
2889 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2890 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2891
2892 if (!wait_loop) {
2893 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2894 "the polling period\n", reg_idx);
2895 }
2896}
2897
Alexander Duyck84418e32010-08-19 13:40:54 +00002898void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2899 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002900{
2901 struct ixgbe_hw *hw = &adapter->hw;
2902 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002903 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002904 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002905
Alexander Duyck9e10e042010-08-19 13:40:06 +00002906 /* disable queue to avoid issues while updating state */
2907 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002908 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002909
Alexander Duyckacd37172010-08-19 13:36:05 +00002910 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2911 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2912 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2913 ring->count * sizeof(union ixgbe_adv_rx_desc));
2914 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2915 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002916 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002917
2918 ixgbe_configure_srrctl(adapter, ring);
2919 ixgbe_configure_rscctl(adapter, ring);
2920
Greg Rosee9f98072011-01-26 01:06:07 +00002921 /* If operating in IOV mode set RLPML for X540 */
2922 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2923 hw->mac.type == ixgbe_mac_X540) {
2924 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2925 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2926 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2927 }
2928
Alexander Duyck9e10e042010-08-19 13:40:06 +00002929 if (hw->mac.type == ixgbe_mac_82598EB) {
2930 /*
2931 * enable cache line friendly hardware writes:
2932 * PTHRESH=32 descriptors (half the internal cache),
2933 * this also removes ugly rx_no_buffer_count increment
2934 * HTHRESH=4 descriptors (to minimize latency on fetch)
2935 * WTHRESH=8 burst writeback up to two cache lines
2936 */
2937 rxdctl &= ~0x3FFFFF;
2938 rxdctl |= 0x080420;
2939 }
2940
2941 /* enable receive descriptor ring */
2942 rxdctl |= IXGBE_RXDCTL_ENABLE;
2943 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2944
2945 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002946 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002947}
2948
Alexander Duyck48654522010-08-19 13:36:27 +00002949static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2950{
2951 struct ixgbe_hw *hw = &adapter->hw;
2952 int p;
2953
2954 /* PSRTYPE must be initialized in non 82598 adapters */
2955 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002956 IXGBE_PSRTYPE_UDPHDR |
2957 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002958 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002959 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002960
2961 if (hw->mac.type == ixgbe_mac_82598EB)
2962 return;
2963
2964 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2965 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2966
2967 for (p = 0; p < adapter->num_rx_pools; p++)
2968 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2969 psrtype);
2970}
2971
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002972static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2973{
2974 struct ixgbe_hw *hw = &adapter->hw;
2975 u32 gcr_ext;
2976 u32 vt_reg_bits;
2977 u32 reg_offset, vf_shift;
2978 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00002979 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002980
2981 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2982 return;
2983
2984 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2985 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2986 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2987 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2988
2989 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00002990 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002991
2992 /* Enable only the PF's pool for Tx/Rx */
2993 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2994 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2995 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2996 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2997 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2998
2999 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3000 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3001
3002 /*
3003 * Set up VF register offsets for selected VT Mode,
3004 * i.e. 32 or 64 VFs for SR-IOV
3005 */
3006 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3007 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3008 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3009 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3010
3011 /* enable Tx loopback for VF/PF communication */
3012 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003013 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003014 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003015 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003016 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003017 /* For VFs that have spoof checking turned off */
3018 for (i = 0; i < adapter->num_vfs; i++) {
3019 if (!adapter->vfinfo[i].spoofchk_enabled)
3020 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3021 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003022}
3023
Alexander Duyck477de6e2010-08-19 13:38:11 +00003024static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003025{
Auke Kok9a799d72007-09-15 14:07:45 -07003026 struct ixgbe_hw *hw = &adapter->hw;
3027 struct net_device *netdev = adapter->netdev;
3028 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003029 struct ixgbe_ring *rx_ring;
3030 int i;
3031 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003032
Alexander Duyck477de6e2010-08-19 13:38:11 +00003033#ifdef IXGBE_FCOE
3034 /* adjust max frame to be able to do baby jumbo for FCoE */
3035 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3036 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3037 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3038
3039#endif /* IXGBE_FCOE */
3040 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3041 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3042 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3043 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3044
3045 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003046 }
3047
Alexander Duyck919e78a2011-08-26 09:52:38 +00003048 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3049 max_frame += VLAN_HLEN;
3050
Auke Kok9a799d72007-09-15 14:07:45 -07003051 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003052 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3053 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003054 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3055
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003056 /*
3057 * Setup the HW Rx Head and Tail Descriptor Pointers and
3058 * the Base and Length of the Rx Descriptor Ring
3059 */
Auke Kok9a799d72007-09-15 14:07:45 -07003060 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003061 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003062 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3063 set_ring_rsc_enabled(rx_ring);
3064 else
3065 clear_ring_rsc_enabled(rx_ring);
Yi Zou63f39bd2009-05-17 12:34:35 +00003066#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003067 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003068 struct ixgbe_ring_feature *f;
3069 f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckf8003262012-03-03 02:35:52 +00003070 if ((i >= f->mask) && (i < f->mask + f->indices))
3071 set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state);
Yi Zou63f39bd2009-05-17 12:34:35 +00003072 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003073#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003074 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003075}
3076
Alexander Duyck73670962010-08-19 13:38:34 +00003077static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3078{
3079 struct ixgbe_hw *hw = &adapter->hw;
3080 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3081
3082 switch (hw->mac.type) {
3083 case ixgbe_mac_82598EB:
3084 /*
3085 * For VMDq support of different descriptor types or
3086 * buffer sizes through the use of multiple SRRCTL
3087 * registers, RDRXCTL.MVMEN must be set to 1
3088 *
3089 * also, the manual doesn't mention it clearly but DCA hints
3090 * will only use queue 0's tags unless this bit is set. Side
3091 * effects of setting this bit are only that SRRCTL must be
3092 * fully programmed [0..15]
3093 */
3094 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3095 break;
3096 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003097 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003098 /* Disable RSC for ACK packets */
3099 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3100 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3101 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3102 /* hardware requires some bits to be set by default */
3103 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3104 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3105 break;
3106 default:
3107 /* We should do nothing since we don't know this hardware */
3108 return;
3109 }
3110
3111 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3112}
3113
Alexander Duyck477de6e2010-08-19 13:38:11 +00003114/**
3115 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3116 * @adapter: board private structure
3117 *
3118 * Configure the Rx unit of the MAC after a reset.
3119 **/
3120static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3121{
3122 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003123 int i;
3124 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003125
3126 /* disable receives while setting up the descriptors */
3127 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3128 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3129
3130 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003131 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003132
Alexander Duyck9e10e042010-08-19 13:40:06 +00003133 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003134 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003135
Alexander Duyck9e10e042010-08-19 13:40:06 +00003136 ixgbe_set_uta(adapter);
3137
Alexander Duyck477de6e2010-08-19 13:38:11 +00003138 /* set_rx_buffer_len must be called before ring initialization */
3139 ixgbe_set_rx_buffer_len(adapter);
3140
3141 /*
3142 * Setup the HW Rx Head and Tail Descriptor Pointers and
3143 * the Base and Length of the Rx Descriptor Ring
3144 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003145 for (i = 0; i < adapter->num_rx_queues; i++)
3146 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003147
Alexander Duyck9e10e042010-08-19 13:40:06 +00003148 /* disable drop enable for 82598 parts */
3149 if (hw->mac.type == ixgbe_mac_82598EB)
3150 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3151
3152 /* enable all receives */
3153 rxctrl |= IXGBE_RXCTRL_RXEN;
3154 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003155}
3156
Jiri Pirko8e586132011-12-08 19:52:37 -05003157static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003158{
3159 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003160 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003161 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003162
3163 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003164 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003165 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003166
3167 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003168}
3169
Jiri Pirko8e586132011-12-08 19:52:37 -05003170static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003171{
3172 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003173 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003174 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003175
Auke Kok9a799d72007-09-15 14:07:45 -07003176 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003177 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003178 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003179
3180 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003181}
3182
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003183/**
3184 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3185 * @adapter: driver data
3186 */
3187static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3188{
3189 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003190 u32 vlnctrl;
3191
3192 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3193 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3194 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3195}
3196
3197/**
3198 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3199 * @adapter: driver data
3200 */
3201static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3202{
3203 struct ixgbe_hw *hw = &adapter->hw;
3204 u32 vlnctrl;
3205
3206 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3207 vlnctrl |= IXGBE_VLNCTRL_VFE;
3208 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3209 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3210}
3211
3212/**
3213 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3214 * @adapter: driver data
3215 */
3216static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3217{
3218 struct ixgbe_hw *hw = &adapter->hw;
3219 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003220 int i, j;
3221
3222 switch (hw->mac.type) {
3223 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003224 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3225 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003226 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3227 break;
3228 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003229 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003230 for (i = 0; i < adapter->num_rx_queues; i++) {
3231 j = adapter->rx_ring[i]->reg_idx;
3232 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3233 vlnctrl &= ~IXGBE_RXDCTL_VME;
3234 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3235 }
3236 break;
3237 default:
3238 break;
3239 }
3240}
3241
3242/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003243 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003244 * @adapter: driver data
3245 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003246static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003247{
3248 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003249 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003250 int i, j;
3251
3252 switch (hw->mac.type) {
3253 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003254 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3255 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003256 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3257 break;
3258 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003259 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003260 for (i = 0; i < adapter->num_rx_queues; i++) {
3261 j = adapter->rx_ring[i]->reg_idx;
3262 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3263 vlnctrl |= IXGBE_RXDCTL_VME;
3264 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3265 }
3266 break;
3267 default:
3268 break;
3269 }
3270}
3271
Auke Kok9a799d72007-09-15 14:07:45 -07003272static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3273{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003274 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003275
Jesse Grossf62bbb52010-10-20 13:56:10 +00003276 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3277
3278 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3279 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003280}
3281
3282/**
Alexander Duyck28500622010-06-15 09:25:48 +00003283 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3284 * @netdev: network interface device structure
3285 *
3286 * Writes unicast address list to the RAR table.
3287 * Returns: -ENOMEM on failure/insufficient address space
3288 * 0 on no addresses written
3289 * X on writing X addresses to the RAR table
3290 **/
3291static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3292{
3293 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3294 struct ixgbe_hw *hw = &adapter->hw;
3295 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003296 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003297 int count = 0;
3298
3299 /* return ENOMEM indicating insufficient memory for addresses */
3300 if (netdev_uc_count(netdev) > rar_entries)
3301 return -ENOMEM;
3302
3303 if (!netdev_uc_empty(netdev) && rar_entries) {
3304 struct netdev_hw_addr *ha;
3305 /* return error if we do not support writing to RAR table */
3306 if (!hw->mac.ops.set_rar)
3307 return -ENOMEM;
3308
3309 netdev_for_each_uc_addr(ha, netdev) {
3310 if (!rar_entries)
3311 break;
3312 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3313 vfn, IXGBE_RAH_AV);
3314 count++;
3315 }
3316 }
3317 /* write the addresses in reverse order to avoid write combining */
3318 for (; rar_entries > 0 ; rar_entries--)
3319 hw->mac.ops.clear_rar(hw, rar_entries);
3320
3321 return count;
3322}
3323
3324/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003325 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003326 * @netdev: network interface device structure
3327 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003328 * The set_rx_method entry point is called whenever the unicast/multicast
3329 * address list or the network interface flags are updated. This routine is
3330 * responsible for configuring the hardware for proper unicast, multicast and
3331 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003332 **/
Greg Rose7f870472010-01-09 02:25:29 +00003333void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003334{
3335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3336 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003337 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3338 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003339
3340 /* Check for Promiscuous and All Multicast modes */
3341
3342 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3343
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003344 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003345 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003346 fctrl |= IXGBE_FCTRL_BAM;
3347 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3348 fctrl |= IXGBE_FCTRL_PMCF;
3349
Alexander Duyck28500622010-06-15 09:25:48 +00003350 /* clear the bits we are changing the status of */
3351 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3352
Auke Kok9a799d72007-09-15 14:07:45 -07003353 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003354 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003355 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003356 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003357 /* don't hardware filter vlans in promisc mode */
3358 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003359 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003360 if (netdev->flags & IFF_ALLMULTI) {
3361 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003362 vmolr |= IXGBE_VMOLR_MPE;
3363 } else {
3364 /*
3365 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003366 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003367 * that we can at least receive multicast traffic
3368 */
3369 hw->mac.ops.update_mc_addr_list(hw, netdev);
3370 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003371 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003372 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003373 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003374 /*
3375 * Write addresses to available RAR registers, if there is not
3376 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003377 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003378 */
3379 count = ixgbe_write_uc_addr_list(netdev);
3380 if (count < 0) {
3381 fctrl |= IXGBE_FCTRL_UPE;
3382 vmolr |= IXGBE_VMOLR_ROPE;
3383 }
3384 }
3385
3386 if (adapter->num_vfs) {
3387 ixgbe_restore_vf_multicasts(adapter);
3388 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3389 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3390 IXGBE_VMOLR_ROPE);
3391 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003392 }
3393
Ben Greear3f2d1c02012-03-08 08:28:41 +00003394 /* This is useful for sniffing bad packets. */
3395 if (adapter->netdev->features & NETIF_F_RXALL) {
3396 /* UPE and MPE will be handled by normal PROMISC logic
3397 * in e1000e_set_rx_mode */
3398 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3399 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3400 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3401
3402 fctrl &= ~(IXGBE_FCTRL_DPF);
3403 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3404 }
3405
Auke Kok9a799d72007-09-15 14:07:45 -07003406 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003407
3408 if (netdev->features & NETIF_F_HW_VLAN_RX)
3409 ixgbe_vlan_strip_enable(adapter);
3410 else
3411 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003412}
3413
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003414static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3415{
3416 int q_idx;
3417 struct ixgbe_q_vector *q_vector;
3418 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3419
3420 /* legacy and MSI only use one vector */
3421 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3422 q_vectors = 1;
3423
3424 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003425 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003426 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003427 }
3428}
3429
3430static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3431{
3432 int q_idx;
3433 struct ixgbe_q_vector *q_vector;
3434 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3435
3436 /* legacy and MSI only use one vector */
3437 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3438 q_vectors = 1;
3439
3440 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003441 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003442 napi_disable(&q_vector->napi);
3443 }
3444}
3445
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003446#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003447/*
3448 * ixgbe_configure_dcb - Configure DCB hardware
3449 * @adapter: ixgbe adapter struct
3450 *
3451 * This is called by the driver on open to configure the DCB hardware.
3452 * This is also called by the gennetlink interface when reconfiguring
3453 * the DCB state.
3454 */
3455static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3456{
3457 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003458 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003459
Alexander Duyck67ebd792010-08-19 13:34:04 +00003460 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3461 if (hw->mac.type == ixgbe_mac_82598EB)
3462 netif_set_gso_max_size(adapter->netdev, 65536);
3463 return;
3464 }
3465
3466 if (hw->mac.type == ixgbe_mac_82598EB)
3467 netif_set_gso_max_size(adapter->netdev, 32768);
3468
Alexander Duyck2f90b862008-11-20 20:52:10 -08003469
Alexander Duyck2f90b862008-11-20 20:52:10 -08003470 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003471 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003472
Alexander Duyck2f90b862008-11-20 20:52:10 -08003473 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003474
John Fastabendb1208182011-10-15 05:00:10 +00003475#ifdef IXGBE_FCOE
3476 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3477 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3478#endif
3479
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003480 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003481 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003482 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3483 DCB_TX_CONFIG);
3484 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3485 DCB_RX_CONFIG);
3486 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003487 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3488 ixgbe_dcb_hw_ets(&adapter->hw,
3489 adapter->ixgbe_ieee_ets,
3490 max_frame);
3491 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3492 adapter->ixgbe_ieee_pfc->pfc_en,
3493 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003494 }
John Fastabend8187cd42011-02-23 05:58:08 +00003495
3496 /* Enable RSS Hash per TC */
3497 if (hw->mac.type != ixgbe_mac_82598EB) {
3498 int i;
3499 u32 reg = 0;
3500
3501 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3502 u8 msb = 0;
3503 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3504
3505 while (cnt >>= 1)
3506 msb++;
3507
3508 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3509 }
3510 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3511 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003512}
John Fastabend9da712d2011-08-23 03:14:22 +00003513#endif
3514
3515/* Additional bittime to account for IXGBE framing */
3516#define IXGBE_ETH_FRAMING 20
3517
3518/*
3519 * ixgbe_hpbthresh - calculate high water mark for flow control
3520 *
3521 * @adapter: board private structure to calculate for
3522 * @pb - packet buffer to calculate
3523 */
3524static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3525{
3526 struct ixgbe_hw *hw = &adapter->hw;
3527 struct net_device *dev = adapter->netdev;
3528 int link, tc, kb, marker;
3529 u32 dv_id, rx_pba;
3530
3531 /* Calculate max LAN frame size */
3532 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3533
3534#ifdef IXGBE_FCOE
3535 /* FCoE traffic class uses FCOE jumbo frames */
3536 if (dev->features & NETIF_F_FCOE_MTU) {
3537 int fcoe_pb = 0;
3538
3539#ifdef CONFIG_IXGBE_DCB
3540 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003541
3542#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003543 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3544 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3545 }
3546#endif
3547
3548 /* Calculate delay value for device */
3549 switch (hw->mac.type) {
3550 case ixgbe_mac_X540:
3551 dv_id = IXGBE_DV_X540(link, tc);
3552 break;
3553 default:
3554 dv_id = IXGBE_DV(link, tc);
3555 break;
3556 }
3557
3558 /* Loopback switch introduces additional latency */
3559 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3560 dv_id += IXGBE_B2BT(tc);
3561
3562 /* Delay value is calculated in bit times convert to KB */
3563 kb = IXGBE_BT2KB(dv_id);
3564 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3565
3566 marker = rx_pba - kb;
3567
3568 /* It is possible that the packet buffer is not large enough
3569 * to provide required headroom. In this case throw an error
3570 * to user and a do the best we can.
3571 */
3572 if (marker < 0) {
3573 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3574 "headroom to support flow control."
3575 "Decrease MTU or number of traffic classes\n", pb);
3576 marker = tc + 1;
3577 }
3578
3579 return marker;
3580}
3581
3582/*
3583 * ixgbe_lpbthresh - calculate low water mark for for flow control
3584 *
3585 * @adapter: board private structure to calculate for
3586 * @pb - packet buffer to calculate
3587 */
3588static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3589{
3590 struct ixgbe_hw *hw = &adapter->hw;
3591 struct net_device *dev = adapter->netdev;
3592 int tc;
3593 u32 dv_id;
3594
3595 /* Calculate max LAN frame size */
3596 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3597
3598 /* Calculate delay value for device */
3599 switch (hw->mac.type) {
3600 case ixgbe_mac_X540:
3601 dv_id = IXGBE_LOW_DV_X540(tc);
3602 break;
3603 default:
3604 dv_id = IXGBE_LOW_DV(tc);
3605 break;
3606 }
3607
3608 /* Delay value is calculated in bit times convert to KB */
3609 return IXGBE_BT2KB(dv_id);
3610}
3611
3612/*
3613 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3614 */
3615static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3616{
3617 struct ixgbe_hw *hw = &adapter->hw;
3618 int num_tc = netdev_get_num_tc(adapter->netdev);
3619 int i;
3620
3621 if (!num_tc)
3622 num_tc = 1;
3623
3624 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3625
3626 for (i = 0; i < num_tc; i++) {
3627 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3628
3629 /* Low water marks must not be larger than high water marks */
3630 if (hw->fc.low_water > hw->fc.high_water[i])
3631 hw->fc.low_water = 0;
3632 }
3633}
John Fastabend80605c652011-05-02 12:34:10 +00003634
3635static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3636{
John Fastabend80605c652011-05-02 12:34:10 +00003637 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003638 int hdrm;
3639 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003640
3641 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3642 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003643 hdrm = 32 << adapter->fdir_pballoc;
3644 else
3645 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003646
Alexander Duyckf7e10272011-07-21 00:40:35 +00003647 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003648 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003649}
3650
Alexander Duycke4911d52011-05-11 07:18:52 +00003651static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3652{
3653 struct ixgbe_hw *hw = &adapter->hw;
3654 struct hlist_node *node, *node2;
3655 struct ixgbe_fdir_filter *filter;
3656
3657 spin_lock(&adapter->fdir_perfect_lock);
3658
3659 if (!hlist_empty(&adapter->fdir_filter_list))
3660 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3661
3662 hlist_for_each_entry_safe(filter, node, node2,
3663 &adapter->fdir_filter_list, fdir_node) {
3664 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003665 &filter->filter,
3666 filter->sw_idx,
3667 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3668 IXGBE_FDIR_DROP_QUEUE :
3669 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003670 }
3671
3672 spin_unlock(&adapter->fdir_perfect_lock);
3673}
3674
Auke Kok9a799d72007-09-15 14:07:45 -07003675static void ixgbe_configure(struct ixgbe_adapter *adapter)
3676{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003677 struct ixgbe_hw *hw = &adapter->hw;
3678
John Fastabend80605c652011-05-02 12:34:10 +00003679 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003680#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003681 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003682#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003683
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003684 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003685 ixgbe_restore_vlan(adapter);
3686
Yi Zoueacd73f2009-05-13 13:11:06 +00003687#ifdef IXGBE_FCOE
3688 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3689 ixgbe_configure_fcoe(adapter);
3690
3691#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003692
3693 switch (hw->mac.type) {
3694 case ixgbe_mac_82599EB:
3695 case ixgbe_mac_X540:
3696 hw->mac.ops.disable_rx_buff(hw);
3697 break;
3698 default:
3699 break;
3700 }
3701
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003702 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003703 ixgbe_init_fdir_signature_82599(&adapter->hw,
3704 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003705 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3706 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3707 adapter->fdir_pballoc);
3708 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003709 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003710
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003711 switch (hw->mac.type) {
3712 case ixgbe_mac_82599EB:
3713 case ixgbe_mac_X540:
3714 hw->mac.ops.enable_rx_buff(hw);
3715 break;
3716 default:
3717 break;
3718 }
3719
Alexander Duyck933d41f2010-09-07 21:34:29 +00003720 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003721
Auke Kok9a799d72007-09-15 14:07:45 -07003722 ixgbe_configure_tx(adapter);
3723 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003724}
3725
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003726static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3727{
3728 switch (hw->phy.type) {
3729 case ixgbe_phy_sfp_avago:
3730 case ixgbe_phy_sfp_ftl:
3731 case ixgbe_phy_sfp_intel:
3732 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003733 case ixgbe_phy_sfp_passive_tyco:
3734 case ixgbe_phy_sfp_passive_unknown:
3735 case ixgbe_phy_sfp_active_unknown:
3736 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003737 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003738 case ixgbe_phy_nl:
3739 if (hw->mac.type == ixgbe_mac_82598EB)
3740 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003741 default:
3742 return false;
3743 }
3744}
3745
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003746/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003747 * ixgbe_sfp_link_config - set up SFP+ link
3748 * @adapter: pointer to private adapter struct
3749 **/
3750static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3751{
Alexander Duyck70864002011-04-27 09:13:56 +00003752 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003753 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003754 * is that an SFP was inserted/removed after the reset
3755 * but before SFP detection was enabled. As such the best
3756 * solution is to just start searching as soon as we start
3757 */
3758 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3759 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003760
Alexander Duyck70864002011-04-27 09:13:56 +00003761 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003762}
3763
3764/**
3765 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003766 * @hw: pointer to private hardware struct
3767 *
3768 * Returns 0 on success, negative on failure
3769 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003770static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003771{
3772 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003773 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003774 u32 ret = IXGBE_ERR_LINK_SETUP;
3775
3776 if (hw->mac.ops.check_link)
3777 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3778
3779 if (ret)
3780 goto link_cfg_out;
3781
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003782 autoneg = hw->phy.autoneg_advertised;
3783 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003784 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3785 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003786 if (ret)
3787 goto link_cfg_out;
3788
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003789 if (hw->mac.ops.setup_link)
3790 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003791link_cfg_out:
3792 return ret;
3793}
3794
Alexander Duycka34bcff2010-08-19 13:39:20 +00003795static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003796{
Auke Kok9a799d72007-09-15 14:07:45 -07003797 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003798 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003799
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003800 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003801 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3802 IXGBE_GPIE_OCD;
3803 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003804 /*
3805 * use EIAM to auto-mask when MSI-X interrupt is asserted
3806 * this saves a register write for every interrupt
3807 */
3808 switch (hw->mac.type) {
3809 case ixgbe_mac_82598EB:
3810 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3811 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003812 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003813 case ixgbe_mac_X540:
3814 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003815 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3816 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3817 break;
3818 }
3819 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003820 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3821 * specifically only auto mask tx and rx interrupts */
3822 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003823 }
3824
Alexander Duycka34bcff2010-08-19 13:39:20 +00003825 /* XXX: to interrupt immediately for EICS writes, enable this */
3826 /* gpie |= IXGBE_GPIE_EIMEN; */
3827
3828 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3829 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3830 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003831 }
3832
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003833 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003834 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3835 switch (adapter->hw.mac.type) {
3836 case ixgbe_mac_82599EB:
3837 gpie |= IXGBE_SDP0_GPIEN;
3838 break;
3839 case ixgbe_mac_X540:
3840 gpie |= IXGBE_EIMS_TS;
3841 break;
3842 default:
3843 break;
3844 }
3845 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003846
Alexander Duycka34bcff2010-08-19 13:39:20 +00003847 /* Enable fan failure interrupt */
3848 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003849 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003850
Don Skidmore2698b202011-04-13 07:01:52 +00003851 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003852 gpie |= IXGBE_SDP1_GPIEN;
3853 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003854 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003855
3856 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3857}
3858
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003859static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003860{
3861 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003862 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003863 u32 ctrl_ext;
3864
3865 ixgbe_get_hw_control(adapter);
3866 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003867
Auke Kok9a799d72007-09-15 14:07:45 -07003868 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3869 ixgbe_configure_msix(adapter);
3870 else
3871 ixgbe_configure_msi_and_legacy(adapter);
3872
Don Skidmorec6ecf392010-12-03 03:31:51 +00003873 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3874 if (hw->mac.ops.enable_tx_laser &&
3875 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003876 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003877 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003878 hw->mac.ops.enable_tx_laser(hw);
3879
Auke Kok9a799d72007-09-15 14:07:45 -07003880 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003881 ixgbe_napi_enable_all(adapter);
3882
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003883 if (ixgbe_is_sfp(hw)) {
3884 ixgbe_sfp_link_config(adapter);
3885 } else {
3886 err = ixgbe_non_sfp_link_config(hw);
3887 if (err)
3888 e_err(probe, "link_config FAILED %d\n", err);
3889 }
3890
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003891 /* clear any pending interrupts, may auto mask */
3892 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003893 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003894
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003895 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003896 * If this adapter has a fan, check to see if we had a failure
3897 * before we enabled the interrupt.
3898 */
3899 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3900 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3901 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003902 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003903 }
3904
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003905 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003906 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003907
Auke Kok9a799d72007-09-15 14:07:45 -07003908 /* bring the link up in the watchdog, this could race with our first
3909 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003910 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3911 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003912 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003913
3914 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3915 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3916 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3917 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003918}
3919
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003920void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3921{
3922 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003923 /* put off any impending NetWatchDogTimeout */
3924 adapter->netdev->trans_start = jiffies;
3925
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003926 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003927 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003928 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003929 /*
3930 * If SR-IOV enabled then wait a bit before bringing the adapter
3931 * back up to give the VFs time to respond to the reset. The
3932 * two second wait is based upon the watchdog timer cycle in
3933 * the VF driver.
3934 */
3935 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3936 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003937 ixgbe_up(adapter);
3938 clear_bit(__IXGBE_RESETTING, &adapter->state);
3939}
3940
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003941void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003942{
3943 /* hardware has been reset, we need to reload some things */
3944 ixgbe_configure(adapter);
3945
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003946 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003947}
3948
3949void ixgbe_reset(struct ixgbe_adapter *adapter)
3950{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003951 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003952 int err;
3953
Alexander Duyck70864002011-04-27 09:13:56 +00003954 /* lock SFP init bit to prevent race conditions with the watchdog */
3955 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3956 usleep_range(1000, 2000);
3957
3958 /* clear all SFP and link config related flags while holding SFP_INIT */
3959 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3960 IXGBE_FLAG2_SFP_NEEDS_RESET);
3961 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3962
Don Skidmore8ca783a2009-05-26 20:40:47 -07003963 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003964 switch (err) {
3965 case 0:
3966 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003967 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003968 break;
3969 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003970 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003971 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003972 case IXGBE_ERR_EEPROM_VERSION:
3973 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003974 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003975 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00003976 "your hardware. If you are experiencing problems "
3977 "please contact your Intel or hardware "
3978 "representative who provided you with this "
3979 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003980 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003981 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003982 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003983 }
Auke Kok9a799d72007-09-15 14:07:45 -07003984
Alexander Duyck70864002011-04-27 09:13:56 +00003985 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3986
Auke Kok9a799d72007-09-15 14:07:45 -07003987 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003988 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3989 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003990}
3991
Auke Kok9a799d72007-09-15 14:07:45 -07003992/**
Alexander Duyckf8003262012-03-03 02:35:52 +00003993 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
3994 * @rx_ring: ring to setup
3995 *
3996 * On many IA platforms the L1 cache has a critical stride of 4K, this
3997 * results in each receive buffer starting in the same cache set. To help
3998 * reduce the pressure on this cache set we can interleave the offsets so
3999 * that only every other buffer will be in the same cache set.
4000 **/
4001static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4002{
4003 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4004 u16 i;
4005
4006 for (i = 0; i < rx_ring->count; i += 2) {
4007 rx_buffer[0].page_offset = 0;
4008 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4009 rx_buffer = &rx_buffer[2];
4010 }
4011}
4012
4013/**
Auke Kok9a799d72007-09-15 14:07:45 -07004014 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004015 * @rx_ring: ring to free buffers from
4016 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004017static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004018{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004019 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004020 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004021 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004022
Alexander Duyck84418e32010-08-19 13:40:54 +00004023 /* ring already cleared, nothing to do */
4024 if (!rx_ring->rx_buffer_info)
4025 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004026
Alexander Duyck84418e32010-08-19 13:40:54 +00004027 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004028 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004029 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004030
Alexander Duyckf8003262012-03-03 02:35:52 +00004031 rx_buffer = &rx_ring->rx_buffer_info[i];
4032 if (rx_buffer->skb) {
4033 struct sk_buff *skb = rx_buffer->skb;
4034 if (IXGBE_CB(skb)->page_released) {
4035 dma_unmap_page(dev,
4036 IXGBE_CB(skb)->dma,
4037 ixgbe_rx_bufsz(rx_ring),
4038 DMA_FROM_DEVICE);
4039 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004040 }
4041 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004042 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004043 rx_buffer->skb = NULL;
4044 if (rx_buffer->dma)
4045 dma_unmap_page(dev, rx_buffer->dma,
4046 ixgbe_rx_pg_size(rx_ring),
4047 DMA_FROM_DEVICE);
4048 rx_buffer->dma = 0;
4049 if (rx_buffer->page)
4050 put_page(rx_buffer->page);
4051 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004052 }
4053
4054 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4055 memset(rx_ring->rx_buffer_info, 0, size);
4056
Alexander Duyckf8003262012-03-03 02:35:52 +00004057 ixgbe_init_rx_page_offset(rx_ring);
4058
Auke Kok9a799d72007-09-15 14:07:45 -07004059 /* Zero out the descriptor ring */
4060 memset(rx_ring->desc, 0, rx_ring->size);
4061
Alexander Duyckf8003262012-03-03 02:35:52 +00004062 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004063 rx_ring->next_to_clean = 0;
4064 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004065}
4066
4067/**
4068 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004069 * @tx_ring: ring to be cleaned
4070 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004071static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004072{
4073 struct ixgbe_tx_buffer *tx_buffer_info;
4074 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004075 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004076
Alexander Duyck84418e32010-08-19 13:40:54 +00004077 /* ring already cleared, nothing to do */
4078 if (!tx_ring->tx_buffer_info)
4079 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004080
Alexander Duyck84418e32010-08-19 13:40:54 +00004081 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004082 for (i = 0; i < tx_ring->count; i++) {
4083 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004084 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004085 }
4086
4087 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4088 memset(tx_ring->tx_buffer_info, 0, size);
4089
4090 /* Zero out the descriptor ring */
4091 memset(tx_ring->desc, 0, tx_ring->size);
4092
4093 tx_ring->next_to_use = 0;
4094 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004095}
4096
4097/**
Auke Kok9a799d72007-09-15 14:07:45 -07004098 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4099 * @adapter: board private structure
4100 **/
4101static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4102{
4103 int i;
4104
4105 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004106 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004107}
4108
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004109/**
4110 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4111 * @adapter: board private structure
4112 **/
4113static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4114{
4115 int i;
4116
4117 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004118 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004119}
4120
Alexander Duycke4911d52011-05-11 07:18:52 +00004121static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4122{
4123 struct hlist_node *node, *node2;
4124 struct ixgbe_fdir_filter *filter;
4125
4126 spin_lock(&adapter->fdir_perfect_lock);
4127
4128 hlist_for_each_entry_safe(filter, node, node2,
4129 &adapter->fdir_filter_list, fdir_node) {
4130 hlist_del(&filter->fdir_node);
4131 kfree(filter);
4132 }
4133 adapter->fdir_filter_count = 0;
4134
4135 spin_unlock(&adapter->fdir_perfect_lock);
4136}
4137
Auke Kok9a799d72007-09-15 14:07:45 -07004138void ixgbe_down(struct ixgbe_adapter *adapter)
4139{
4140 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004141 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004142 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004143 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004144
4145 /* signal that we are down to the interrupt handler */
4146 set_bit(__IXGBE_DOWN, &adapter->state);
4147
4148 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004149 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4150 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004151
Yi Zou2d39d572011-01-06 14:29:56 +00004152 /* disable all enabled rx queues */
4153 for (i = 0; i < adapter->num_rx_queues; i++)
4154 /* this call also flushes the previous write */
4155 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4156
Don Skidmore032b4322011-03-18 09:32:53 +00004157 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004158
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004159 netif_tx_stop_all_queues(netdev);
4160
Alexander Duyck70864002011-04-27 09:13:56 +00004161 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004162 netif_carrier_off(netdev);
4163 netif_tx_disable(netdev);
4164
4165 ixgbe_irq_disable(adapter);
4166
4167 ixgbe_napi_disable_all(adapter);
4168
Alexander Duyckd034acf2011-04-27 09:25:34 +00004169 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4170 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004171 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4172
4173 del_timer_sync(&adapter->service_timer);
4174
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004175 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004176 /* Clear EITR Select mapping */
4177 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4178
4179 /* Mark all the VFs as inactive */
4180 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004181 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004182
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004183 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004184 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004185
Auke Kok9a799d72007-09-15 14:07:45 -07004186 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004187 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004188 }
4189
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004190 /* disable transmits in the hardware now that interrupts are off */
4191 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004192 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004193 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004194 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004195
4196 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004197 switch (hw->mac.type) {
4198 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004199 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004200 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004201 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4202 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004203 break;
4204 default:
4205 break;
4206 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004207
Paul Larson6f4a0e42008-06-24 17:00:56 -07004208 if (!pci_channel_offline(adapter->pdev))
4209 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004210
4211 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4212 if (hw->mac.ops.disable_tx_laser &&
4213 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004214 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004215 (hw->mac.type == ixgbe_mac_82599EB))))
4216 hw->mac.ops.disable_tx_laser(hw);
4217
Auke Kok9a799d72007-09-15 14:07:45 -07004218 ixgbe_clean_all_tx_rings(adapter);
4219 ixgbe_clean_all_rx_rings(adapter);
4220
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004221#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004222 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004223 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004224#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004225}
4226
Auke Kok9a799d72007-09-15 14:07:45 -07004227/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004228 * ixgbe_poll - NAPI Rx polling callback
4229 * @napi: structure for representing this polling device
4230 * @budget: how many packets driver is allowed to clean
4231 *
4232 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004233 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004234static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004235{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004236 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004237 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004238 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004239 struct ixgbe_ring *ring;
4240 int per_ring_budget;
4241 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004242
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004243#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004244 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4245 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004246#endif
4247
Alexander Duycka5579282012-02-08 07:50:04 +00004248 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004249 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004250
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004251 /* attempt to distribute budget to each queue fairly, but don't allow
4252 * the budget to go below 1 because we'll exit polling */
4253 if (q_vector->rx.count > 1)
4254 per_ring_budget = max(budget/q_vector->rx.count, 1);
4255 else
4256 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004257
Alexander Duycka5579282012-02-08 07:50:04 +00004258 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004259 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4260 per_ring_budget);
4261
4262 /* If all work not completed, return budget and keep polling */
4263 if (!clean_complete)
4264 return budget;
4265
4266 /* all work done, exit the polling mode */
4267 napi_complete(napi);
4268 if (adapter->rx_itr_setting & 1)
4269 ixgbe_set_itr(q_vector);
4270 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4271 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4272
4273 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004274}
4275
4276/**
4277 * ixgbe_tx_timeout - Respond to a Tx Hang
4278 * @netdev: network interface device structure
4279 **/
4280static void ixgbe_tx_timeout(struct net_device *netdev)
4281{
4282 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4283
4284 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004285 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004286}
4287
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004288/**
4289 * ixgbe_set_rss_queues: Allocate queues for RSS
4290 * @adapter: board private structure to initialize
4291 *
4292 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4293 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4294 *
4295 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004296static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4297{
4298 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004299 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004300
4301 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004302 f->mask = 0xF;
4303 adapter->num_rx_queues = f->indices;
4304 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004305 ret = true;
4306 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004307 ret = false;
4308 }
4309
4310 return ret;
4311}
4312
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004313/**
4314 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4315 * @adapter: board private structure to initialize
4316 *
4317 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4318 * to the original CPU that initiated the Tx session. This runs in addition
4319 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4320 * Rx load across CPUs using RSS.
4321 *
4322 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004323static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004324{
4325 bool ret = false;
4326 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4327
4328 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4329 f_fdir->mask = 0;
4330
Alexander Duyck24ddd962012-02-10 02:08:32 +00004331 /*
4332 * Use RSS in addition to Flow Director to ensure the best
4333 * distribution of flows across cores, even when an FDIR flow
4334 * isn't matched.
4335 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004336 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4337 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004338 adapter->num_tx_queues = f_fdir->indices;
4339 adapter->num_rx_queues = f_fdir->indices;
4340 ret = true;
4341 } else {
4342 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004343 }
4344 return ret;
4345}
4346
Yi Zou0331a832009-05-17 12:33:52 +00004347#ifdef IXGBE_FCOE
4348/**
4349 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4350 * @adapter: board private structure to initialize
4351 *
4352 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4353 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4354 * rx queues out of the max number of rx queues, instead, it is used as the
4355 * index of the first rx queue used by FCoE.
4356 *
4357 **/
4358static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4359{
Yi Zou0331a832009-05-17 12:33:52 +00004360 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4361
John Fastabende5b64632011-03-08 03:44:52 +00004362 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4363 return false;
4364
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004365 f->indices = min_t(int, num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004366
John Fastabende901acd2011-04-26 07:26:08 +00004367 adapter->num_rx_queues = 1;
4368 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004369
John Fastabende901acd2011-04-26 07:26:08 +00004370 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4371 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004372 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004373 ixgbe_set_fdir_queues(adapter);
4374 else
4375 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004376 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004377
John Fastabende901acd2011-04-26 07:26:08 +00004378 /* adding FCoE rx rings to the end */
4379 f->mask = adapter->num_rx_queues;
4380 adapter->num_rx_queues += f->indices;
4381 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004382
John Fastabende5b64632011-03-08 03:44:52 +00004383 return true;
4384}
4385#endif /* IXGBE_FCOE */
4386
John Fastabende901acd2011-04-26 07:26:08 +00004387/* Artificial max queue cap per traffic class in DCB mode */
4388#define DCB_QUEUE_CAP 8
4389
John Fastabende5b64632011-03-08 03:44:52 +00004390#ifdef CONFIG_IXGBE_DCB
4391static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4392{
John Fastabende901acd2011-04-26 07:26:08 +00004393 int per_tc_q, q, i, offset = 0;
4394 struct net_device *dev = adapter->netdev;
4395 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004396
John Fastabende901acd2011-04-26 07:26:08 +00004397 if (!tcs)
4398 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004399
John Fastabende901acd2011-04-26 07:26:08 +00004400 /* Map queue offset and counts onto allocated tx queues */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004401 per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP);
4402 q = min_t(int, num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004403
John Fastabend8b1c0b22011-05-03 02:26:48 +00004404 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004405 netdev_set_tc_queue(dev, i, q, offset);
4406 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004407 }
4408
John Fastabende901acd2011-04-26 07:26:08 +00004409 adapter->num_tx_queues = q * tcs;
4410 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004411
4412#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004413 /* FCoE enabled queues require special configuration indexed
4414 * by feature specific indices and mask. Here we map FCoE
4415 * indices onto the DCB queue pairs allowing FCoE to own
4416 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004417 */
John Fastabende901acd2011-04-26 07:26:08 +00004418 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
John Fastabendcdf485b2012-02-11 06:26:00 +00004419 u8 prio_tc[MAX_USER_PRIORITY] = {0};
John Fastabende901acd2011-04-26 07:26:08 +00004420 int tc;
4421 struct ixgbe_ring_feature *f =
4422 &adapter->ring_feature[RING_F_FCOE];
4423
John Fastabendcdf485b2012-02-11 06:26:00 +00004424 ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc);
4425 tc = prio_tc[adapter->fcoe.up];
John Fastabende901acd2011-04-26 07:26:08 +00004426 f->indices = dev->tc_to_txq[tc].count;
4427 f->mask = dev->tc_to_txq[tc].offset;
4428 }
John Fastabende5b64632011-03-08 03:44:52 +00004429#endif
4430
John Fastabende901acd2011-04-26 07:26:08 +00004431 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004432}
John Fastabende5b64632011-03-08 03:44:52 +00004433#endif
Yi Zou0331a832009-05-17 12:33:52 +00004434
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004435/**
4436 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4437 * @adapter: board private structure to initialize
4438 *
4439 * IOV doesn't actually use anything, so just NAK the
4440 * request for now and let the other queue routines
4441 * figure out what to do.
4442 */
4443static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4444{
4445 return false;
4446}
4447
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004448/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004449 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004450 * @adapter: board private structure to initialize
4451 *
4452 * This is the top level queue allocation routine. The order here is very
4453 * important, starting with the "most" number of features turned on at once,
4454 * and ending with the smallest set of features. This way large combinations
4455 * can be allocated if they're turned on, and smaller combinations are the
4456 * fallthrough conditions.
4457 *
4458 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004459static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004460{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004461 /* Start with base case */
4462 adapter->num_rx_queues = 1;
4463 adapter->num_tx_queues = 1;
4464 adapter->num_rx_pools = adapter->num_rx_queues;
4465 adapter->num_rx_queues_per_pool = 1;
4466
4467 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004468 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004469
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004470#ifdef CONFIG_IXGBE_DCB
4471 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004472 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004473
4474#endif
John Fastabende5b64632011-03-08 03:44:52 +00004475#ifdef IXGBE_FCOE
4476 if (ixgbe_set_fcoe_queues(adapter))
4477 goto done;
4478
4479#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004480 if (ixgbe_set_fdir_queues(adapter))
4481 goto done;
4482
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004483 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004484 goto done;
4485
4486 /* fallback to base case */
4487 adapter->num_rx_queues = 1;
4488 adapter->num_tx_queues = 1;
4489
4490done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004491 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4492 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4493 return 0;
4494
Ben Hutchings847f53f2010-09-27 08:28:56 +00004495 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004496 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004497 return netif_set_real_num_rx_queues(adapter->netdev,
4498 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004499}
4500
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004501static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004502 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004503{
4504 int err, vector_threshold;
4505
Alexander Duyck8f154862012-02-10 02:08:37 +00004506 /* We'll want at least 2 (vector_threshold):
4507 * 1) TxQ[0] + RxQ[0] handler
4508 * 2) Other (Link Status Change, etc.)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004509 */
4510 vector_threshold = MIN_MSIX_COUNT;
4511
Alexander Duyck24ddd962012-02-10 02:08:32 +00004512 /*
4513 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004514 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4515 * Right now, we simply care about how many we'll get; we'll
4516 * set them up later while requesting irq's.
4517 */
4518 while (vectors >= vector_threshold) {
4519 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004520 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004521 if (!err) /* Success in acquiring all requested vectors. */
4522 break;
4523 else if (err < 0)
4524 vectors = 0; /* Nasty failure, quit now */
4525 else /* err == number of vectors we should try again with */
4526 vectors = err;
4527 }
4528
4529 if (vectors < vector_threshold) {
4530 /* Can't allocate enough MSI-X interrupts? Oh well.
4531 * This just means we'll go with either a single MSI
4532 * vector or fall back to legacy interrupts.
4533 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004534 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4535 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004536 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4537 kfree(adapter->msix_entries);
4538 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004539 } else {
4540 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004541 /*
4542 * Adjust for only the vectors we'll use, which is minimum
4543 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4544 * vectors we were allocated.
4545 */
4546 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004547 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004548 }
4549}
4550
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004551/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004552 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004553 * @adapter: board private structure to initialize
4554 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004555 * Cache the descriptor ring offsets for RSS to the assigned rings.
4556 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004557 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004558static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004559{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004560 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004561
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004562 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4563 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004564
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004565 for (i = 0; i < adapter->num_rx_queues; i++)
4566 adapter->rx_ring[i]->reg_idx = i;
4567 for (i = 0; i < adapter->num_tx_queues; i++)
4568 adapter->tx_ring[i]->reg_idx = i;
4569
4570 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004571}
4572
4573#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004574
4575/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004576static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4577 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004578{
4579 struct net_device *dev = adapter->netdev;
4580 struct ixgbe_hw *hw = &adapter->hw;
4581 u8 num_tcs = netdev_get_num_tc(dev);
4582
4583 *tx = 0;
4584 *rx = 0;
4585
4586 switch (hw->mac.type) {
4587 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004588 *tx = tc << 2;
4589 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004590 break;
4591 case ixgbe_mac_82599EB:
4592 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004593 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004594 if (tc < 3) {
4595 *tx = tc << 5;
4596 *rx = tc << 4;
4597 } else if (tc < 5) {
4598 *tx = ((tc + 2) << 4);
4599 *rx = tc << 4;
4600 } else if (tc < num_tcs) {
4601 *tx = ((tc + 8) << 3);
4602 *rx = tc << 4;
4603 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004604 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004605 *rx = tc << 5;
4606 switch (tc) {
4607 case 0:
4608 *tx = 0;
4609 break;
4610 case 1:
4611 *tx = 64;
4612 break;
4613 case 2:
4614 *tx = 96;
4615 break;
4616 case 3:
4617 *tx = 112;
4618 break;
4619 default:
4620 break;
4621 }
4622 }
4623 break;
4624 default:
4625 break;
4626 }
4627}
4628
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004629/**
4630 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4631 * @adapter: board private structure to initialize
4632 *
4633 * Cache the descriptor ring offsets for DCB to the assigned rings.
4634 *
4635 **/
4636static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4637{
John Fastabende5b64632011-03-08 03:44:52 +00004638 struct net_device *dev = adapter->netdev;
4639 int i, j, k;
4640 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004641
John Fastabend8b1c0b22011-05-03 02:26:48 +00004642 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004643 return false;
4644
John Fastabende5b64632011-03-08 03:44:52 +00004645 for (i = 0, k = 0; i < num_tcs; i++) {
4646 unsigned int tx_s, rx_s;
4647 u16 count = dev->tc_to_txq[i].count;
4648
4649 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4650 for (j = 0; j < count; j++, k++) {
4651 adapter->tx_ring[k]->reg_idx = tx_s + j;
4652 adapter->rx_ring[k]->reg_idx = rx_s + j;
4653 adapter->tx_ring[k]->dcb_tc = i;
4654 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004655 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004656 }
John Fastabende5b64632011-03-08 03:44:52 +00004657
4658 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004659}
4660#endif
4661
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004662/**
4663 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4664 * @adapter: board private structure to initialize
4665 *
4666 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4667 *
4668 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004669static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004670{
4671 int i;
4672 bool ret = false;
4673
Alexander Duyck03ecf912011-05-20 07:36:17 +00004674 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4675 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004676 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004677 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004678 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004679 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004680 ret = true;
4681 }
4682
4683 return ret;
4684}
4685
Yi Zou0331a832009-05-17 12:33:52 +00004686#ifdef IXGBE_FCOE
4687/**
4688 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4689 * @adapter: board private structure to initialize
4690 *
4691 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4692 *
4693 */
4694static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4695{
Yi Zou0331a832009-05-17 12:33:52 +00004696 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004697 int i;
4698 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004699
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004700 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4701 return false;
4702
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004703 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004704 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004705 ixgbe_cache_ring_fdir(adapter);
4706 else
4707 ixgbe_cache_ring_rss(adapter);
4708
4709 fcoe_rx_i = f->mask;
4710 fcoe_tx_i = f->mask;
4711 }
4712 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4713 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4714 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4715 }
4716 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004717}
4718
4719#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004720/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004721 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4722 * @adapter: board private structure to initialize
4723 *
4724 * SR-IOV doesn't use any descriptor rings but changes the default if
4725 * no other mapping is used.
4726 *
4727 */
4728static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4729{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004730 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4731 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004732 if (adapter->num_vfs)
4733 return true;
4734 else
4735 return false;
4736}
4737
4738/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004739 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4740 * @adapter: board private structure to initialize
4741 *
4742 * Once we know the feature-set enabled for the device, we'll cache
4743 * the register offset the descriptor ring is assigned to.
4744 *
4745 * Note, the order the various feature calls is important. It must start with
4746 * the "most" features enabled at the same time, then trickle down to the
4747 * least amount of features turned on at once.
4748 **/
4749static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4750{
4751 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004752 adapter->rx_ring[0]->reg_idx = 0;
4753 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004754
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004755 if (ixgbe_cache_ring_sriov(adapter))
4756 return;
4757
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004758#ifdef CONFIG_IXGBE_DCB
4759 if (ixgbe_cache_ring_dcb(adapter))
4760 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004761#endif
John Fastabende5b64632011-03-08 03:44:52 +00004762
4763#ifdef IXGBE_FCOE
4764 if (ixgbe_cache_ring_fcoe(adapter))
4765 return;
4766#endif /* IXGBE_FCOE */
4767
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004768 if (ixgbe_cache_ring_fdir(adapter))
4769 return;
4770
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004771 if (ixgbe_cache_ring_rss(adapter))
4772 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004773}
4774
Auke Kok9a799d72007-09-15 14:07:45 -07004775/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004776 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4777 * @adapter: board private structure to initialize
4778 *
4779 * Attempt to configure the interrupts using the best available
4780 * capabilities of the hardware and the kernel.
4781 **/
Al Virofeea6a52008-11-27 15:34:07 -08004782static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004783{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004784 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004785 int err = 0;
4786 int vector, v_budget;
4787
4788 /*
4789 * It's easy to be greedy for MSI-X vectors, but it really
4790 * doesn't do us much good if we have a lot more vectors
4791 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004792 * (roughly) the same number of vectors as there are CPU's.
Alexander Duyck8f154862012-02-10 02:08:37 +00004793 * The default is to use pairs of vectors.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004794 */
Alexander Duyck8f154862012-02-10 02:08:37 +00004795 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
4796 v_budget = min_t(int, v_budget, num_online_cpus());
4797 v_budget += NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004798
4799 /*
4800 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004801 * hw.mac->max_msix_vectors vectors. With features
4802 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4803 * descriptor queues supported by our device. Thus, we cap it off in
4804 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004805 */
Alexander Duyckde88eee2012-02-08 07:49:59 +00004806 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004807
4808 /* A failure in MSI-X entry allocation isn't fatal, but it does
4809 * mean we disable MSI-X capabilities of the adapter. */
4810 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004811 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004812 if (adapter->msix_entries) {
4813 for (vector = 0; vector < v_budget; vector++)
4814 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004815
Alexander Duyck7a921c92009-05-06 10:43:28 +00004816 ixgbe_acquire_msix_vectors(adapter, v_budget);
4817
4818 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4819 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004820 }
David S. Miller26d27842010-05-03 15:18:22 -07004821
Alexander Duyck7a921c92009-05-06 10:43:28 +00004822 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4823 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004824 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004825 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004826 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004827 "queues are disabled. Disabling Flow Director\n");
4828 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004829 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004830 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004831 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4832 ixgbe_disable_sriov(adapter);
4833
Ben Hutchings847f53f2010-09-27 08:28:56 +00004834 err = ixgbe_set_num_queues(adapter);
4835 if (err)
4836 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004837
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004838 err = pci_enable_msi(adapter->pdev);
4839 if (!err) {
4840 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4841 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004842 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4843 "Unable to allocate MSI interrupt, "
4844 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004845 /* reset err */
4846 err = 0;
4847 }
4848
4849out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004850 return err;
4851}
4852
Alexander Duyckde88eee2012-02-08 07:49:59 +00004853static void ixgbe_add_ring(struct ixgbe_ring *ring,
4854 struct ixgbe_ring_container *head)
4855{
4856 ring->next = head->ring;
4857 head->ring = ring;
4858 head->count++;
4859}
4860
4861/**
4862 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
4863 * @adapter: board private structure to initialize
4864 * @v_idx: index of vector in adapter struct
4865 *
4866 * We allocate one q_vector. If allocation fails we return -ENOMEM.
4867 **/
4868static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
4869 int txr_count, int txr_idx,
4870 int rxr_count, int rxr_idx)
4871{
4872 struct ixgbe_q_vector *q_vector;
4873 struct ixgbe_ring *ring;
4874 int node = -1;
4875 int cpu = -1;
4876 int ring_count, size;
4877
4878 ring_count = txr_count + rxr_count;
4879 size = sizeof(struct ixgbe_q_vector) +
4880 (sizeof(struct ixgbe_ring) * ring_count);
4881
4882 /* customize cpu for Flow Director mapping */
4883 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4884 if (cpu_online(v_idx)) {
4885 cpu = v_idx;
4886 node = cpu_to_node(cpu);
4887 }
4888 }
4889
4890 /* allocate q_vector and rings */
4891 q_vector = kzalloc_node(size, GFP_KERNEL, node);
4892 if (!q_vector)
4893 q_vector = kzalloc(size, GFP_KERNEL);
4894 if (!q_vector)
4895 return -ENOMEM;
4896
4897 /* setup affinity mask and node */
4898 if (cpu != -1)
4899 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
4900 else
4901 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
4902 q_vector->numa_node = node;
4903
4904 /* initialize NAPI */
4905 netif_napi_add(adapter->netdev, &q_vector->napi,
4906 ixgbe_poll, 64);
4907
4908 /* tie q_vector and adapter together */
4909 adapter->q_vector[v_idx] = q_vector;
4910 q_vector->adapter = adapter;
4911 q_vector->v_idx = v_idx;
4912
4913 /* initialize work limits */
4914 q_vector->tx.work_limit = adapter->tx_work_limit;
4915
4916 /* initialize pointer to rings */
4917 ring = q_vector->ring;
4918
4919 while (txr_count) {
4920 /* assign generic ring traits */
4921 ring->dev = &adapter->pdev->dev;
4922 ring->netdev = adapter->netdev;
4923
4924 /* configure backlink on ring */
4925 ring->q_vector = q_vector;
4926
4927 /* update q_vector Tx values */
4928 ixgbe_add_ring(ring, &q_vector->tx);
4929
4930 /* apply Tx specific ring traits */
4931 ring->count = adapter->tx_ring_count;
4932 ring->queue_index = txr_idx;
4933
4934 /* assign ring to adapter */
4935 adapter->tx_ring[txr_idx] = ring;
4936
4937 /* update count and index */
4938 txr_count--;
4939 txr_idx++;
4940
4941 /* push pointer to next ring */
4942 ring++;
4943 }
4944
4945 while (rxr_count) {
4946 /* assign generic ring traits */
4947 ring->dev = &adapter->pdev->dev;
4948 ring->netdev = adapter->netdev;
4949
4950 /* configure backlink on ring */
4951 ring->q_vector = q_vector;
4952
4953 /* update q_vector Rx values */
4954 ixgbe_add_ring(ring, &q_vector->rx);
4955
4956 /*
4957 * 82599 errata, UDP frames with a 0 checksum
4958 * can be marked as checksum errors.
4959 */
4960 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4961 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4962
4963 /* apply Rx specific ring traits */
4964 ring->count = adapter->rx_ring_count;
4965 ring->queue_index = rxr_idx;
4966
4967 /* assign ring to adapter */
4968 adapter->rx_ring[rxr_idx] = ring;
4969
4970 /* update count and index */
4971 rxr_count--;
4972 rxr_idx++;
4973
4974 /* push pointer to next ring */
4975 ring++;
4976 }
4977
4978 return 0;
4979}
4980
4981/**
4982 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
4983 * @adapter: board private structure to initialize
4984 * @v_idx: Index of vector to be freed
4985 *
4986 * This function frees the memory allocated to the q_vector. In addition if
4987 * NAPI is enabled it will delete any references to the NAPI struct prior
4988 * to freeing the q_vector.
4989 **/
4990static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
4991{
4992 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4993 struct ixgbe_ring *ring;
4994
Alexander Duycka5579282012-02-08 07:50:04 +00004995 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004996 adapter->tx_ring[ring->queue_index] = NULL;
4997
Alexander Duycka5579282012-02-08 07:50:04 +00004998 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004999 adapter->rx_ring[ring->queue_index] = NULL;
5000
5001 adapter->q_vector[v_idx] = NULL;
5002 netif_napi_del(&q_vector->napi);
5003
5004 /*
5005 * ixgbe_get_stats64() might access the rings on this vector,
5006 * we must wait a grace period before freeing it.
5007 */
5008 kfree_rcu(q_vector, rcu);
5009}
5010
Alexander Duyck7a921c92009-05-06 10:43:28 +00005011/**
5012 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
5013 * @adapter: board private structure to initialize
5014 *
5015 * We allocate one q_vector per queue interrupt. If allocation fails we
5016 * return -ENOMEM.
5017 **/
5018static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5019{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005020 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5021 int rxr_remaining = adapter->num_rx_queues;
5022 int txr_remaining = adapter->num_tx_queues;
5023 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
5024 int err;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005025
Alexander Duyckde88eee2012-02-08 07:49:59 +00005026 /* only one q_vector if MSI-X is disabled. */
5027 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
5028 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005029
Alexander Duyckde88eee2012-02-08 07:49:59 +00005030 if (q_vectors >= (rxr_remaining + txr_remaining)) {
5031 for (; rxr_remaining; v_idx++, q_vectors--) {
5032 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5033 err = ixgbe_alloc_q_vector(adapter, v_idx,
5034 0, 0, rqpv, rxr_idx);
5035
5036 if (err)
5037 goto err_out;
5038
5039 /* update counts and index */
5040 rxr_remaining -= rqpv;
5041 rxr_idx += rqpv;
5042 }
5043 }
5044
5045 for (; q_vectors; v_idx++, q_vectors--) {
5046 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5047 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors);
5048 err = ixgbe_alloc_q_vector(adapter, v_idx,
5049 tqpv, txr_idx,
5050 rqpv, rxr_idx);
5051
5052 if (err)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005053 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005054
Alexander Duyckde88eee2012-02-08 07:49:59 +00005055 /* update counts and index */
5056 rxr_remaining -= rqpv;
5057 rxr_idx += rqpv;
5058 txr_remaining -= tqpv;
5059 txr_idx += tqpv;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005060 }
5061
5062 return 0;
5063
5064err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005065 while (v_idx) {
5066 v_idx--;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005067 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005068 }
Alexander Duyckde88eee2012-02-08 07:49:59 +00005069
Alexander Duyck7a921c92009-05-06 10:43:28 +00005070 return -ENOMEM;
5071}
5072
5073/**
5074 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5075 * @adapter: board private structure to initialize
5076 *
5077 * This function frees the memory allocated to the q_vectors. In addition if
5078 * NAPI is enabled it will delete any references to the NAPI struct prior
5079 * to freeing the q_vector.
5080 **/
5081static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5082{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005083 int v_idx, q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005084
Alexander Duyck91281fd2009-06-04 16:00:27 +00005085 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005086 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005087 else
Alexander Duyckde88eee2012-02-08 07:49:59 +00005088 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005089
Alexander Duyckde88eee2012-02-08 07:49:59 +00005090 for (v_idx = 0; v_idx < q_vectors; v_idx++)
5091 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005092}
5093
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005094static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005095{
5096 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5097 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5098 pci_disable_msix(adapter->pdev);
5099 kfree(adapter->msix_entries);
5100 adapter->msix_entries = NULL;
5101 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5102 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5103 pci_disable_msi(adapter->pdev);
5104 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005105}
5106
5107/**
5108 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5109 * @adapter: board private structure to initialize
5110 *
5111 * We determine which interrupt scheme to use based on...
5112 * - Kernel support (MSI, MSI-X)
5113 * - which can be user-defined (via MODULE_PARAM)
5114 * - Hardware queue count (num_*_queues)
5115 * - defined by miscellaneous hardware support/features (RSS, etc.)
5116 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005117int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005118{
5119 int err;
5120
5121 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005122 err = ixgbe_set_num_queues(adapter);
5123 if (err)
5124 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005125
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005126 err = ixgbe_set_interrupt_capability(adapter);
5127 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005128 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005129 goto err_set_interrupt;
5130 }
5131
Alexander Duyck7a921c92009-05-06 10:43:28 +00005132 err = ixgbe_alloc_q_vectors(adapter);
5133 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005134 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005135 goto err_alloc_q_vectors;
5136 }
5137
Alexander Duyckde88eee2012-02-08 07:49:59 +00005138 ixgbe_cache_ring_register(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005139
Emil Tantilov849c4542010-06-03 16:53:41 +00005140 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005141 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5142 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005143
5144 set_bit(__IXGBE_DOWN, &adapter->state);
5145
5146 return 0;
5147
Alexander Duyck7a921c92009-05-06 10:43:28 +00005148err_alloc_q_vectors:
5149 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005150err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005151 return err;
5152}
5153
5154/**
5155 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5156 * @adapter: board private structure to clear interrupt scheme on
5157 *
5158 * We go through and clear interrupt specific resources and reset the structure
5159 * to pre-load conditions
5160 **/
5161void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5162{
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005163 adapter->num_tx_queues = 0;
5164 adapter->num_rx_queues = 0;
5165
Alexander Duyck7a921c92009-05-06 10:43:28 +00005166 ixgbe_free_q_vectors(adapter);
5167 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005168}
5169
5170/**
5171 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5172 * @adapter: board private structure to initialize
5173 *
5174 * ixgbe_sw_init initializes the Adapter private data structure.
5175 * Fields are initialized based on PCI device information and
5176 * OS network device settings (MTU size).
5177 **/
5178static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5179{
5180 struct ixgbe_hw *hw = &adapter->hw;
5181 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005182 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005183#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005184 int j;
5185 struct tc_configuration *tc;
5186#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005187
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005188 /* PCI config space info */
5189
5190 hw->vendor_id = pdev->vendor;
5191 hw->device_id = pdev->device;
5192 hw->revision_id = pdev->revision;
5193 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5194 hw->subsystem_device_id = pdev->subsystem_device;
5195
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005196 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005197 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005198 adapter->ring_feature[RING_F_RSS].indices = rss;
5199 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005200 switch (hw->mac.type) {
5201 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005202 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5203 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005204 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005205 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005206 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005207 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5208 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005209 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005210 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5211 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005212 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5213 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005214 /* Flow Director hash filters enabled */
5215 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5216 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005217 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005218 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005219 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005220#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005221 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5222 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5223 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005224#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005225 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005226 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005227#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005228#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005229 break;
5230 default:
5231 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005232 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005233
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005234 /* n-tuple support exists, always init our spinlock */
5235 spin_lock_init(&adapter->fdir_perfect_lock);
5236
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005237#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005238 switch (hw->mac.type) {
5239 case ixgbe_mac_X540:
5240 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5241 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5242 break;
5243 default:
5244 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5245 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5246 break;
5247 }
5248
Alexander Duyck2f90b862008-11-20 20:52:10 -08005249 /* Configure DCB traffic classes */
5250 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5251 tc = &adapter->dcb_cfg.tc_config[j];
5252 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5253 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5254 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5255 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5256 tc->dcb_pfc = pfc_disabled;
5257 }
John Fastabend4de2a022011-09-27 03:52:01 +00005258
5259 /* Initialize default user to priority mapping, UPx->TC0 */
5260 tc = &adapter->dcb_cfg.tc_config[0];
5261 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5262 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5263
Alexander Duyck2f90b862008-11-20 20:52:10 -08005264 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5265 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005266 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005267 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005268 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005269 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005270 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005271
5272#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005273
5274 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005275 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005276 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005277#ifdef CONFIG_DCB
5278 adapter->last_lfc_mode = hw->fc.current_mode;
5279#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005280 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005281 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5282 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005283 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005284
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005285 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005286 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005287 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005288
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005289 /* set default ring sizes */
5290 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5291 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5292
Alexander Duyckbd198052011-06-11 01:45:08 +00005293 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005294 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005295
Auke Kok9a799d72007-09-15 14:07:45 -07005296 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005297 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005298 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005299 return -EIO;
5300 }
5301
Auke Kok9a799d72007-09-15 14:07:45 -07005302 set_bit(__IXGBE_DOWN, &adapter->state);
5303
5304 return 0;
5305}
5306
5307/**
5308 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005309 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005310 *
5311 * Return 0 on success, negative on failure
5312 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005313int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005314{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005315 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005316 int orig_node = dev_to_node(dev);
5317 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005318 int size;
5319
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005320 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005321
5322 if (tx_ring->q_vector)
5323 numa_node = tx_ring->q_vector->numa_node;
5324
5325 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005326 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005327 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005328 if (!tx_ring->tx_buffer_info)
5329 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005330
5331 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005332 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005333 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005334
Alexander Duyckde88eee2012-02-08 07:49:59 +00005335 set_dev_node(dev, numa_node);
5336 tx_ring->desc = dma_alloc_coherent(dev,
5337 tx_ring->size,
5338 &tx_ring->dma,
5339 GFP_KERNEL);
5340 set_dev_node(dev, orig_node);
5341 if (!tx_ring->desc)
5342 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5343 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005344 if (!tx_ring->desc)
5345 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005346
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005347 tx_ring->next_to_use = 0;
5348 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005349 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005350
5351err:
5352 vfree(tx_ring->tx_buffer_info);
5353 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005354 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005355 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005356}
5357
5358/**
Alexander Duyck69888672008-09-11 20:05:39 -07005359 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5360 * @adapter: board private structure
5361 *
5362 * If this function returns with an error, then it's possible one or
5363 * more of the rings is populated (while the rest are not). It is the
5364 * callers duty to clean those orphaned rings.
5365 *
5366 * Return 0 on success, negative on failure
5367 **/
5368static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5369{
5370 int i, err = 0;
5371
5372 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005373 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005374 if (!err)
5375 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005376 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005377 break;
5378 }
5379
5380 return err;
5381}
5382
5383/**
Auke Kok9a799d72007-09-15 14:07:45 -07005384 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005385 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005386 *
5387 * Returns 0 on success, negative on failure
5388 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005389int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005390{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005391 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005392 int orig_node = dev_to_node(dev);
5393 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005394 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005395
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005396 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005397
5398 if (rx_ring->q_vector)
5399 numa_node = rx_ring->q_vector->numa_node;
5400
5401 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005402 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005403 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005404 if (!rx_ring->rx_buffer_info)
5405 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005406
Auke Kok9a799d72007-09-15 14:07:45 -07005407 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005408 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5409 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005410
Alexander Duyckde88eee2012-02-08 07:49:59 +00005411 set_dev_node(dev, numa_node);
5412 rx_ring->desc = dma_alloc_coherent(dev,
5413 rx_ring->size,
5414 &rx_ring->dma,
5415 GFP_KERNEL);
5416 set_dev_node(dev, orig_node);
5417 if (!rx_ring->desc)
5418 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5419 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005420 if (!rx_ring->desc)
5421 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005422
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005423 rx_ring->next_to_clean = 0;
5424 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005425
Alexander Duyckf8003262012-03-03 02:35:52 +00005426 ixgbe_init_rx_page_offset(rx_ring);
5427
Auke Kok9a799d72007-09-15 14:07:45 -07005428 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005429err:
5430 vfree(rx_ring->rx_buffer_info);
5431 rx_ring->rx_buffer_info = NULL;
5432 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005433 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005434}
5435
5436/**
Alexander Duyck69888672008-09-11 20:05:39 -07005437 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5438 * @adapter: board private structure
5439 *
5440 * If this function returns with an error, then it's possible one or
5441 * more of the rings is populated (while the rest are not). It is the
5442 * callers duty to clean those orphaned rings.
5443 *
5444 * Return 0 on success, negative on failure
5445 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005446static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5447{
5448 int i, err = 0;
5449
5450 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005451 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005452 if (!err)
5453 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005454 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005455 break;
5456 }
5457
5458 return err;
5459}
5460
5461/**
Auke Kok9a799d72007-09-15 14:07:45 -07005462 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005463 * @tx_ring: Tx descriptor ring for a specific queue
5464 *
5465 * Free all transmit software resources
5466 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005467void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005468{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005469 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005470
5471 vfree(tx_ring->tx_buffer_info);
5472 tx_ring->tx_buffer_info = NULL;
5473
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005474 /* if not set, then don't free */
5475 if (!tx_ring->desc)
5476 return;
5477
5478 dma_free_coherent(tx_ring->dev, tx_ring->size,
5479 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005480
5481 tx_ring->desc = NULL;
5482}
5483
5484/**
5485 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5486 * @adapter: board private structure
5487 *
5488 * Free all transmit software resources
5489 **/
5490static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5491{
5492 int i;
5493
5494 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005495 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005496 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005497}
5498
5499/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005500 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005501 * @rx_ring: ring to clean the resources from
5502 *
5503 * Free all receive software resources
5504 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005505void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005506{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005507 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005508
5509 vfree(rx_ring->rx_buffer_info);
5510 rx_ring->rx_buffer_info = NULL;
5511
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005512 /* if not set, then don't free */
5513 if (!rx_ring->desc)
5514 return;
5515
5516 dma_free_coherent(rx_ring->dev, rx_ring->size,
5517 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005518
5519 rx_ring->desc = NULL;
5520}
5521
5522/**
5523 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5524 * @adapter: board private structure
5525 *
5526 * Free all receive software resources
5527 **/
5528static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5529{
5530 int i;
5531
5532 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005533 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005534 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005535}
5536
5537/**
Auke Kok9a799d72007-09-15 14:07:45 -07005538 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5539 * @netdev: network interface device structure
5540 * @new_mtu: new value for maximum frame size
5541 *
5542 * Returns 0 on success, negative on failure
5543 **/
5544static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5545{
5546 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5547 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5548
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005549 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005550 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5551 return -EINVAL;
5552
5553 /*
5554 * For 82599EB we cannot allow PF to change MTU greater than 1500
5555 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
5556 * don't allocate and chain buffers correctly.
5557 */
5558 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5559 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
5560 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00005561 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07005562
Emil Tantilov396e7992010-07-01 20:05:12 +00005563 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005564
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005565 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005566 netdev->mtu = new_mtu;
5567
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005568 if (netif_running(netdev))
5569 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005570
5571 return 0;
5572}
5573
5574/**
5575 * ixgbe_open - Called when a network interface is made active
5576 * @netdev: network interface device structure
5577 *
5578 * Returns 0 on success, negative value on failure
5579 *
5580 * The open entry point is called when a network interface is made
5581 * active by the system (IFF_UP). At this point all resources needed
5582 * for transmit and receive operations are allocated, the interrupt
5583 * handler is registered with the OS, the watchdog timer is started,
5584 * and the stack is notified that the interface is ready.
5585 **/
5586static int ixgbe_open(struct net_device *netdev)
5587{
5588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5589 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005590
Auke Kok4bebfaa2008-02-11 09:26:01 -08005591 /* disallow open during test */
5592 if (test_bit(__IXGBE_TESTING, &adapter->state))
5593 return -EBUSY;
5594
Jesse Brandeburg54386462009-04-17 20:44:27 +00005595 netif_carrier_off(netdev);
5596
Auke Kok9a799d72007-09-15 14:07:45 -07005597 /* allocate transmit descriptors */
5598 err = ixgbe_setup_all_tx_resources(adapter);
5599 if (err)
5600 goto err_setup_tx;
5601
Auke Kok9a799d72007-09-15 14:07:45 -07005602 /* allocate receive descriptors */
5603 err = ixgbe_setup_all_rx_resources(adapter);
5604 if (err)
5605 goto err_setup_rx;
5606
5607 ixgbe_configure(adapter);
5608
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005609 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005610 if (err)
5611 goto err_req_irq;
5612
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005613 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005614
5615 return 0;
5616
Auke Kok9a799d72007-09-15 14:07:45 -07005617err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005618err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005619 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005620err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005621 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005622 ixgbe_reset(adapter);
5623
5624 return err;
5625}
5626
5627/**
5628 * ixgbe_close - Disables a network interface
5629 * @netdev: network interface device structure
5630 *
5631 * Returns 0, this is not allowed to fail
5632 *
5633 * The close entry point is called when an interface is de-activated
5634 * by the OS. The hardware is still under the drivers control, but
5635 * needs to be disabled. A global MAC reset is issued to stop the
5636 * hardware, and all transmit and receive resources are freed.
5637 **/
5638static int ixgbe_close(struct net_device *netdev)
5639{
5640 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005641
5642 ixgbe_down(adapter);
5643 ixgbe_free_irq(adapter);
5644
Alexander Duycke4911d52011-05-11 07:18:52 +00005645 ixgbe_fdir_filter_exit(adapter);
5646
Auke Kok9a799d72007-09-15 14:07:45 -07005647 ixgbe_free_all_tx_resources(adapter);
5648 ixgbe_free_all_rx_resources(adapter);
5649
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005650 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005651
5652 return 0;
5653}
5654
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005655#ifdef CONFIG_PM
5656static int ixgbe_resume(struct pci_dev *pdev)
5657{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005658 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5659 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005660 u32 err;
5661
5662 pci_set_power_state(pdev, PCI_D0);
5663 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005664 /*
5665 * pci_restore_state clears dev->state_saved so call
5666 * pci_save_state to restore it.
5667 */
5668 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005669
5670 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005671 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005672 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005673 return err;
5674 }
5675 pci_set_master(pdev);
5676
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005677 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005678
5679 err = ixgbe_init_interrupt_scheme(adapter);
5680 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005681 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005682 return err;
5683 }
5684
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005685 ixgbe_reset(adapter);
5686
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005687 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5688
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005689 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005690 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005691 if (err)
5692 return err;
5693 }
5694
5695 netif_device_attach(netdev);
5696
5697 return 0;
5698}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005699#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005700
5701static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005702{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005703 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5704 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005705 struct ixgbe_hw *hw = &adapter->hw;
5706 u32 ctrl, fctrl;
5707 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005708#ifdef CONFIG_PM
5709 int retval = 0;
5710#endif
5711
5712 netif_device_detach(netdev);
5713
5714 if (netif_running(netdev)) {
5715 ixgbe_down(adapter);
5716 ixgbe_free_irq(adapter);
5717 ixgbe_free_all_tx_resources(adapter);
5718 ixgbe_free_all_rx_resources(adapter);
5719 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005720
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005721 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005722#ifdef CONFIG_DCB
5723 kfree(adapter->ixgbe_ieee_pfc);
5724 kfree(adapter->ixgbe_ieee_ets);
5725#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005726
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005727#ifdef CONFIG_PM
5728 retval = pci_save_state(pdev);
5729 if (retval)
5730 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005731
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005732#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005733 if (wufc) {
5734 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005735
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005736 /* turn on all-multi mode if wake on multicast is enabled */
5737 if (wufc & IXGBE_WUFC_MC) {
5738 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5739 fctrl |= IXGBE_FCTRL_MPE;
5740 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5741 }
5742
5743 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5744 ctrl |= IXGBE_CTRL_GIO_DIS;
5745 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5746
5747 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5748 } else {
5749 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5750 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5751 }
5752
Alexander Duyckbd508172010-11-16 19:27:03 -08005753 switch (hw->mac.type) {
5754 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005755 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005756 break;
5757 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005758 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005759 pci_wake_from_d3(pdev, !!wufc);
5760 break;
5761 default:
5762 break;
5763 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005764
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005765 *enable_wake = !!wufc;
5766
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005767 ixgbe_release_hw_control(adapter);
5768
5769 pci_disable_device(pdev);
5770
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005771 return 0;
5772}
5773
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005774#ifdef CONFIG_PM
5775static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5776{
5777 int retval;
5778 bool wake;
5779
5780 retval = __ixgbe_shutdown(pdev, &wake);
5781 if (retval)
5782 return retval;
5783
5784 if (wake) {
5785 pci_prepare_to_sleep(pdev);
5786 } else {
5787 pci_wake_from_d3(pdev, false);
5788 pci_set_power_state(pdev, PCI_D3hot);
5789 }
5790
5791 return 0;
5792}
5793#endif /* CONFIG_PM */
5794
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005795static void ixgbe_shutdown(struct pci_dev *pdev)
5796{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005797 bool wake;
5798
5799 __ixgbe_shutdown(pdev, &wake);
5800
5801 if (system_state == SYSTEM_POWER_OFF) {
5802 pci_wake_from_d3(pdev, wake);
5803 pci_set_power_state(pdev, PCI_D3hot);
5804 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005805}
5806
5807/**
Auke Kok9a799d72007-09-15 14:07:45 -07005808 * ixgbe_update_stats - Update the board statistics counters.
5809 * @adapter: board private structure
5810 **/
5811void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5812{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005813 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005814 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005815 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005816 u64 total_mpc = 0;
5817 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005818 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5819 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005820 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005821#ifdef IXGBE_FCOE
5822 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5823 unsigned int cpu;
5824 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5825#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005826
Don Skidmored08935c2010-06-11 13:20:29 +00005827 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5828 test_bit(__IXGBE_RESETTING, &adapter->state))
5829 return;
5830
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005831 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005832 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005833 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005834 for (i = 0; i < 16; i++)
5835 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005836 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005837 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005838 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5839 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005840 }
5841 adapter->rsc_total_count = rsc_count;
5842 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005843 }
5844
Alexander Duyck5b7da512010-11-16 19:26:50 -08005845 for (i = 0; i < adapter->num_rx_queues; i++) {
5846 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5847 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5848 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5849 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005850 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005851 bytes += rx_ring->stats.bytes;
5852 packets += rx_ring->stats.packets;
5853 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005854 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005855 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5856 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005857 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005858 netdev->stats.rx_bytes = bytes;
5859 netdev->stats.rx_packets = packets;
5860
5861 bytes = 0;
5862 packets = 0;
5863 /* gather some stats to the adapter struct that are per queue */
5864 for (i = 0; i < adapter->num_tx_queues; i++) {
5865 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5866 restart_queue += tx_ring->tx_stats.restart_queue;
5867 tx_busy += tx_ring->tx_stats.tx_busy;
5868 bytes += tx_ring->stats.bytes;
5869 packets += tx_ring->stats.packets;
5870 }
5871 adapter->restart_queue = restart_queue;
5872 adapter->tx_busy = tx_busy;
5873 netdev->stats.tx_bytes = bytes;
5874 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005875
Joe Perches7ca647b2010-09-07 21:35:40 +00005876 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005877
5878 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005879 for (i = 0; i < 8; i++) {
5880 /* for packet buffers not used, the register should read 0 */
5881 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5882 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005883 hwstats->mpc[i] += mpc;
5884 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005885 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5886 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005887 switch (hw->mac.type) {
5888 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005889 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5890 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5891 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005892 hwstats->pxonrxc[i] +=
5893 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005894 break;
5895 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005896 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005897 hwstats->pxonrxc[i] +=
5898 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005899 break;
5900 default:
5901 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005902 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005903 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005904
5905 /*16 register reads */
5906 for (i = 0; i < 16; i++) {
5907 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5908 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5909 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5910 (hw->mac.type == ixgbe_mac_X540)) {
5911 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5912 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5913 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5914 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5915 }
5916 }
5917
Joe Perches7ca647b2010-09-07 21:35:40 +00005918 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005919 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005920 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005921
John Fastabendc84d3242010-11-16 19:27:12 -08005922 ixgbe_update_xoff_received(adapter);
5923
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005924 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005925 switch (hw->mac.type) {
5926 case ixgbe_mac_82598EB:
5927 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005928 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5929 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5930 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5931 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005932 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005933 /* OS2BMC stats are X540 only*/
5934 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5935 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5936 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5937 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5938 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005939 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005940 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005941 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005942 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005943 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005944 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005945 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005946 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5947 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005948#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005949 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5950 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5951 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5952 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5953 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5954 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005955 /* Add up per cpu counters for total ddp aloc fail */
5956 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5957 for_each_possible_cpu(cpu) {
5958 fcoe_noddp_counts_sum +=
5959 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5960 fcoe_noddp_ext_buff_counts_sum +=
5961 *per_cpu_ptr(fcoe->
5962 pcpu_noddp_ext_buff, cpu);
5963 }
5964 }
5965 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5966 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005967#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005968 break;
5969 default:
5970 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005971 }
Auke Kok9a799d72007-09-15 14:07:45 -07005972 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005973 hwstats->bprc += bprc;
5974 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005975 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005976 hwstats->mprc -= bprc;
5977 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5978 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5979 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5980 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5981 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5982 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5983 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5984 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005985 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005986 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005987 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005988 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005989 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5990 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005991 /*
5992 * 82598 errata - tx of flow control packets is included in tx counters
5993 */
5994 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005995 hwstats->gptc -= xon_off_tot;
5996 hwstats->mptc -= xon_off_tot;
5997 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5998 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5999 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6000 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6001 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6002 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6003 hwstats->ptc64 -= xon_off_tot;
6004 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6005 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6006 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6007 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6008 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6009 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006010
6011 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006012 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006013
6014 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006015 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006016 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006017 netdev->stats.rx_length_errors = hwstats->rlec;
6018 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006019 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006020}
6021
6022/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006023 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6024 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006025 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006026static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006027{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006028 struct ixgbe_hw *hw = &adapter->hw;
6029 int i;
6030
Alexander Duyckd034acf2011-04-27 09:25:34 +00006031 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6032 return;
6033
6034 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6035
6036 /* if interface is down do nothing */
6037 if (test_bit(__IXGBE_DOWN, &adapter->state))
6038 return;
6039
6040 /* do nothing if we are not using signature filters */
6041 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6042 return;
6043
6044 adapter->fdir_overflow++;
6045
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006046 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6047 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006048 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006049 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006050 /* re-enable flow director interrupts */
6051 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006052 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006053 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006054 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006055 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006056}
6057
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006058/**
6059 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6060 * @adapter - pointer to the device adapter structure
6061 *
6062 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006063 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006064 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006065 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006066 */
6067static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6068{
Auke Kok9a799d72007-09-15 14:07:45 -07006069 struct ixgbe_hw *hw = &adapter->hw;
6070 u64 eics = 0;
6071 int i;
6072
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006073 /* If we're down or resetting, just bail */
6074 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6075 test_bit(__IXGBE_RESETTING, &adapter->state))
6076 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006077
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006078 /* Force detection of hung controller */
6079 if (netif_carrier_ok(adapter->netdev)) {
6080 for (i = 0; i < adapter->num_tx_queues; i++)
6081 set_check_for_tx_hang(adapter->tx_ring[i]);
6082 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006083
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006084 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006085 /*
6086 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006087 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006088 * would set *both* EIMS and EICS for any bit in EIAM
6089 */
6090 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6091 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006092 } else {
6093 /* get one bit for every active tx/rx interrupt vector */
6094 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6095 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006096 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006097 eics |= ((u64)1 << i);
6098 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006099 }
6100
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006101 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006102 ixgbe_irq_rearm_queues(adapter, eics);
6103
Alexander Duyckfe49f042009-06-04 16:00:09 +00006104}
6105
6106/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006107 * ixgbe_watchdog_update_link - update the link status
6108 * @adapter - pointer to the device adapter structure
6109 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006110 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006111static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006112{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006113 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006114 u32 link_speed = adapter->link_speed;
6115 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006116 int i;
6117
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006118 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6119 return;
6120
6121 if (hw->mac.ops.check_link) {
6122 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006123 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006124 /* always assume link is up, if no check link function */
6125 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6126 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006127 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006128 if (link_up) {
6129 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6130 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6131 hw->mac.ops.fc_enable(hw, i);
6132 } else {
6133 hw->mac.ops.fc_enable(hw, 0);
6134 }
6135 }
6136
6137 if (link_up ||
6138 time_after(jiffies, (adapter->link_check_timeout +
6139 IXGBE_TRY_LINK_TIMEOUT))) {
6140 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6141 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6142 IXGBE_WRITE_FLUSH(hw);
6143 }
6144
6145 adapter->link_up = link_up;
6146 adapter->link_speed = link_speed;
6147}
6148
6149/**
6150 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6151 * print link up message
6152 * @adapter - pointer to the device adapter structure
6153 **/
6154static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6155{
6156 struct net_device *netdev = adapter->netdev;
6157 struct ixgbe_hw *hw = &adapter->hw;
6158 u32 link_speed = adapter->link_speed;
6159 bool flow_rx, flow_tx;
6160
6161 /* only continue if link was previously down */
6162 if (netif_carrier_ok(netdev))
6163 return;
6164
6165 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6166
6167 switch (hw->mac.type) {
6168 case ixgbe_mac_82598EB: {
6169 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6170 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6171 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6172 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6173 }
6174 break;
6175 case ixgbe_mac_X540:
6176 case ixgbe_mac_82599EB: {
6177 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6178 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6179 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6180 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6181 }
6182 break;
6183 default:
6184 flow_tx = false;
6185 flow_rx = false;
6186 break;
6187 }
6188 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6189 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6190 "10 Gbps" :
6191 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6192 "1 Gbps" :
6193 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6194 "100 Mbps" :
6195 "unknown speed"))),
6196 ((flow_rx && flow_tx) ? "RX/TX" :
6197 (flow_rx ? "RX" :
6198 (flow_tx ? "TX" : "None"))));
6199
6200 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006201 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006202}
6203
6204/**
6205 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6206 * print link down message
6207 * @adapter - pointer to the adapter structure
6208 **/
6209static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6210{
6211 struct net_device *netdev = adapter->netdev;
6212 struct ixgbe_hw *hw = &adapter->hw;
6213
6214 adapter->link_up = false;
6215 adapter->link_speed = 0;
6216
6217 /* only continue if link was up previously */
6218 if (!netif_carrier_ok(netdev))
6219 return;
6220
6221 /* poll for SFP+ cable when link is down */
6222 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6223 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6224
6225 e_info(drv, "NIC Link is Down\n");
6226 netif_carrier_off(netdev);
6227}
6228
6229/**
6230 * ixgbe_watchdog_flush_tx - flush queues on link down
6231 * @adapter - pointer to the device adapter structure
6232 **/
6233static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6234{
6235 int i;
6236 int some_tx_pending = 0;
6237
6238 if (!netif_carrier_ok(adapter->netdev)) {
6239 for (i = 0; i < adapter->num_tx_queues; i++) {
6240 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6241 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6242 some_tx_pending = 1;
6243 break;
6244 }
6245 }
6246
6247 if (some_tx_pending) {
6248 /* We've lost link, so the controller stops DMA,
6249 * but we've got queued Tx work that's never going
6250 * to get done, so reset controller to flush Tx.
6251 * (Do the reset outside of interrupt context).
6252 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006253 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006254 }
6255 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006256}
6257
Greg Rosea985b6c32010-11-18 03:02:52 +00006258static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6259{
6260 u32 ssvpc;
6261
6262 /* Do not perform spoof check for 82598 */
6263 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6264 return;
6265
6266 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6267
6268 /*
6269 * ssvpc register is cleared on read, if zero then no
6270 * spoofed packets in the last interval.
6271 */
6272 if (!ssvpc)
6273 return;
6274
6275 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6276}
6277
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006278/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006279 * ixgbe_watchdog_subtask - check and bring link up
6280 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006281 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006282static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006283{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006284 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006285 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6286 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006287 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006288
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006289 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006290
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006291 if (adapter->link_up)
6292 ixgbe_watchdog_link_is_up(adapter);
6293 else
6294 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006295
Greg Rosea985b6c32010-11-18 03:02:52 +00006296 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006297 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006298
6299 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006300}
6301
Alexander Duyck70864002011-04-27 09:13:56 +00006302/**
6303 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6304 * @adapter - the ixgbe adapter structure
6305 **/
6306static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6307{
6308 struct ixgbe_hw *hw = &adapter->hw;
6309 s32 err;
6310
6311 /* not searching for SFP so there is nothing to do here */
6312 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6313 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6314 return;
6315
6316 /* someone else is in init, wait until next service event */
6317 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6318 return;
6319
6320 err = hw->phy.ops.identify_sfp(hw);
6321 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6322 goto sfp_out;
6323
6324 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6325 /* If no cable is present, then we need to reset
6326 * the next time we find a good cable. */
6327 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6328 }
6329
6330 /* exit on error */
6331 if (err)
6332 goto sfp_out;
6333
6334 /* exit if reset not needed */
6335 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6336 goto sfp_out;
6337
6338 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6339
6340 /*
6341 * A module may be identified correctly, but the EEPROM may not have
6342 * support for that module. setup_sfp() will fail in that case, so
6343 * we should not allow that module to load.
6344 */
6345 if (hw->mac.type == ixgbe_mac_82598EB)
6346 err = hw->phy.ops.reset(hw);
6347 else
6348 err = hw->mac.ops.setup_sfp(hw);
6349
6350 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6351 goto sfp_out;
6352
6353 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6354 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6355
6356sfp_out:
6357 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6358
6359 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6360 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6361 e_dev_err("failed to initialize because an unsupported "
6362 "SFP+ module type was detected.\n");
6363 e_dev_err("Reload the driver after installing a "
6364 "supported module.\n");
6365 unregister_netdev(adapter->netdev);
6366 }
6367}
6368
6369/**
6370 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6371 * @adapter - the ixgbe adapter structure
6372 **/
6373static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6374{
6375 struct ixgbe_hw *hw = &adapter->hw;
6376 u32 autoneg;
6377 bool negotiation;
6378
6379 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6380 return;
6381
6382 /* someone else is in init, wait until next service event */
6383 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6384 return;
6385
6386 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6387
6388 autoneg = hw->phy.autoneg_advertised;
6389 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6390 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006391 if (hw->mac.ops.setup_link)
6392 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6393
6394 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6395 adapter->link_check_timeout = jiffies;
6396 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6397}
6398
Greg Rose83c61fa2011-09-07 05:59:35 +00006399#ifdef CONFIG_PCI_IOV
6400static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6401{
6402 int vf;
6403 struct ixgbe_hw *hw = &adapter->hw;
6404 struct net_device *netdev = adapter->netdev;
6405 u32 gpc;
6406 u32 ciaa, ciad;
6407
6408 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6409 if (gpc) /* If incrementing then no need for the check below */
6410 return;
6411 /*
6412 * Check to see if a bad DMA write target from an errant or
6413 * malicious VF has caused a PCIe error. If so then we can
6414 * issue a VFLR to the offending VF(s) and then resume without
6415 * requesting a full slot reset.
6416 */
6417
6418 for (vf = 0; vf < adapter->num_vfs; vf++) {
6419 ciaa = (vf << 16) | 0x80000000;
6420 /* 32 bit read so align, we really want status at offset 6 */
6421 ciaa |= PCI_COMMAND;
6422 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6423 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6424 ciaa &= 0x7FFFFFFF;
6425 /* disable debug mode asap after reading data */
6426 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6427 /* Get the upper 16 bits which will be the PCI status reg */
6428 ciad >>= 16;
6429 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6430 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6431 /* Issue VFLR */
6432 ciaa = (vf << 16) | 0x80000000;
6433 ciaa |= 0xA8;
6434 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6435 ciad = 0x00008000; /* VFLR */
6436 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6437 ciaa &= 0x7FFFFFFF;
6438 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6439 }
6440 }
6441}
6442
6443#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006444/**
6445 * ixgbe_service_timer - Timer Call-back
6446 * @data: pointer to adapter cast into an unsigned long
6447 **/
6448static void ixgbe_service_timer(unsigned long data)
6449{
6450 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6451 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006452 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006453
Greg Rose83c61fa2011-09-07 05:59:35 +00006454#ifdef CONFIG_PCI_IOV
6455 ready = false;
6456
6457 /*
6458 * don't bother with SR-IOV VF DMA hang check if there are
6459 * no VFs or the link is down
6460 */
6461 if (!adapter->num_vfs ||
6462 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6463 ready = true;
6464 goto normal_timer_service;
6465 }
6466
6467 /* If we have VFs allocated then we must check for DMA hangs */
6468 ixgbe_check_for_bad_vf(adapter);
6469 next_event_offset = HZ / 50;
6470 adapter->timer_event_accumulator++;
6471
6472 if (adapter->timer_event_accumulator >= 100) {
6473 ready = true;
6474 adapter->timer_event_accumulator = 0;
6475 }
6476
6477 goto schedule_event;
6478
6479normal_timer_service:
6480#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006481 /* poll faster when waiting for link */
6482 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6483 next_event_offset = HZ / 10;
6484 else
6485 next_event_offset = HZ * 2;
6486
Greg Rose83c61fa2011-09-07 05:59:35 +00006487#ifdef CONFIG_PCI_IOV
6488schedule_event:
6489#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006490 /* Reset the timer */
6491 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6492
Greg Rose83c61fa2011-09-07 05:59:35 +00006493 if (ready)
6494 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006495}
6496
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006497static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6498{
6499 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6500 return;
6501
6502 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6503
6504 /* If we're already down or resetting, just bail */
6505 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6506 test_bit(__IXGBE_RESETTING, &adapter->state))
6507 return;
6508
6509 ixgbe_dump(adapter);
6510 netdev_err(adapter->netdev, "Reset adapter\n");
6511 adapter->tx_timeout_count++;
6512
6513 ixgbe_reinit_locked(adapter);
6514}
6515
Alexander Duyck70864002011-04-27 09:13:56 +00006516/**
6517 * ixgbe_service_task - manages and runs subtasks
6518 * @work: pointer to work_struct containing our data
6519 **/
6520static void ixgbe_service_task(struct work_struct *work)
6521{
6522 struct ixgbe_adapter *adapter = container_of(work,
6523 struct ixgbe_adapter,
6524 service_task);
6525
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006526 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006527 ixgbe_sfp_detection_subtask(adapter);
6528 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006529 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006530 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006531 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006532 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006533
6534 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006535}
6536
Alexander Duyck897ab152011-05-27 05:31:47 +00006537void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6538 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006539{
6540 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006541 u16 i = tx_ring->next_to_use;
6542
Alexander Duycke4f74022012-01-31 02:59:44 +00006543 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006544
6545 i++;
6546 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6547
6548 /* set bits to identify this as an advanced context descriptor */
6549 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6550
6551 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6552 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6553 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6554 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6555}
6556
6557static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6558 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6559{
Auke Kok9a799d72007-09-15 14:07:45 -07006560 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006561 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006562 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006563
Alexander Duyck897ab152011-05-27 05:31:47 +00006564 if (!skb_is_gso(skb))
6565 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006566
Alexander Duyck897ab152011-05-27 05:31:47 +00006567 if (skb_header_cloned(skb)) {
6568 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6569 if (err)
6570 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006571 }
6572
Alexander Duyck897ab152011-05-27 05:31:47 +00006573 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6574 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6575
6576 if (protocol == __constant_htons(ETH_P_IP)) {
6577 struct iphdr *iph = ip_hdr(skb);
6578 iph->tot_len = 0;
6579 iph->check = 0;
6580 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6581 iph->daddr, 0,
6582 IPPROTO_TCP,
6583 0);
6584 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6585 } else if (skb_is_gso_v6(skb)) {
6586 ipv6_hdr(skb)->payload_len = 0;
6587 tcp_hdr(skb)->check =
6588 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6589 &ipv6_hdr(skb)->daddr,
6590 0, IPPROTO_TCP, 0);
6591 }
6592
6593 l4len = tcp_hdrlen(skb);
6594 *hdr_len = skb_transport_offset(skb) + l4len;
6595
6596 /* mss_l4len_id: use 1 as index for TSO */
6597 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6598 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6599 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6600
6601 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6602 vlan_macip_lens = skb_network_header_len(skb);
6603 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6604 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6605
6606 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6607 mss_l4len_idx);
6608
6609 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006610}
6611
Alexander Duyck897ab152011-05-27 05:31:47 +00006612static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006613 struct sk_buff *skb, u32 tx_flags,
6614 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006615{
Alexander Duyck897ab152011-05-27 05:31:47 +00006616 u32 vlan_macip_lens = 0;
6617 u32 mss_l4len_idx = 0;
6618 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006619
Alexander Duyck897ab152011-05-27 05:31:47 +00006620 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006621 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6622 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006623 return false;
6624 } else {
6625 u8 l4_hdr = 0;
6626 switch (protocol) {
6627 case __constant_htons(ETH_P_IP):
6628 vlan_macip_lens |= skb_network_header_len(skb);
6629 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6630 l4_hdr = ip_hdr(skb)->protocol;
6631 break;
6632 case __constant_htons(ETH_P_IPV6):
6633 vlan_macip_lens |= skb_network_header_len(skb);
6634 l4_hdr = ipv6_hdr(skb)->nexthdr;
6635 break;
6636 default:
6637 if (unlikely(net_ratelimit())) {
6638 dev_warn(tx_ring->dev,
6639 "partial checksum but proto=%x!\n",
6640 skb->protocol);
6641 }
6642 break;
6643 }
Auke Kok9a799d72007-09-15 14:07:45 -07006644
Alexander Duyck897ab152011-05-27 05:31:47 +00006645 switch (l4_hdr) {
6646 case IPPROTO_TCP:
6647 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6648 mss_l4len_idx = tcp_hdrlen(skb) <<
6649 IXGBE_ADVTXD_L4LEN_SHIFT;
6650 break;
6651 case IPPROTO_SCTP:
6652 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6653 mss_l4len_idx = sizeof(struct sctphdr) <<
6654 IXGBE_ADVTXD_L4LEN_SHIFT;
6655 break;
6656 case IPPROTO_UDP:
6657 mss_l4len_idx = sizeof(struct udphdr) <<
6658 IXGBE_ADVTXD_L4LEN_SHIFT;
6659 break;
6660 default:
6661 if (unlikely(net_ratelimit())) {
6662 dev_warn(tx_ring->dev,
6663 "partial checksum but l4 proto=%x!\n",
6664 skb->protocol);
6665 }
6666 break;
6667 }
Auke Kok9a799d72007-09-15 14:07:45 -07006668 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006669
Alexander Duyck897ab152011-05-27 05:31:47 +00006670 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6671 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6672
6673 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6674 type_tucmd, mss_l4len_idx);
6675
6676 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006677}
6678
Alexander Duyckd3d00232011-07-15 02:31:25 +00006679static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6680{
6681 /* set type for advanced descriptor with frame checksum insertion */
6682 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6683 IXGBE_ADVTXD_DCMD_IFCS |
6684 IXGBE_ADVTXD_DCMD_DEXT);
6685
6686 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006687 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006688 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6689
6690 /* set segmentation enable bits for TSO/FSO */
6691#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006692 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006693#else
6694 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6695#endif
6696 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6697
6698 return cmd_type;
6699}
6700
6701static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6702{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006703 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006704
6705 /* enable L4 checksum for TSO and TX checksum offload */
6706 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6707 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6708
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006709 /* enble IPv4 checksum for TSO */
6710 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6711 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006712
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006713 /* use index 1 context for TSO/FSO/FCOE */
6714#ifdef IXGBE_FCOE
6715 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6716#else
6717 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006718#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006719 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6720
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006721 /*
6722 * Check Context must be set if Tx switch is enabled, which it
6723 * always is for case where virtual functions are running
6724 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006725#ifdef IXGBE_FCOE
6726 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6727#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006728 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006729#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006730 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6731
Alexander Duyckd3d00232011-07-15 02:31:25 +00006732 return olinfo_status;
6733}
6734
6735#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6736 IXGBE_TXD_CMD_RS)
6737
6738static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6739 struct sk_buff *skb,
6740 struct ixgbe_tx_buffer *first,
6741 u32 tx_flags,
6742 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006743{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006744 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006745 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006746 union ixgbe_adv_tx_desc *tx_desc;
6747 dma_addr_t dma;
6748 __le32 cmd_type, olinfo_status;
6749 struct skb_frag_struct *frag;
6750 unsigned int f = 0;
6751 unsigned int data_len = skb->data_len;
6752 unsigned int size = skb_headlen(skb);
6753 u32 offset = 0;
6754 u32 paylen = skb->len - hdr_len;
6755 u16 i = tx_ring->next_to_use;
6756 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006757
Alexander Duyckd3d00232011-07-15 02:31:25 +00006758#ifdef IXGBE_FCOE
6759 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6760 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6761 data_len -= sizeof(struct fcoe_crc_eof);
6762 } else {
6763 size -= sizeof(struct fcoe_crc_eof) - data_len;
6764 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006765 }
Auke Kok9a799d72007-09-15 14:07:45 -07006766 }
6767
Alexander Duyckd3d00232011-07-15 02:31:25 +00006768#endif
6769 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6770 if (dma_mapping_error(dev, dma))
6771 goto dma_error;
6772
6773 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6774 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6775
Alexander Duycke4f74022012-01-31 02:59:44 +00006776 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006777
6778 for (;;) {
6779 while (size > IXGBE_MAX_DATA_PER_TXD) {
6780 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6781 tx_desc->read.cmd_type_len =
6782 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6783 tx_desc->read.olinfo_status = olinfo_status;
6784
6785 offset += IXGBE_MAX_DATA_PER_TXD;
6786 size -= IXGBE_MAX_DATA_PER_TXD;
6787
6788 tx_desc++;
6789 i++;
6790 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006791 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006792 i = 0;
6793 }
6794 }
6795
6796 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6797 tx_buffer_info->length = offset + size;
6798 tx_buffer_info->tx_flags = tx_flags;
6799 tx_buffer_info->dma = dma;
6800
6801 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
Ben Greearf43f3132012-03-06 09:42:04 +00006802 if (unlikely(skb->no_fcs))
6803 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006804 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6805 tx_desc->read.olinfo_status = olinfo_status;
6806
6807 if (!data_len)
6808 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006809
6810 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006811#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006812 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006813#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006814 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006815#endif
6816 data_len -= size;
6817 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006818
Alexander Duyckd3d00232011-07-15 02:31:25 +00006819 offset = 0;
6820 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006821
Ian Campbell877749b2011-08-29 23:18:26 +00006822 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006823 if (dma_mapping_error(dev, dma))
6824 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006825
Alexander Duyckd3d00232011-07-15 02:31:25 +00006826 tx_desc++;
6827 i++;
6828 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006829 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006830 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006831 }
6832 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006833
Alexander Duyckd3d00232011-07-15 02:31:25 +00006834 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6835
6836 i++;
6837 if (i == tx_ring->count)
6838 i = 0;
6839
6840 tx_ring->next_to_use = i;
6841
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006842 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6843 gso_segs = skb_shinfo(skb)->gso_segs;
6844#ifdef IXGBE_FCOE
6845 /* adjust for FCoE Sequence Offload */
6846 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6847 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6848 skb_shinfo(skb)->gso_size);
6849#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006850 else
6851 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006852
6853 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006854 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6855 tx_buffer_info->gso_segs = gso_segs;
6856 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006857
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006858 netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount);
6859
Alexander Duyckd3d00232011-07-15 02:31:25 +00006860 /* set the timestamp */
6861 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006862
6863 /*
6864 * Force memory writes to complete before letting h/w
6865 * know there are new descriptors to fetch. (Only
6866 * applicable for weak-ordered memory model archs,
6867 * such as IA-64).
6868 */
6869 wmb();
6870
Alexander Duyckd3d00232011-07-15 02:31:25 +00006871 /* set next_to_watch value indicating a packet is present */
6872 first->next_to_watch = tx_desc;
6873
6874 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006875 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006876
6877 return;
6878dma_error:
6879 dev_err(dev, "TX DMA map failed\n");
6880
6881 /* clear dma mappings for failed tx_buffer_info map */
6882 for (;;) {
6883 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6884 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6885 if (tx_buffer_info == first)
6886 break;
6887 if (i == 0)
6888 i = tx_ring->count;
6889 i--;
6890 }
6891
6892 dev_kfree_skb_any(skb);
6893
6894 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006895}
6896
Alexander Duyck69830522011-01-06 14:29:58 +00006897static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6898 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006899{
Alexander Duyck69830522011-01-06 14:29:58 +00006900 struct ixgbe_q_vector *q_vector = ring->q_vector;
6901 union ixgbe_atr_hash_dword input = { .dword = 0 };
6902 union ixgbe_atr_hash_dword common = { .dword = 0 };
6903 union {
6904 unsigned char *network;
6905 struct iphdr *ipv4;
6906 struct ipv6hdr *ipv6;
6907 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006908 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006909 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006910
Alexander Duyck69830522011-01-06 14:29:58 +00006911 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6912 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006913 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006914
Alexander Duyck69830522011-01-06 14:29:58 +00006915 /* do nothing if sampling is disabled */
6916 if (!ring->atr_sample_rate)
6917 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006918
Alexander Duyck69830522011-01-06 14:29:58 +00006919 ring->atr_count++;
6920
6921 /* snag network header to get L4 type and address */
6922 hdr.network = skb_network_header(skb);
6923
6924 /* Currently only IPv4/IPv6 with TCP is supported */
6925 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6926 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6927 (protocol != __constant_htons(ETH_P_IP) ||
6928 hdr.ipv4->protocol != IPPROTO_TCP))
6929 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006930
6931 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006932
Alexander Duyck66f32a82011-06-29 05:43:22 +00006933 /* skip this packet since it is invalid or the socket is closing */
6934 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006935 return;
6936
6937 /* sample on all syn packets or once every atr sample count */
6938 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6939 return;
6940
6941 /* reset sample count */
6942 ring->atr_count = 0;
6943
6944 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6945
6946 /*
6947 * src and dst are inverted, think how the receiver sees them
6948 *
6949 * The input is broken into two sections, a non-compressed section
6950 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6951 * is XORed together and stored in the compressed dword.
6952 */
6953 input.formatted.vlan_id = vlan_id;
6954
6955 /*
6956 * since src port and flex bytes occupy the same word XOR them together
6957 * and write the value to source port portion of compressed dword
6958 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006959 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006960 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6961 else
6962 common.port.src ^= th->dest ^ protocol;
6963 common.port.dst ^= th->source;
6964
6965 if (protocol == __constant_htons(ETH_P_IP)) {
6966 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6967 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6968 } else {
6969 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6970 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6971 hdr.ipv6->saddr.s6_addr32[1] ^
6972 hdr.ipv6->saddr.s6_addr32[2] ^
6973 hdr.ipv6->saddr.s6_addr32[3] ^
6974 hdr.ipv6->daddr.s6_addr32[0] ^
6975 hdr.ipv6->daddr.s6_addr32[1] ^
6976 hdr.ipv6->daddr.s6_addr32[2] ^
6977 hdr.ipv6->daddr.s6_addr32[3];
6978 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006979
6980 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006981 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6982 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006983}
6984
Alexander Duyck63544e92011-05-27 05:31:42 +00006985static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006986{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006987 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006988 /* Herbert's original patch had:
6989 * smp_mb__after_netif_stop_queue();
6990 * but since that doesn't exist yet, just open code it. */
6991 smp_mb();
6992
6993 /* We need to check again in a case another CPU has just
6994 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006995 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006996 return -EBUSY;
6997
6998 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006999 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08007000 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007001 return 0;
7002}
7003
Alexander Duyck82d4e462011-06-11 01:44:58 +00007004static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007005{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00007006 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007007 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007008 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007009}
7010
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007011static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
7012{
7013 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00007014 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7015 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00007016#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00007017 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00007018
John Fastabende5b64632011-03-08 03:44:52 +00007019 if (((protocol == htons(ETH_P_FCOE)) ||
7020 (protocol == htons(ETH_P_FIP))) &&
7021 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
7022 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
7023 txq += adapter->ring_feature[RING_F_FCOE].mask;
7024 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00007025 }
7026#endif
7027
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007028 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
7029 while (unlikely(txq >= dev->real_num_tx_queues))
7030 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00007031 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007032 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007033
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007034 return skb_tx_hash(dev, skb);
7035}
7036
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007037netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007038 struct ixgbe_adapter *adapter,
7039 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007040{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007041 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007042 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007043 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007044#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7045 unsigned short f;
7046#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007047 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007048 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007049 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007050
Alexander Duycka535c302011-05-27 05:31:52 +00007051 /*
7052 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007053 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007054 * + 2 desc gap to keep tail from touching head,
7055 * + 1 desc for context descriptor,
7056 * otherwise try next time
7057 */
7058#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7059 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7060 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7061#else
7062 count += skb_shinfo(skb)->nr_frags;
7063#endif
7064 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7065 tx_ring->tx_stats.tx_busy++;
7066 return NETDEV_TX_BUSY;
7067 }
7068
Alexander Duyck66f32a82011-06-29 05:43:22 +00007069 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007070 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007071 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7072 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7073 /* else if it is a SW VLAN check the next protocol and store the tag */
7074 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7075 struct vlan_hdr *vhdr, _vhdr;
7076 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7077 if (!vhdr)
7078 goto out_drop;
7079
7080 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007081 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7082 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007083 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007084 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007085
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007086#ifdef CONFIG_PCI_IOV
7087 /*
7088 * Use the l2switch_enable flag - would be false if the DMA
7089 * Tx switch had been disabled.
7090 */
7091 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7092 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7093
7094#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007095 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007096 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007097 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7098 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007099 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007100 tx_flags |= (skb->priority & 0x7) <<
7101 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007102 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7103 struct vlan_ethhdr *vhdr;
7104 if (skb_header_cloned(skb) &&
7105 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7106 goto out_drop;
7107 vhdr = (struct vlan_ethhdr *)skb->data;
7108 vhdr->h_vlan_TCI = htons(tx_flags >>
7109 IXGBE_TX_FLAGS_VLAN_SHIFT);
7110 } else {
7111 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7112 }
7113 }
Alexander Duycka535c302011-05-27 05:31:52 +00007114
Alexander Duycka535c302011-05-27 05:31:52 +00007115 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007116 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007117
Yi Zoueacd73f2009-05-13 13:11:06 +00007118#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007119 /* setup tx offload for FCoE */
7120 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7121 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007122 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7123 if (tso < 0)
7124 goto out_drop;
7125 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007126 tx_flags |= IXGBE_TX_FLAGS_FSO |
7127 IXGBE_TX_FLAGS_FCOE;
7128 else
7129 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007130
Alexander Duyck66f32a82011-06-29 05:43:22 +00007131 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007132 }
Auke Kok9a799d72007-09-15 14:07:45 -07007133
Auke Kok9a799d72007-09-15 14:07:45 -07007134#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007135 /* setup IPv4/IPv6 offloads */
7136 if (protocol == __constant_htons(ETH_P_IP))
7137 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007138
Alexander Duyck66f32a82011-06-29 05:43:22 +00007139 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7140 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007141 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007142 else if (tso)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007143 tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007144 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7145 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7146
7147 /* add the ATR filter if ATR is on */
7148 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7149 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7150
7151#ifdef IXGBE_FCOE
7152xmit_fcoe:
7153#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007154 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7155
7156 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007157
7158 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007159
7160out_drop:
7161 dev_kfree_skb_any(skb);
7162 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007163}
7164
Alexander Duycka50c29d2012-02-08 07:50:40 +00007165static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7166 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007167{
7168 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7169 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007170
Alexander Duycka50c29d2012-02-08 07:50:40 +00007171 if (skb->len <= 0) {
7172 dev_kfree_skb_any(skb);
7173 return NETDEV_TX_OK;
7174 }
7175
7176 /*
7177 * The minimum packet size for olinfo paylen is 17 so pad the skb
7178 * in order to meet this minimum size requirement.
7179 */
7180 if (skb->len < 17) {
7181 if (skb_padto(skb, 17))
7182 return NETDEV_TX_OK;
7183 skb->len = 17;
7184 }
7185
Auke Kok9a799d72007-09-15 14:07:45 -07007186 tx_ring = adapter->tx_ring[skb->queue_mapping];
7187 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7188}
7189
7190/**
7191 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007192 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007193 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007194 *
Auke Kok9a799d72007-09-15 14:07:45 -07007195 * Returns 0 on success, negative on failure
7196 **/
7197static int ixgbe_set_mac(struct net_device *netdev, void *p)
7198{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007199 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7200 struct ixgbe_hw *hw = &adapter->hw;
7201 struct sockaddr *addr = p;
7202
7203 if (!is_valid_ether_addr(addr->sa_data))
7204 return -EADDRNOTAVAIL;
7205
7206 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7207 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7208
7209 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7210 IXGBE_RAH_AV);
7211
7212 return 0;
7213}
7214
7215static int
7216ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7217{
7218 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7219 struct ixgbe_hw *hw = &adapter->hw;
7220 u16 value;
7221 int rc;
7222
7223 if (prtad != hw->phy.mdio.prtad)
7224 return -EINVAL;
7225 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7226 if (!rc)
7227 rc = value;
7228 return rc;
7229}
7230
7231static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7232 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007233{
7234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007235 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007236
7237 if (prtad != hw->phy.mdio.prtad)
7238 return -EINVAL;
7239 return hw->phy.ops.write_reg(hw, addr, devad, value);
7240}
7241
7242static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7243{
7244 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7245
7246 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7247}
7248
7249/**
7250 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7251 * netdev->dev_addrs
7252 * @netdev: network interface device structure
7253 *
7254 * Returns non-zero on failure
7255 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007256static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007257{
7258 int err = 0;
7259 struct ixgbe_adapter *adapter = netdev_priv(dev);
7260 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7261
7262 if (is_valid_ether_addr(mac->san_addr)) {
7263 rtnl_lock();
7264 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7265 rtnl_unlock();
7266 }
7267 return err;
7268}
7269
7270/**
7271 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7272 * netdev->dev_addrs
7273 * @netdev: network interface device structure
7274 *
Auke Kok9a799d72007-09-15 14:07:45 -07007275 * Returns non-zero on failure
7276 **/
7277static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7278{
7279 int err = 0;
7280 struct ixgbe_adapter *adapter = netdev_priv(dev);
7281 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7282
7283 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007284 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007285 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007286 rtnl_unlock();
7287 }
7288 return err;
7289}
Auke Kok9a799d72007-09-15 14:07:45 -07007290
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007291#ifdef CONFIG_NET_POLL_CONTROLLER
7292/*
7293 * Polling 'interrupt' - used by things like netconsole to send skbs
7294 * without having to re-enable interrupts. It's not called while
7295 * the interrupt routine is executing.
7296 */
7297static void ixgbe_netpoll(struct net_device *netdev)
7298{
7299 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007300 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007301
7302 /* if interface is down do nothing */
7303 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007304 return;
7305
7306 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007307 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007308 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007309 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007310 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007311 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007312 }
7313 } else {
7314 ixgbe_intr(adapter->pdev->irq, netdev);
7315 }
7316 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7317}
7318#endif
7319
Eric Dumazetde1036b2010-10-20 23:00:04 +00007320static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7321 struct rtnl_link_stats64 *stats)
7322{
7323 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7324 int i;
7325
Eric Dumazet1a515022010-11-16 19:26:42 -08007326 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007327 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007328 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007329 u64 bytes, packets;
7330 unsigned int start;
7331
Eric Dumazet1a515022010-11-16 19:26:42 -08007332 if (ring) {
7333 do {
7334 start = u64_stats_fetch_begin_bh(&ring->syncp);
7335 packets = ring->stats.packets;
7336 bytes = ring->stats.bytes;
7337 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7338 stats->rx_packets += packets;
7339 stats->rx_bytes += bytes;
7340 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007341 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007342
7343 for (i = 0; i < adapter->num_tx_queues; i++) {
7344 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7345 u64 bytes, packets;
7346 unsigned int start;
7347
7348 if (ring) {
7349 do {
7350 start = u64_stats_fetch_begin_bh(&ring->syncp);
7351 packets = ring->stats.packets;
7352 bytes = ring->stats.bytes;
7353 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7354 stats->tx_packets += packets;
7355 stats->tx_bytes += bytes;
7356 }
7357 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007358 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007359 /* following stats updated by ixgbe_watchdog_task() */
7360 stats->multicast = netdev->stats.multicast;
7361 stats->rx_errors = netdev->stats.rx_errors;
7362 stats->rx_length_errors = netdev->stats.rx_length_errors;
7363 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7364 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7365 return stats;
7366}
7367
John Fastabend8b1c0b22011-05-03 02:26:48 +00007368/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7369 * #adapter: pointer to ixgbe_adapter
7370 * @tc: number of traffic classes currently enabled
7371 *
7372 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7373 * 802.1Q priority maps to a packet buffer that exists.
7374 */
7375static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7376{
7377 struct ixgbe_hw *hw = &adapter->hw;
7378 u32 reg, rsave;
7379 int i;
7380
7381 /* 82598 have a static priority to TC mapping that can not
7382 * be changed so no validation is needed.
7383 */
7384 if (hw->mac.type == ixgbe_mac_82598EB)
7385 return;
7386
7387 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7388 rsave = reg;
7389
7390 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7391 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7392
7393 /* If up2tc is out of bounds default to zero */
7394 if (up2tc > tc)
7395 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7396 }
7397
7398 if (reg != rsave)
7399 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7400
7401 return;
7402}
7403
7404
7405/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7406 * classes.
7407 *
7408 * @netdev: net device to configure
7409 * @tc: number of traffic classes to enable
7410 */
7411int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7412{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007413 struct ixgbe_adapter *adapter = netdev_priv(dev);
7414 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007415
John Fastabende7589ea2011-07-18 22:38:36 +00007416 /* Multiple traffic classes requires multiple queues */
7417 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7418 e_err(drv, "Enable failed, needs MSI-X\n");
7419 return -EINVAL;
7420 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007421
7422 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007423 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007424 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7425 return -EINVAL;
7426
7427 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007428 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007429 * hardware is not flexible enough to do this dynamically.
7430 */
7431 if (netif_running(dev))
7432 ixgbe_close(dev);
7433 ixgbe_clear_interrupt_scheme(adapter);
7434
John Fastabende7589ea2011-07-18 22:38:36 +00007435 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007436 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007437 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7438
7439 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7440 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7441
7442 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7443 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7444 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007445 netdev_reset_tc(dev);
7446
John Fastabende7589ea2011-07-18 22:38:36 +00007447 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7448
7449 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7450 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7451
7452 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7453 adapter->dcb_cfg.pfc_mode_enable = false;
7454 }
7455
John Fastabend8b1c0b22011-05-03 02:26:48 +00007456 ixgbe_init_interrupt_scheme(adapter);
7457 ixgbe_validate_rtr(adapter, tc);
7458 if (netif_running(dev))
7459 ixgbe_open(dev);
7460
7461 return 0;
7462}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007463
Don Skidmore082757a2011-07-21 05:55:00 +00007464void ixgbe_do_reset(struct net_device *netdev)
7465{
7466 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7467
7468 if (netif_running(netdev))
7469 ixgbe_reinit_locked(adapter);
7470 else
7471 ixgbe_reset(adapter);
7472}
7473
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007474static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7475 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007476{
7477 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7478
7479#ifdef CONFIG_DCB
7480 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7481 data &= ~NETIF_F_HW_VLAN_RX;
7482#endif
7483
7484 /* return error if RXHASH is being enabled when RSS is not supported */
7485 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7486 data &= ~NETIF_F_RXHASH;
7487
7488 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7489 if (!(data & NETIF_F_RXCSUM))
7490 data &= ~NETIF_F_LRO;
7491
7492 /* Turn off LRO if not RSC capable or invalid ITR settings */
7493 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7494 data &= ~NETIF_F_LRO;
7495 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7496 (adapter->rx_itr_setting != 1 &&
7497 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7498 data &= ~NETIF_F_LRO;
7499 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7500 }
7501
7502 return data;
7503}
7504
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007505static int ixgbe_set_features(struct net_device *netdev,
7506 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007507{
7508 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ben Greear3f2d1c02012-03-08 08:28:41 +00007509 netdev_features_t changed = netdev->features ^ data;
Don Skidmore082757a2011-07-21 05:55:00 +00007510 bool need_reset = false;
7511
Don Skidmore082757a2011-07-21 05:55:00 +00007512 /* Make sure RSC matches LRO, reset if change */
7513 if (!!(data & NETIF_F_LRO) !=
7514 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7515 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7516 switch (adapter->hw.mac.type) {
7517 case ixgbe_mac_X540:
7518 case ixgbe_mac_82599EB:
7519 need_reset = true;
7520 break;
7521 default:
7522 break;
7523 }
7524 }
7525
7526 /*
7527 * Check if Flow Director n-tuple support was enabled or disabled. If
7528 * the state changed, we need to reset.
7529 */
7530 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7531 /* turn off ATR, enable perfect filters and reset */
7532 if (data & NETIF_F_NTUPLE) {
7533 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7534 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7535 need_reset = true;
7536 }
7537 } else if (!(data & NETIF_F_NTUPLE)) {
7538 /* turn off Flow Director, set ATR and reset */
7539 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7540 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7541 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7542 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7543 need_reset = true;
7544 }
7545
Ben Greear3f2d1c02012-03-08 08:28:41 +00007546 if (changed & NETIF_F_RXALL)
7547 need_reset = true;
7548
7549 netdev->features = data;
Don Skidmore082757a2011-07-21 05:55:00 +00007550 if (need_reset)
7551 ixgbe_do_reset(netdev);
7552
7553 return 0;
7554
7555}
7556
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007557static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007558 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007559 .ndo_stop = ixgbe_close,
7560 .ndo_start_xmit = ixgbe_xmit_frame,
7561 .ndo_select_queue = ixgbe_select_queue,
7562 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007563 .ndo_validate_addr = eth_validate_addr,
7564 .ndo_set_mac_address = ixgbe_set_mac,
7565 .ndo_change_mtu = ixgbe_change_mtu,
7566 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007567 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7568 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007569 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007570 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7571 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7572 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007573 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007574 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007575 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007576 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007577#ifdef CONFIG_NET_POLL_CONTROLLER
7578 .ndo_poll_controller = ixgbe_netpoll,
7579#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007580#ifdef IXGBE_FCOE
7581 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007582 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007583 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007584 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7585 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007586 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007587 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007588#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007589 .ndo_set_features = ixgbe_set_features,
7590 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007591};
7592
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007593static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7594 const struct ixgbe_info *ii)
7595{
7596#ifdef CONFIG_PCI_IOV
7597 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007598
Greg Rosec6bda302011-08-24 02:37:55 +00007599 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007600 return;
7601
7602 /* The 82599 supports up to 64 VFs per physical function
7603 * but this implementation limits allocation to 63 so that
7604 * basic networking resources are still available to the
7605 * physical function
7606 */
7607 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007608 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007609#endif /* CONFIG_PCI_IOV */
7610}
7611
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007612/**
Auke Kok9a799d72007-09-15 14:07:45 -07007613 * ixgbe_probe - Device Initialization Routine
7614 * @pdev: PCI device information struct
7615 * @ent: entry in ixgbe_pci_tbl
7616 *
7617 * Returns 0 on success, negative on failure
7618 *
7619 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7620 * The OS initialization, configuring of the adapter private structure,
7621 * and a hardware reset occur.
7622 **/
7623static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007624 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007625{
7626 struct net_device *netdev;
7627 struct ixgbe_adapter *adapter = NULL;
7628 struct ixgbe_hw *hw;
7629 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007630 static int cards_found;
7631 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007632 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007633 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007634#ifdef IXGBE_FCOE
7635 u16 device_caps;
7636#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007637 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007638 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007639
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007640 /* Catch broken hardware that put the wrong VF device ID in
7641 * the PCIe SR-IOV capability.
7642 */
7643 if (pdev->is_virtfn) {
7644 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7645 pci_name(pdev), pdev->vendor, pdev->device);
7646 return -EINVAL;
7647 }
7648
gouji-new9ce77662009-05-06 10:44:45 +00007649 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007650 if (err)
7651 return err;
7652
Nick Nunley1b507732010-04-27 13:10:27 +00007653 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7654 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007655 pci_using_dac = 1;
7656 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007657 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007658 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007659 err = dma_set_coherent_mask(&pdev->dev,
7660 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007661 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007662 dev_err(&pdev->dev,
7663 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007664 goto err_dma;
7665 }
7666 }
7667 pci_using_dac = 0;
7668 }
7669
gouji-new9ce77662009-05-06 10:44:45 +00007670 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007671 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007672 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007673 dev_err(&pdev->dev,
7674 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007675 goto err_pci_reg;
7676 }
7677
Frans Pop19d5afd2009-10-02 10:04:12 -07007678 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007679
Auke Kok9a799d72007-09-15 14:07:45 -07007680 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007681 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007682
John Fastabende901acd2011-04-26 07:26:08 +00007683#ifdef CONFIG_IXGBE_DCB
7684 indices *= MAX_TRAFFIC_CLASS;
7685#endif
7686
John Fastabendc85a2612010-02-25 23:15:21 +00007687 if (ii->mac == ixgbe_mac_82598EB)
7688 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7689 else
7690 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7691
John Fastabende901acd2011-04-26 07:26:08 +00007692#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007693 indices += min_t(unsigned int, num_possible_cpus(),
7694 IXGBE_MAX_FCOE_INDICES);
7695#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007696 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007697 if (!netdev) {
7698 err = -ENOMEM;
7699 goto err_alloc_etherdev;
7700 }
7701
Auke Kok9a799d72007-09-15 14:07:45 -07007702 SET_NETDEV_DEV(netdev, &pdev->dev);
7703
Auke Kok9a799d72007-09-15 14:07:45 -07007704 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007705 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007706
7707 adapter->netdev = netdev;
7708 adapter->pdev = pdev;
7709 hw = &adapter->hw;
7710 hw->back = adapter;
7711 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7712
Jeff Kirsher05857982008-09-11 19:57:00 -07007713 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007714 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007715 if (!hw->hw_addr) {
7716 err = -EIO;
7717 goto err_ioremap;
7718 }
7719
7720 for (i = 1; i <= 5; i++) {
7721 if (pci_resource_len(pdev, i) == 0)
7722 continue;
7723 }
7724
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007725 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007726 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007727 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007728 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007729
Auke Kok9a799d72007-09-15 14:07:45 -07007730 adapter->bd_number = cards_found;
7731
Auke Kok9a799d72007-09-15 14:07:45 -07007732 /* Setup hw api */
7733 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007734 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007735
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007736 /* EEPROM */
7737 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7738 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7739 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7740 if (!(eec & (1 << 8)))
7741 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7742
7743 /* PHY */
7744 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007745 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007746 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7747 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7748 hw->phy.mdio.mmds = 0;
7749 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7750 hw->phy.mdio.dev = netdev;
7751 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7752 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007753
Don Skidmore8ca783a2009-05-26 20:40:47 -07007754 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007755
7756 /* setup the private structure */
7757 err = ixgbe_sw_init(adapter);
7758 if (err)
7759 goto err_sw_init;
7760
Don Skidmoree86bff02010-02-11 04:14:08 +00007761 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007762 switch (adapter->hw.mac.type) {
7763 case ixgbe_mac_82599EB:
7764 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007765 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007766 break;
7767 default:
7768 break;
7769 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007770
Don Skidmorebf069c92009-05-07 10:39:54 +00007771 /*
7772 * If there is a fan on this device and it has failed log the
7773 * failure.
7774 */
7775 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7776 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7777 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007778 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007779 }
7780
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007781 if (allow_unsupported_sfp)
7782 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7783
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007784 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007785 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007786 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007787 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007788 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7789 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007790 err = 0;
7791 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007792 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007793 "module type was detected.\n");
7794 e_dev_err("Reload the driver after installing a supported "
7795 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007796 goto err_sw_init;
7797 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007798 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007799 goto err_sw_init;
7800 }
7801
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007802 ixgbe_probe_vf(adapter, ii);
7803
Emil Tantilov396e7992010-07-01 20:05:12 +00007804 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007805 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007806 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007807 NETIF_F_HW_VLAN_TX |
7808 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007809 NETIF_F_HW_VLAN_FILTER |
7810 NETIF_F_TSO |
7811 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007812 NETIF_F_RXHASH |
7813 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007814
Don Skidmore082757a2011-07-21 05:55:00 +00007815 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007816
Don Skidmore58be7662011-04-12 09:42:11 +00007817 switch (adapter->hw.mac.type) {
7818 case ixgbe_mac_82599EB:
7819 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007820 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007821 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7822 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007823 break;
7824 default:
7825 break;
7826 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007827
Ben Greear3f2d1c02012-03-08 08:28:41 +00007828 netdev->hw_features |= NETIF_F_RXALL;
7829
Jeff Kirsherad31c402008-06-05 04:05:30 -07007830 netdev->vlan_features |= NETIF_F_TSO;
7831 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007832 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007833 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007834 netdev->vlan_features |= NETIF_F_SG;
7835
Jiri Pirko01789342011-08-16 06:29:00 +00007836 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007837 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007838
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007839 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7840 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7841 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007842
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007843#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007844 netdev->dcbnl_ops = &dcbnl_ops;
7845#endif
7846
Yi Zoueacd73f2009-05-13 13:11:06 +00007847#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007848 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007849 if (hw->mac.ops.get_device_caps) {
7850 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007851 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7852 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007853 }
7854 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007855 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7856 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7857 netdev->vlan_features |= NETIF_F_FSO;
7858 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7859 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007860#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007861 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007862 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007863 netdev->vlan_features |= NETIF_F_HIGHDMA;
7864 }
Auke Kok9a799d72007-09-15 14:07:45 -07007865
Don Skidmore082757a2011-07-21 05:55:00 +00007866 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7867 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007868 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007869 netdev->features |= NETIF_F_LRO;
7870
Auke Kok9a799d72007-09-15 14:07:45 -07007871 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007872 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007873 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007874 err = -EIO;
7875 goto err_eeprom;
7876 }
7877
7878 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7879 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7880
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007881 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007882 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007883 err = -EIO;
7884 goto err_eeprom;
7885 }
7886
Alexander Duyck70864002011-04-27 09:13:56 +00007887 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7888 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007889
Alexander Duyck70864002011-04-27 09:13:56 +00007890 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7891 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007892
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007893 err = ixgbe_init_interrupt_scheme(adapter);
7894 if (err)
7895 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007896
Don Skidmore082757a2011-07-21 05:55:00 +00007897 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7898 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007899 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007900 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007901
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007902 /* WOL not supported for all but the following */
7903 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007904 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007905 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007906 /* Only these subdevice supports WOL */
7907 switch (pdev->subsystem_device) {
7908 case IXGBE_SUBDEV_ID_82599_560FLR:
7909 /* only support first port */
7910 if (hw->bus.func != 0)
7911 break;
7912 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007913 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007914 break;
7915 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007916 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007917 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7918 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007919 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007920 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007921 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007922 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007923 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007924 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007925 case IXGBE_DEV_ID_X540T:
7926 /* Check eeprom to see if it is enabled */
7927 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7928 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7929
7930 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7931 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7932 (hw->bus.func == 0)))
7933 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007934 break;
7935 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007936 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7937
Emil Tantilov15e52092011-09-29 05:01:29 +00007938 /* save off EEPROM version number */
7939 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7940 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7941
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007942 /* pick up the PCI bus settings for reporting later */
7943 hw->mac.ops.get_bus_info(hw);
7944
Auke Kok9a799d72007-09-15 14:07:45 -07007945 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007946 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007947 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7948 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007949 "Unknown"),
7950 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7951 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7952 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7953 "Unknown"),
7954 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007955
7956 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7957 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007958 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007959 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007960 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007961 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007962 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007963 else
Don Skidmore289700db2010-12-03 03:32:58 +00007964 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7965 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007966
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007967 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007968 e_dev_warn("PCI-Express bandwidth available for this card is "
7969 "not sufficient for optimal performance.\n");
7970 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7971 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007972 }
7973
Auke Kok9a799d72007-09-15 14:07:45 -07007974 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007975 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007976
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007977 if (err == IXGBE_ERR_EEPROM_VERSION) {
7978 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007979 e_dev_warn("This device is a pre-production adapter/LOM. "
7980 "Please be aware there may be issues associated "
7981 "with your hardware. If you are experiencing "
7982 "problems please contact your Intel or hardware "
7983 "representative who provided you with this "
7984 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007985 }
Auke Kok9a799d72007-09-15 14:07:45 -07007986 strcpy(netdev->name, "eth%d");
7987 err = register_netdev(netdev);
7988 if (err)
7989 goto err_register;
7990
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007991 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7992 if (hw->mac.ops.disable_tx_laser &&
7993 ((hw->phy.multispeed_fiber) ||
7994 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7995 (hw->mac.type == ixgbe_mac_82599EB))))
7996 hw->mac.ops.disable_tx_laser(hw);
7997
Jesse Brandeburg54386462009-04-17 20:44:27 +00007998 /* carrier off reporting is important to ethtool even BEFORE open */
7999 netif_carrier_off(netdev);
8000
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008001#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03008002 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008003 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008004 ixgbe_setup_dca(adapter);
8005 }
8006#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008007 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008008 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008009 for (i = 0; i < adapter->num_vfs; i++)
8010 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8011 }
8012
Jacob Keller2466dd92011-09-08 03:50:54 +00008013 /* firmware requires driver version to be 0xFFFFFFFF
8014 * since os does not support feature
8015 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008016 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008017 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8018 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008019
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008020 /* add san mac addr to netdev */
8021 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008022
Neerav Parikhea818752012-01-04 20:23:40 +00008023 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07008024 cards_found++;
8025 return 0;
8026
8027err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008028 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008029 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008030err_sw_init:
8031err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008032 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
8033 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008034 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07008035 iounmap(hw->hw_addr);
8036err_ioremap:
8037 free_netdev(netdev);
8038err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008039 pci_release_selected_regions(pdev,
8040 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008041err_pci_reg:
8042err_dma:
8043 pci_disable_device(pdev);
8044 return err;
8045}
8046
8047/**
8048 * ixgbe_remove - Device Removal Routine
8049 * @pdev: PCI device information struct
8050 *
8051 * ixgbe_remove is called by the PCI subsystem to alert the driver
8052 * that it should release a PCI device. The could be caused by a
8053 * Hot-Plug event, or because the driver is going to be removed from
8054 * memory.
8055 **/
8056static void __devexit ixgbe_remove(struct pci_dev *pdev)
8057{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008058 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8059 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008060
8061 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008062 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008063
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008064#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008065 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8066 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8067 dca_remove_requester(&pdev->dev);
8068 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8069 }
8070
8071#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008072#ifdef IXGBE_FCOE
8073 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8074 ixgbe_cleanup_fcoe(adapter);
8075
8076#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008077
8078 /* remove the added san mac */
8079 ixgbe_del_sanmac_netdev(netdev);
8080
Donald Skidmorec4900be2008-11-20 21:11:42 -08008081 if (netdev->reg_state == NETREG_REGISTERED)
8082 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008083
Greg Rosec6bda302011-08-24 02:37:55 +00008084 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8085 if (!(ixgbe_check_vf_assignment(adapter)))
8086 ixgbe_disable_sriov(adapter);
8087 else
8088 e_dev_warn("Unloading driver while VFs are assigned "
8089 "- VFs will not be deallocated\n");
8090 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008091
Alexander Duyck7a921c92009-05-06 10:43:28 +00008092 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008093
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008094 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008095
8096 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008097 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008098 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008099
Emil Tantilov849c4542010-06-03 16:53:41 +00008100 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008101
Auke Kok9a799d72007-09-15 14:07:45 -07008102 free_netdev(netdev);
8103
Frans Pop19d5afd2009-10-02 10:04:12 -07008104 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008105
Auke Kok9a799d72007-09-15 14:07:45 -07008106 pci_disable_device(pdev);
8107}
8108
8109/**
8110 * ixgbe_io_error_detected - called when PCI error is detected
8111 * @pdev: Pointer to PCI device
8112 * @state: The current pci connection state
8113 *
8114 * This function is called after a PCI bus error affecting
8115 * this device has been detected.
8116 */
8117static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008118 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008119{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008120 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8121 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008122
Greg Rose83c61fa2011-09-07 05:59:35 +00008123#ifdef CONFIG_PCI_IOV
8124 struct pci_dev *bdev, *vfdev;
8125 u32 dw0, dw1, dw2, dw3;
8126 int vf, pos;
8127 u16 req_id, pf_func;
8128
8129 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8130 adapter->num_vfs == 0)
8131 goto skip_bad_vf_detection;
8132
8133 bdev = pdev->bus->self;
8134 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8135 bdev = bdev->bus->self;
8136
8137 if (!bdev)
8138 goto skip_bad_vf_detection;
8139
8140 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8141 if (!pos)
8142 goto skip_bad_vf_detection;
8143
8144 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8145 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8146 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8147 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8148
8149 req_id = dw1 >> 16;
8150 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8151 if (!(req_id & 0x0080))
8152 goto skip_bad_vf_detection;
8153
8154 pf_func = req_id & 0x01;
8155 if ((pf_func & 1) == (pdev->devfn & 1)) {
8156 unsigned int device_id;
8157
8158 vf = (req_id & 0x7F) >> 1;
8159 e_dev_err("VF %d has caused a PCIe error\n", vf);
8160 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8161 "%8.8x\tdw3: %8.8x\n",
8162 dw0, dw1, dw2, dw3);
8163 switch (adapter->hw.mac.type) {
8164 case ixgbe_mac_82599EB:
8165 device_id = IXGBE_82599_VF_DEVICE_ID;
8166 break;
8167 case ixgbe_mac_X540:
8168 device_id = IXGBE_X540_VF_DEVICE_ID;
8169 break;
8170 default:
8171 device_id = 0;
8172 break;
8173 }
8174
8175 /* Find the pci device of the offending VF */
8176 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8177 while (vfdev) {
8178 if (vfdev->devfn == (req_id & 0xFF))
8179 break;
8180 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8181 device_id, vfdev);
8182 }
8183 /*
8184 * There's a slim chance the VF could have been hot plugged,
8185 * so if it is no longer present we don't need to issue the
8186 * VFLR. Just clean up the AER in that case.
8187 */
8188 if (vfdev) {
8189 e_dev_err("Issuing VFLR to VF %d\n", vf);
8190 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8191 }
8192
8193 pci_cleanup_aer_uncorrect_error_status(pdev);
8194 }
8195
8196 /*
8197 * Even though the error may have occurred on the other port
8198 * we still need to increment the vf error reference count for
8199 * both ports because the I/O resume function will be called
8200 * for both of them.
8201 */
8202 adapter->vferr_refcount++;
8203
8204 return PCI_ERS_RESULT_RECOVERED;
8205
8206skip_bad_vf_detection:
8207#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008208 netif_device_detach(netdev);
8209
Breno Leitao3044b8d2009-05-06 10:44:26 +00008210 if (state == pci_channel_io_perm_failure)
8211 return PCI_ERS_RESULT_DISCONNECT;
8212
Auke Kok9a799d72007-09-15 14:07:45 -07008213 if (netif_running(netdev))
8214 ixgbe_down(adapter);
8215 pci_disable_device(pdev);
8216
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008217 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008218 return PCI_ERS_RESULT_NEED_RESET;
8219}
8220
8221/**
8222 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8223 * @pdev: Pointer to PCI device
8224 *
8225 * Restart the card from scratch, as if from a cold-boot.
8226 */
8227static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8228{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008229 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008230 pci_ers_result_t result;
8231 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008232
gouji-new9ce77662009-05-06 10:44:45 +00008233 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008234 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008235 result = PCI_ERS_RESULT_DISCONNECT;
8236 } else {
8237 pci_set_master(pdev);
8238 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008239 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008240
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008241 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008242
8243 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008244 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008245 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008246 }
Auke Kok9a799d72007-09-15 14:07:45 -07008247
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008248 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8249 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008250 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8251 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008252 /* non-fatal, continue */
8253 }
Auke Kok9a799d72007-09-15 14:07:45 -07008254
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008255 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008256}
8257
8258/**
8259 * ixgbe_io_resume - called when traffic can start flowing again.
8260 * @pdev: Pointer to PCI device
8261 *
8262 * This callback is called when the error recovery driver tells us that
8263 * its OK to resume normal operation.
8264 */
8265static void ixgbe_io_resume(struct pci_dev *pdev)
8266{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008267 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8268 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008269
Greg Rose83c61fa2011-09-07 05:59:35 +00008270#ifdef CONFIG_PCI_IOV
8271 if (adapter->vferr_refcount) {
8272 e_info(drv, "Resuming after VF err\n");
8273 adapter->vferr_refcount--;
8274 return;
8275 }
8276
8277#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008278 if (netif_running(netdev))
8279 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008280
8281 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008282}
8283
8284static struct pci_error_handlers ixgbe_err_handler = {
8285 .error_detected = ixgbe_io_error_detected,
8286 .slot_reset = ixgbe_io_slot_reset,
8287 .resume = ixgbe_io_resume,
8288};
8289
8290static struct pci_driver ixgbe_driver = {
8291 .name = ixgbe_driver_name,
8292 .id_table = ixgbe_pci_tbl,
8293 .probe = ixgbe_probe,
8294 .remove = __devexit_p(ixgbe_remove),
8295#ifdef CONFIG_PM
8296 .suspend = ixgbe_suspend,
8297 .resume = ixgbe_resume,
8298#endif
8299 .shutdown = ixgbe_shutdown,
8300 .err_handler = &ixgbe_err_handler
8301};
8302
8303/**
8304 * ixgbe_init_module - Driver Registration Routine
8305 *
8306 * ixgbe_init_module is the first routine called when the driver is
8307 * loaded. All it does is register with the PCI subsystem.
8308 **/
8309static int __init ixgbe_init_module(void)
8310{
8311 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008312 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008313 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008314
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008315#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008316 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008317#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008318
Auke Kok9a799d72007-09-15 14:07:45 -07008319 ret = pci_register_driver(&ixgbe_driver);
8320 return ret;
8321}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008322
Auke Kok9a799d72007-09-15 14:07:45 -07008323module_init(ixgbe_init_module);
8324
8325/**
8326 * ixgbe_exit_module - Driver Exit Cleanup Routine
8327 *
8328 * ixgbe_exit_module is called just before the driver is removed
8329 * from memory.
8330 **/
8331static void __exit ixgbe_exit_module(void)
8332{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008333#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008334 dca_unregister_notify(&dca_notifier);
8335#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008336 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008337 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008338}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008339
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008340#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008341static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008342 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008343{
8344 int ret_val;
8345
8346 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008347 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008348
8349 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8350}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008351
Alexander Duyckb4533682009-03-31 21:32:42 +00008352#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008353
Auke Kok9a799d72007-09-15 14:07:45 -07008354module_exit(ixgbe_exit_module);
8355
8356/* ixgbe_main.c */