blob: 832a9fc3ad57fbe1aa70c56b650a244d77494140 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Neerav Parikhea818752012-01-04 20:23:40 +000058char ixgbe_default_device_descr[] =
59 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define MAJ 3
Don Skidmore19d478b2011-10-07 03:53:51 +000061#define MIN 6
62#define BUILD 7
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000063#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000064 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070065const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000066static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000067 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070068
69static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070070 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000071 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
292 struct ixgbe_tx_buffer *tx_buffer_info;
293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
332 tx_buffer_info =
333 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000334 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000335 n, tx_ring->next_to_use, tx_ring->next_to_clean,
336 (u64)tx_buffer_info->dma,
337 tx_buffer_info->length,
338 tx_buffer_info->next_to_watch,
339 (u64)tx_buffer_info->time_stamp);
340 }
341
342 /* Print TX Rings */
343 if (!netif_msg_tx_done(adapter))
344 goto rx_ring_summary;
345
346 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
347
348 /* Transmit Descriptor Formats
349 *
350 * Advanced Transmit Descriptor
351 * +--------------------------------------------------------------+
352 * 0 | Buffer Address [63:0] |
353 * +--------------------------------------------------------------+
354 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
355 * +--------------------------------------------------------------+
356 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
357 */
358
359 for (n = 0; n < adapter->num_tx_queues; n++) {
360 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("------------------------------------\n");
362 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
363 pr_info("------------------------------------\n");
364 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 "[PlPOIdStDDt Ln] [bi->dma ] "
366 "leng ntw timestamp bi->skb\n");
367
368 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000369 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 tx_buffer_info = &tx_ring->tx_buffer_info[i];
371 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000372 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000373 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000374 le64_to_cpu(u0->a),
375 le64_to_cpu(u0->b),
376 (u64)tx_buffer_info->dma,
377 tx_buffer_info->length,
378 tx_buffer_info->next_to_watch,
379 (u64)tx_buffer_info->time_stamp,
380 tx_buffer_info->skb);
381 if (i == tx_ring->next_to_use &&
382 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000383 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000385 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000386 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000387 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 else
Joe Perchesc7689572010-09-07 21:35:17 +0000389 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000390
391 if (netif_msg_pktdata(adapter) &&
392 tx_buffer_info->dma != 0)
393 print_hex_dump(KERN_INFO, "",
394 DUMP_PREFIX_ADDRESS, 16, 1,
395 phys_to_virt(tx_buffer_info->dma),
396 tx_buffer_info->length, true);
397 }
398 }
399
400 /* Print RX Rings Summary */
401rx_ring_summary:
402 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000403 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000404 for (n = 0; n < adapter->num_rx_queues; n++) {
405 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000406 pr_info("%5d %5X %5X\n",
407 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000408 }
409
410 /* Print RX Rings */
411 if (!netif_msg_rx_status(adapter))
412 goto exit;
413
414 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
415
416 /* Advanced Receive Descriptor (Read) Format
417 * 63 1 0
418 * +-----------------------------------------------------+
419 * 0 | Packet Buffer Address [63:1] |A0/NSE|
420 * +----------------------------------------------+------+
421 * 8 | Header Buffer Address [63:1] | DD |
422 * +-----------------------------------------------------+
423 *
424 *
425 * Advanced Receive Descriptor (Write-Back) Format
426 *
427 * 63 48 47 32 31 30 21 20 16 15 4 3 0
428 * +------------------------------------------------------+
429 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
430 * | Checksum Ident | | | | Type | Type |
431 * +------------------------------------------------------+
432 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
433 * +------------------------------------------------------+
434 * 63 48 47 32 31 20 19 0
435 */
436 for (n = 0; n < adapter->num_rx_queues; n++) {
437 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("------------------------------------\n");
439 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
440 pr_info("------------------------------------\n");
441 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
443 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000444 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445 "[vl er S cks ln] ---------------- [bi->skb] "
446 "<-- Adv Rx Write-Back format\n");
447
448 for (i = 0; i < rx_ring->count; i++) {
449 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000450 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000451 u0 = (struct my_u0 *)rx_desc;
452 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
453 if (staterr & IXGBE_RXD_STAT_DD) {
454 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000455 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 "%016llX ---------------- %p", i,
457 le64_to_cpu(u0->a),
458 le64_to_cpu(u0->b),
459 rx_buffer_info->skb);
460 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000461 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462 "%016llX %016llX %p", i,
463 le64_to_cpu(u0->a),
464 le64_to_cpu(u0->b),
465 (u64)rx_buffer_info->dma,
466 rx_buffer_info->skb);
467
468 if (netif_msg_pktdata(adapter)) {
469 print_hex_dump(KERN_INFO, "",
470 DUMP_PREFIX_ADDRESS, 16, 1,
471 phys_to_virt(rx_buffer_info->dma),
Alexander Duyckf8003262012-03-03 02:35:52 +0000472 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000473 }
474 }
475
476 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000477 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000478 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000479 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000480 else
Joe Perchesc7689572010-09-07 21:35:17 +0000481 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000482
483 }
484 }
485
486exit:
487 return;
488}
489
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800490static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
491{
492 u32 ctrl_ext;
493
494 /* Let firmware take over control of h/w */
495 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
496 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000497 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800498}
499
500static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
501{
502 u32 ctrl_ext;
503
504 /* Let firmware know the driver has taken over */
505 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000507 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800508}
Auke Kok9a799d72007-09-15 14:07:45 -0700509
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000510/*
511 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
512 * @adapter: pointer to adapter struct
513 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
514 * @queue: queue to map the corresponding interrupt to
515 * @msix_vector: the vector to map to the corresponding queue
516 *
517 */
518static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000519 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700520{
521 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000522 struct ixgbe_hw *hw = &adapter->hw;
523 switch (hw->mac.type) {
524 case ixgbe_mac_82598EB:
525 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
526 if (direction == -1)
527 direction = 0;
528 index = (((direction * 64) + queue) >> 2) & 0x1F;
529 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
530 ivar &= ~(0xFF << (8 * (queue & 0x3)));
531 ivar |= (msix_vector << (8 * (queue & 0x3)));
532 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
533 break;
534 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800535 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000536 if (direction == -1) {
537 /* other causes */
538 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
539 index = ((queue & 1) * 8);
540 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
541 ivar &= ~(0xFF << index);
542 ivar |= (msix_vector << index);
543 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
544 break;
545 } else {
546 /* tx or rx causes */
547 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
548 index = ((16 * (queue & 1)) + (8 * direction));
549 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
550 ivar &= ~(0xFF << index);
551 ivar |= (msix_vector << index);
552 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
553 break;
554 }
555 default:
556 break;
557 }
Auke Kok9a799d72007-09-15 14:07:45 -0700558}
559
Alexander Duyckfe49f042009-06-04 16:00:09 +0000560static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000561 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000562{
563 u32 mask;
564
Alexander Duyckbd508172010-11-16 19:27:03 -0800565 switch (adapter->hw.mac.type) {
566 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000567 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800569 break;
570 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800571 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572 mask = (qmask & 0xFFFFFFFF);
573 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
574 mask = (qmask >> 32);
575 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800576 break;
577 default:
578 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000579 }
580}
581
Alexander Duyckd3d00232011-07-15 02:31:25 +0000582static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
583 struct ixgbe_tx_buffer *tx_buffer)
584{
585 if (tx_buffer->dma) {
586 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
587 dma_unmap_page(ring->dev,
588 tx_buffer->dma,
589 tx_buffer->length,
590 DMA_TO_DEVICE);
591 else
592 dma_unmap_single(ring->dev,
593 tx_buffer->dma,
594 tx_buffer->length,
595 DMA_TO_DEVICE);
596 }
597 tx_buffer->dma = 0;
598}
599
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800600void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
601 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700602{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000603 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
604 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700605 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000606 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700607 /* tx_buffer_info must be completely set up in the transmit path */
608}
609
John Fastabendc84d3242010-11-16 19:27:12 -0800610static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700611{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700612 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800613 struct ixgbe_hw_stats *hwstats = &adapter->stats;
614 u32 data = 0;
615 u32 xoff[8] = {0};
616 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700617
John Fastabendc84d3242010-11-16 19:27:12 -0800618 if ((hw->fc.current_mode == ixgbe_fc_full) ||
619 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
620 switch (hw->mac.type) {
621 case ixgbe_mac_82598EB:
622 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
623 break;
624 default:
625 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
626 }
627 hwstats->lxoffrxc += data;
628
629 /* refill credits (no tx hang) if we received xoff */
630 if (!data)
631 return;
632
633 for (i = 0; i < adapter->num_tx_queues; i++)
634 clear_bit(__IXGBE_HANG_CHECK_ARMED,
635 &adapter->tx_ring[i]->state);
636 return;
637 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
638 return;
639
640 /* update stats for each tc, only valid with PFC enabled */
641 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
642 switch (hw->mac.type) {
643 case ixgbe_mac_82598EB:
644 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
645 break;
646 default:
647 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
648 }
649 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700650 }
651
John Fastabendc84d3242010-11-16 19:27:12 -0800652 /* disarm tx queues that have received xoff frames */
653 for (i = 0; i < adapter->num_tx_queues; i++) {
654 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000655 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800656
657 if (xoff[tc])
658 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
659 }
660}
661
662static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
663{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000664 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800665}
666
667static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
668{
669 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
670 struct ixgbe_hw *hw = &adapter->hw;
671
672 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
673 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
674
675 if (head != tail)
676 return (head < tail) ?
677 tail - head : (tail + ring->count - head);
678
679 return 0;
680}
681
682static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
683{
684 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
685 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
686 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
687 bool ret = false;
688
689 clear_check_for_tx_hang(tx_ring);
690
691 /*
692 * Check for a hung queue, but be thorough. This verifies
693 * that a transmit has been completed since the previous
694 * check AND there is at least one packet pending. The
695 * ARMED bit is set to indicate a potential hang. The
696 * bit is cleared if a pause frame is received to remove
697 * false hang detection due to PFC or 802.3x frames. By
698 * requiring this to fail twice we avoid races with
699 * pfc clearing the ARMED bit and conditions where we
700 * run the check_tx_hang logic with a transmit completion
701 * pending but without time to complete it yet.
702 */
703 if ((tx_done_old == tx_done) && tx_pending) {
704 /* make sure it is true for two checks in a row */
705 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
706 &tx_ring->state);
707 } else {
708 /* update completed stats and continue */
709 tx_ring->tx_stats.tx_done_old = tx_done;
710 /* reset the countdown */
711 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
712 }
713
714 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700715}
716
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000717/**
718 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
719 * @adapter: driver private struct
720 **/
721static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
722{
723
724 /* Do the reset outside of interrupt context */
725 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
726 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
727 ixgbe_service_event_schedule(adapter);
728 }
729}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700730
Auke Kok9a799d72007-09-15 14:07:45 -0700731/**
732 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000733 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700734 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700735 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000736static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000737 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700738{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000739 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000740 struct ixgbe_tx_buffer *tx_buffer;
741 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700742 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000743 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000744 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700745
Alexander Duyckd3d00232011-07-15 02:31:25 +0000746 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000747 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800748
Alexander Duyck30065e62011-07-15 03:05:14 +0000749 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000750 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700751
Alexander Duyckd3d00232011-07-15 02:31:25 +0000752 /* if next_to_watch is not set then there is no work pending */
753 if (!eop_desc)
754 break;
755
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000756 /* prevent any other reads prior to eop_desc */
757 rmb();
758
Alexander Duyckd3d00232011-07-15 02:31:25 +0000759 /* if DD is not set pending work has not been completed */
760 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
761 break;
762
Alexander Duyckd3d00232011-07-15 02:31:25 +0000763 /* clear next_to_watch to prevent false hangs */
764 tx_buffer->next_to_watch = NULL;
765
Alexander Duyckd3d00232011-07-15 02:31:25 +0000766 do {
767 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000768 if (likely(tx_desc == eop_desc)) {
769 eop_desc = NULL;
770 dev_kfree_skb_any(tx_buffer->skb);
771 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800772
Alexander Duyckd3d00232011-07-15 02:31:25 +0000773 total_bytes += tx_buffer->bytecount;
774 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800775 }
776
Alexander Duyckd3d00232011-07-15 02:31:25 +0000777 tx_buffer++;
778 tx_desc++;
779 i++;
780 if (unlikely(i == tx_ring->count)) {
781 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700782
Alexander Duyckd3d00232011-07-15 02:31:25 +0000783 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000784 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000785 }
786
787 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800788 }
789
Auke Kok9a799d72007-09-15 14:07:45 -0700790 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000791 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800792 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000793 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000794 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000795 q_vector->tx.total_bytes += total_bytes;
796 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800797
John Fastabendc84d3242010-11-16 19:27:12 -0800798 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800799 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800800 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycke4f74022012-01-31 02:59:44 +0000801 tx_desc = IXGBE_TX_DESC(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800802 e_err(drv, "Detected Tx Unit Hang\n"
803 " Tx Queue <%d>\n"
804 " TDH, TDT <%x>, <%x>\n"
805 " next_to_use <%x>\n"
806 " next_to_clean <%x>\n"
807 "tx_buffer_info[next_to_clean]\n"
808 " time_stamp <%lx>\n"
809 " jiffies <%lx>\n",
810 tx_ring->queue_index,
811 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
812 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000813 tx_ring->next_to_use, i,
814 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800815
816 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
817
818 e_info(probe,
819 "tx hang %d detected on queue %d, resetting adapter\n",
820 adapter->tx_timeout_count + 1, tx_ring->queue_index);
821
822 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000823 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800824
825 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000826 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800827 }
Auke Kok9a799d72007-09-15 14:07:45 -0700828
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000829 netdev_tx_completed_queue(txring_txq(tx_ring),
830 total_packets, total_bytes);
831
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800832#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000833 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000834 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800835 /* Make sure that anybody stopping the queue after this
836 * sees the new next_to_clean.
837 */
838 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800839 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800840 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800841 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800842 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800843 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800844 }
Auke Kok9a799d72007-09-15 14:07:45 -0700845
Alexander Duyck59224552011-08-31 00:01:06 +0000846 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700847}
848
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400849#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800850static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800851 struct ixgbe_ring *tx_ring,
852 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800853{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000854 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000855 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
856 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800857
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800858 switch (hw->mac.type) {
859 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000860 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800861 break;
862 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800863 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000864 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
865 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
866 break;
867 default:
868 /* for unknown hardware do not write register */
869 return;
870 }
871
872 /*
873 * We can enable relaxed ordering for reads, but not writes when
874 * DCA is enabled. This is due to a known issue in some chipsets
875 * which will cause the DCA tag to be cleared.
876 */
877 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
878 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
879 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
880
881 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
882}
883
884static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
885 struct ixgbe_ring *rx_ring,
886 int cpu)
887{
888 struct ixgbe_hw *hw = &adapter->hw;
889 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
890 u8 reg_idx = rx_ring->reg_idx;
891
892
893 switch (hw->mac.type) {
894 case ixgbe_mac_82599EB:
895 case ixgbe_mac_X540:
896 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800897 break;
898 default:
899 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800900 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000901
902 /*
903 * We can enable relaxed ordering for reads, but not writes when
904 * DCA is enabled. This is due to a known issue in some chipsets
905 * which will cause the DCA tag to be cleared.
906 */
907 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
908 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
909 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
910
911 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800912}
913
914static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
915{
916 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000917 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800918 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800919
920 if (q_vector->cpu == cpu)
921 goto out_no_update;
922
Alexander Duycka5579282012-02-08 07:50:04 +0000923 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000924 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925
Alexander Duycka5579282012-02-08 07:50:04 +0000926 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000927 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800928
929 q_vector->cpu = cpu;
930out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800931 put_cpu();
932}
933
934static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
935{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800936 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800937 int i;
938
939 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
940 return;
941
Alexander Duycke35ec122009-05-21 13:07:12 +0000942 /* always use CB2 mode, difference is masked in the CB driver */
943 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
944
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800945 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
946 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
947 else
948 num_q_vectors = 1;
949
950 for (i = 0; i < num_q_vectors; i++) {
951 adapter->q_vector[i]->cpu = -1;
952 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800953 }
954}
955
956static int __ixgbe_notify_dca(struct device *dev, void *data)
957{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800958 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800959 unsigned long event = *(unsigned long *)data;
960
Don Skidmore2a72c312011-07-20 02:27:05 +0000961 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800962 return 0;
963
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800964 switch (event) {
965 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700966 /* if we're already enabled, don't do it again */
967 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
968 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300969 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700970 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800971 ixgbe_setup_dca(adapter);
972 break;
973 }
974 /* Fall Through since DCA is disabled. */
975 case DCA_PROVIDER_REMOVE:
976 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
977 dca_remove_requester(dev);
978 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
979 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
980 }
981 break;
982 }
983
Denis V. Lunev652f0932008-03-27 14:39:17 +0300984 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800985}
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000986
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000987#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +0000988static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
989 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000990 struct sk_buff *skb)
991{
Alexander Duyck8a0da212012-01-31 02:59:49 +0000992 if (ring->netdev->features & NETIF_F_RXHASH)
993 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000994}
995
Alexander Duyckf8003262012-03-03 02:35:52 +0000996#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -0700997/**
Alexander Duyckff886df2011-06-11 01:45:13 +0000998 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
999 * @adapter: address of board private structure
1000 * @rx_desc: advanced rx descriptor
1001 *
1002 * Returns : true if it is FCoE pkt
1003 */
1004static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1005 union ixgbe_adv_rx_desc *rx_desc)
1006{
1007 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1008
1009 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1010 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1011 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1012 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1013}
1014
Alexander Duyckf8003262012-03-03 02:35:52 +00001015#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001016/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001017 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001018 * @ring: structure containing ring specific data
1019 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001020 * @skb: skb currently being received and modified
1021 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001022static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001023 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001024 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001025{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001026 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001027
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001028 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001029 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001030 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001031
1032 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001033 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1034 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001035 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001036 return;
1037 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001038
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001039 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001040 return;
1041
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001042 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001043 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001044
1045 /*
1046 * 82599 errata, UDP frames with a 0 checksum can be marked as
1047 * checksum errors.
1048 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001049 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1050 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001051 return;
1052
Alexander Duyck8a0da212012-01-31 02:59:49 +00001053 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001054 return;
1055 }
1056
Auke Kok9a799d72007-09-15 14:07:45 -07001057 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001058 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001059}
1060
Alexander Duyck84ea2592010-11-16 19:26:49 -08001061static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001062{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001063 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001064
1065 /* update next to alloc since we have filled the ring */
1066 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001067 /*
1068 * Force memory writes to complete before letting h/w
1069 * know there are new descriptors to fetch. (Only
1070 * applicable for weak-ordered memory model archs,
1071 * such as IA-64).
1072 */
1073 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001074 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001075}
1076
Alexander Duyckf990b792012-01-31 02:59:34 +00001077static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1078 struct ixgbe_rx_buffer *bi)
1079{
1080 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001081 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001082
Alexander Duyckf8003262012-03-03 02:35:52 +00001083 /* since we are recycling buffers we should seldom need to alloc */
1084 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001085 return true;
1086
Alexander Duyckf8003262012-03-03 02:35:52 +00001087 /* alloc new page for storage */
1088 if (likely(!page)) {
1089 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1090 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001091 if (unlikely(!page)) {
1092 rx_ring->rx_stats.alloc_rx_page_failed++;
1093 return false;
1094 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001095 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001096 }
1097
Alexander Duyckf8003262012-03-03 02:35:52 +00001098 /* map page for use */
1099 dma = dma_map_page(rx_ring->dev, page, 0,
1100 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001101
Alexander Duyckf8003262012-03-03 02:35:52 +00001102 /*
1103 * if mapping failed free memory back to system since
1104 * there isn't much point in holding memory we can't use
1105 */
1106 if (dma_mapping_error(rx_ring->dev, dma)) {
1107 put_page(page);
1108 bi->page = NULL;
1109
Alexander Duyckf990b792012-01-31 02:59:34 +00001110 rx_ring->rx_stats.alloc_rx_page_failed++;
1111 return false;
1112 }
1113
Alexander Duyckf8003262012-03-03 02:35:52 +00001114 bi->dma = dma;
1115 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1116
Alexander Duyckf990b792012-01-31 02:59:34 +00001117 return true;
1118}
1119
Auke Kok9a799d72007-09-15 14:07:45 -07001120/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001121 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001122 * @rx_ring: ring to place buffers on
1123 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001124 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001125void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001126{
Auke Kok9a799d72007-09-15 14:07:45 -07001127 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001128 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001129 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001130
Alexander Duyckf8003262012-03-03 02:35:52 +00001131 /* nothing to do */
1132 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001133 return;
1134
Alexander Duycke4f74022012-01-31 02:59:44 +00001135 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001136 bi = &rx_ring->rx_buffer_info[i];
1137 i -= rx_ring->count;
1138
Alexander Duyckf8003262012-03-03 02:35:52 +00001139 do {
1140 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001141 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001142
Alexander Duyckf8003262012-03-03 02:35:52 +00001143 /*
1144 * Refresh the desc even if buffer_addrs didn't change
1145 * because each write-back erases this info.
1146 */
1147 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001148
Alexander Duyckf990b792012-01-31 02:59:34 +00001149 rx_desc++;
1150 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001151 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001152 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001153 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001154 bi = rx_ring->rx_buffer_info;
1155 i -= rx_ring->count;
1156 }
1157
1158 /* clear the hdr_addr for the next_to_use descriptor */
1159 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001160
1161 cleaned_count--;
1162 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001163
Alexander Duyckf990b792012-01-31 02:59:34 +00001164 i += rx_ring->count;
1165
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001166 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001167 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001168}
1169
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001170/**
1171 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1172 * @data: pointer to the start of the headers
1173 * @max_len: total length of section to find headers in
1174 *
1175 * This function is meant to determine the length of headers that will
1176 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1177 * motivation of doing this is to only perform one pull for IPv4 TCP
1178 * packets so that we can do basic things like calculating the gso_size
1179 * based on the average data per packet.
1180 **/
1181static unsigned int ixgbe_get_headlen(unsigned char *data,
1182 unsigned int max_len)
1183{
1184 union {
1185 unsigned char *network;
1186 /* l2 headers */
1187 struct ethhdr *eth;
1188 struct vlan_hdr *vlan;
1189 /* l3 headers */
1190 struct iphdr *ipv4;
1191 } hdr;
1192 __be16 protocol;
1193 u8 nexthdr = 0; /* default to not TCP */
1194 u8 hlen;
1195
1196 /* this should never happen, but better safe than sorry */
1197 if (max_len < ETH_HLEN)
1198 return max_len;
1199
1200 /* initialize network frame pointer */
1201 hdr.network = data;
1202
1203 /* set first protocol and move network header forward */
1204 protocol = hdr.eth->h_proto;
1205 hdr.network += ETH_HLEN;
1206
1207 /* handle any vlan tag if present */
1208 if (protocol == __constant_htons(ETH_P_8021Q)) {
1209 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1210 return max_len;
1211
1212 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1213 hdr.network += VLAN_HLEN;
1214 }
1215
1216 /* handle L3 protocols */
1217 if (protocol == __constant_htons(ETH_P_IP)) {
1218 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1219 return max_len;
1220
1221 /* access ihl as a u8 to avoid unaligned access on ia64 */
1222 hlen = (hdr.network[0] & 0x0F) << 2;
1223
1224 /* verify hlen meets minimum size requirements */
1225 if (hlen < sizeof(struct iphdr))
1226 return hdr.network - data;
1227
1228 /* record next protocol */
1229 nexthdr = hdr.ipv4->protocol;
1230 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001231#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001232 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1233 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1234 return max_len;
1235 hdr.network += FCOE_HEADER_LEN;
1236#endif
1237 } else {
1238 return hdr.network - data;
1239 }
1240
1241 /* finally sort out TCP */
1242 if (nexthdr == IPPROTO_TCP) {
1243 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1244 return max_len;
1245
1246 /* access doff as a u8 to avoid unaligned access on ia64 */
1247 hlen = (hdr.network[12] & 0xF0) >> 2;
1248
1249 /* verify hlen meets minimum size requirements */
1250 if (hlen < sizeof(struct tcphdr))
1251 return hdr.network - data;
1252
1253 hdr.network += hlen;
1254 }
1255
1256 /*
1257 * If everything has gone correctly hdr.network should be the
1258 * data section of the packet and will be the end of the header.
1259 * If not then it probably represents the end of the last recognized
1260 * header.
1261 */
1262 if ((hdr.network - data) < max_len)
1263 return hdr.network - data;
1264 else
1265 return max_len;
1266}
1267
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001268static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1269 union ixgbe_adv_rx_desc *rx_desc,
1270 struct sk_buff *skb)
1271{
1272 __le32 rsc_enabled;
1273 u32 rsc_cnt;
1274
1275 if (!ring_is_rsc_enabled(rx_ring))
1276 return;
1277
1278 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1279 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1280
1281 /* If this is an RSC frame rsc_cnt should be non-zero */
1282 if (!rsc_enabled)
1283 return;
1284
1285 rsc_cnt = le32_to_cpu(rsc_enabled);
1286 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1287
1288 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001289}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001290
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001291static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1292 struct sk_buff *skb)
1293{
Alexander Duyckf8003262012-03-03 02:35:52 +00001294 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001295
1296 /* set gso_size to avoid messing up TCP MSS */
1297 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1298 IXGBE_CB(skb)->append_cnt);
1299}
1300
1301static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1302 struct sk_buff *skb)
1303{
1304 /* if append_cnt is 0 then frame is not RSC */
1305 if (!IXGBE_CB(skb)->append_cnt)
1306 return;
1307
1308 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1309 rx_ring->rx_stats.rsc_flush++;
1310
1311 ixgbe_set_rsc_gso_size(rx_ring, skb);
1312
1313 /* gso_size is computed using append_cnt so always clear it last */
1314 IXGBE_CB(skb)->append_cnt = 0;
1315}
1316
Alexander Duyck8a0da212012-01-31 02:59:49 +00001317/**
1318 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1319 * @rx_ring: rx descriptor ring packet is being transacted on
1320 * @rx_desc: pointer to the EOP Rx descriptor
1321 * @skb: pointer to current skb being populated
1322 *
1323 * This function checks the ring, descriptor, and packet information in
1324 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1325 * other fields within the skb.
1326 **/
1327static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1328 union ixgbe_adv_rx_desc *rx_desc,
1329 struct sk_buff *skb)
1330{
1331 ixgbe_update_rsc_stats(rx_ring, skb);
1332
1333 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1334
1335 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1336
1337 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1338 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1339 __vlan_hwaccel_put_tag(skb, vid);
1340 }
1341
1342 skb_record_rx_queue(skb, rx_ring->queue_index);
1343
1344 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1345}
1346
1347static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1348 struct sk_buff *skb)
1349{
1350 struct ixgbe_adapter *adapter = q_vector->adapter;
1351
1352 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1353 napi_gro_receive(&q_vector->napi, skb);
1354 else
1355 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001356}
1357
Alexander Duyckf8003262012-03-03 02:35:52 +00001358/**
1359 * ixgbe_is_non_eop - process handling of non-EOP buffers
1360 * @rx_ring: Rx ring being processed
1361 * @rx_desc: Rx descriptor for current buffer
1362 * @skb: Current socket buffer containing buffer in progress
1363 *
1364 * This function updates next to clean. If the buffer is an EOP buffer
1365 * this function exits returning false, otherwise it will place the
1366 * sk_buff in the next buffer to be chained and return true indicating
1367 * that this is in fact a non-EOP buffer.
1368 **/
1369static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1370 union ixgbe_adv_rx_desc *rx_desc,
1371 struct sk_buff *skb)
1372{
1373 u32 ntc = rx_ring->next_to_clean + 1;
1374
1375 /* fetch, update, and store next to clean */
1376 ntc = (ntc < rx_ring->count) ? ntc : 0;
1377 rx_ring->next_to_clean = ntc;
1378
1379 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1380
1381 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1382 return false;
1383
1384 /* append_cnt indicates packet is RSC, if so fetch nextp */
1385 if (IXGBE_CB(skb)->append_cnt) {
1386 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1387 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1388 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1389 }
1390
1391 /* place skb in next buffer to be received */
1392 rx_ring->rx_buffer_info[ntc].skb = skb;
1393 rx_ring->rx_stats.non_eop_descs++;
1394
1395 return true;
1396}
1397
1398/**
1399 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1400 * @rx_ring: rx descriptor ring packet is being transacted on
1401 * @rx_desc: pointer to the EOP Rx descriptor
1402 * @skb: pointer to current skb being fixed
1403 *
1404 * Check for corrupted packet headers caused by senders on the local L2
1405 * embedded NIC switch not setting up their Tx Descriptors right. These
1406 * should be very rare.
1407 *
1408 * Also address the case where we are pulling data in on pages only
1409 * and as such no data is present in the skb header.
1410 *
1411 * In addition if skb is not at least 60 bytes we need to pad it so that
1412 * it is large enough to qualify as a valid Ethernet frame.
1413 *
1414 * Returns true if an error was encountered and skb was freed.
1415 **/
1416static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1417 union ixgbe_adv_rx_desc *rx_desc,
1418 struct sk_buff *skb)
1419{
1420 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1421 struct net_device *netdev = rx_ring->netdev;
1422 unsigned char *va;
1423 unsigned int pull_len;
1424
1425 /* if the page was released unmap it, else just sync our portion */
1426 if (unlikely(IXGBE_CB(skb)->page_released)) {
1427 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1428 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1429 IXGBE_CB(skb)->page_released = false;
1430 } else {
1431 dma_sync_single_range_for_cpu(rx_ring->dev,
1432 IXGBE_CB(skb)->dma,
1433 frag->page_offset,
1434 ixgbe_rx_bufsz(rx_ring),
1435 DMA_FROM_DEVICE);
1436 }
1437 IXGBE_CB(skb)->dma = 0;
1438
1439 /* verify that the packet does not have any known errors */
1440 if (unlikely(ixgbe_test_staterr(rx_desc,
1441 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1442 !(netdev->features & NETIF_F_RXALL))) {
1443 dev_kfree_skb_any(skb);
1444 return true;
1445 }
1446
1447 /*
1448 * it is valid to use page_address instead of kmap since we are
1449 * working with pages allocated out of the lomem pool per
1450 * alloc_page(GFP_ATOMIC)
1451 */
1452 va = skb_frag_address(frag);
1453
1454 /*
1455 * we need the header to contain the greater of either ETH_HLEN or
1456 * 60 bytes if the skb->len is less than 60 for skb_pad.
1457 */
1458 pull_len = skb_frag_size(frag);
1459 if (pull_len > 256)
1460 pull_len = ixgbe_get_headlen(va, pull_len);
1461
1462 /* align pull length to size of long to optimize memcpy performance */
1463 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1464
1465 /* update all of the pointers */
1466 skb_frag_size_sub(frag, pull_len);
1467 frag->page_offset += pull_len;
1468 skb->data_len -= pull_len;
1469 skb->tail += pull_len;
1470
1471 /*
1472 * if we sucked the frag empty then we should free it,
1473 * if there are other frags here something is screwed up in hardware
1474 */
1475 if (skb_frag_size(frag) == 0) {
1476 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1477 skb_shinfo(skb)->nr_frags = 0;
1478 __skb_frag_unref(frag);
1479 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1480 }
1481
1482 /* if skb_pad returns an error the skb was freed */
1483 if (unlikely(skb->len < 60)) {
1484 int pad_len = 60 - skb->len;
1485
1486 if (skb_pad(skb, pad_len))
1487 return true;
1488 __skb_put(skb, pad_len);
1489 }
1490
1491 return false;
1492}
1493
1494/**
1495 * ixgbe_can_reuse_page - determine if we can reuse a page
1496 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1497 *
1498 * Returns true if page can be reused in another Rx buffer
1499 **/
1500static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1501{
1502 struct page *page = rx_buffer->page;
1503
1504 /* if we are only owner of page and it is local we can reuse it */
1505 return likely(page_count(page) == 1) &&
1506 likely(page_to_nid(page) == numa_node_id());
1507}
1508
1509/**
1510 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1511 * @rx_ring: rx descriptor ring to store buffers on
1512 * @old_buff: donor buffer to have page reused
1513 *
1514 * Syncronizes page for reuse by the adapter
1515 **/
1516static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1517 struct ixgbe_rx_buffer *old_buff)
1518{
1519 struct ixgbe_rx_buffer *new_buff;
1520 u16 nta = rx_ring->next_to_alloc;
1521 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1522
1523 new_buff = &rx_ring->rx_buffer_info[nta];
1524
1525 /* update, and store next to alloc */
1526 nta++;
1527 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1528
1529 /* transfer page from old buffer to new buffer */
1530 new_buff->page = old_buff->page;
1531 new_buff->dma = old_buff->dma;
1532
1533 /* flip page offset to other buffer and store to new_buff */
1534 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1535
1536 /* sync the buffer for use by the device */
1537 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1538 new_buff->page_offset, bufsz,
1539 DMA_FROM_DEVICE);
1540
1541 /* bump ref count on page before it is given to the stack */
1542 get_page(new_buff->page);
1543}
1544
1545/**
1546 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1547 * @rx_ring: rx descriptor ring to transact packets on
1548 * @rx_buffer: buffer containing page to add
1549 * @rx_desc: descriptor containing length of buffer written by hardware
1550 * @skb: sk_buff to place the data into
1551 *
1552 * This function is based on skb_add_rx_frag. I would have used that
1553 * function however it doesn't handle the truesize case correctly since we
1554 * are allocating more memory than might be used for a single receive.
1555 **/
1556static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1557 struct ixgbe_rx_buffer *rx_buffer,
1558 struct sk_buff *skb, int size)
1559{
1560 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1561 rx_buffer->page, rx_buffer->page_offset,
1562 size);
1563 skb->len += size;
1564 skb->data_len += size;
1565 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1566}
1567
1568/**
1569 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1570 * @q_vector: structure containing interrupt and ring information
1571 * @rx_ring: rx descriptor ring to transact packets on
1572 * @budget: Total limit on number of packets to process
1573 *
1574 * This function provides a "bounce buffer" approach to Rx interrupt
1575 * processing. The advantage to this is that on systems that have
1576 * expensive overhead for IOMMU access this provides a means of avoiding
1577 * it by maintaining the mapping of the page to the syste.
1578 *
1579 * Returns true if all work is completed without reaching budget
1580 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001581static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001582 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001583 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001584{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001585 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001586#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001587 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001588 int ddp_bytes = 0;
1589#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001590 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001591
Alexander Duyckf8003262012-03-03 02:35:52 +00001592 do {
1593 struct ixgbe_rx_buffer *rx_buffer;
1594 union ixgbe_adv_rx_desc *rx_desc;
1595 struct sk_buff *skb;
1596 struct page *page;
1597 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001598
Alexander Duyckf8003262012-03-03 02:35:52 +00001599 /* return some buffers to hardware, one at a time is too slow */
1600 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1601 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1602 cleaned_count = 0;
1603 }
Auke Kok9a799d72007-09-15 14:07:45 -07001604
Alexander Duyckf8003262012-03-03 02:35:52 +00001605 ntc = rx_ring->next_to_clean;
1606 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1607 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001608
Alexander Duyckf8003262012-03-03 02:35:52 +00001609 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1610 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001611
Alexander Duyckf8003262012-03-03 02:35:52 +00001612 /*
1613 * This memory barrier is needed to keep us from reading
1614 * any other fields out of the rx_desc until we know the
1615 * RXD_STAT_DD bit is set
1616 */
1617 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001618
Alexander Duyckf8003262012-03-03 02:35:52 +00001619 page = rx_buffer->page;
1620 prefetchw(page);
1621
1622 skb = rx_buffer->skb;
1623
1624 if (likely(!skb)) {
1625 void *page_addr = page_address(page) +
1626 rx_buffer->page_offset;
1627
1628 /* prefetch first cache line of first page */
1629 prefetch(page_addr);
1630#if L1_CACHE_BYTES < 128
1631 prefetch(page_addr + L1_CACHE_BYTES);
1632#endif
1633
1634 /* allocate a skb to store the frags */
1635 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1636 IXGBE_RX_HDR_SIZE);
1637 if (unlikely(!skb)) {
1638 rx_ring->rx_stats.alloc_rx_buff_failed++;
1639 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001640 }
1641
Alexander Duyckf8003262012-03-03 02:35:52 +00001642 /*
1643 * we will be copying header into skb->data in
1644 * pskb_may_pull so it is in our interest to prefetch
1645 * it now to avoid a possible cache miss
1646 */
1647 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001648
1649 /*
1650 * Delay unmapping of the first packet. It carries the
1651 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001652 * after the writeback. Only unmap it when EOP is
1653 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001654 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001655 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001656 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001657 /* we are reusing so sync this buffer for CPU use */
1658 dma_sync_single_range_for_cpu(rx_ring->dev,
1659 rx_buffer->dma,
1660 rx_buffer->page_offset,
1661 ixgbe_rx_bufsz(rx_ring),
1662 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001663 }
1664
Alexander Duyckf8003262012-03-03 02:35:52 +00001665 /* pull page into skb */
1666 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1667 le16_to_cpu(rx_desc->wb.upper.length));
1668
1669 if (ixgbe_can_reuse_page(rx_buffer)) {
1670 /* hand second half of page back to the ring */
1671 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1672 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1673 /* the page has been released from the ring */
1674 IXGBE_CB(skb)->page_released = true;
1675 } else {
1676 /* we are not reusing the buffer so unmap it */
1677 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1678 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001679 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001680 }
1681
Alexander Duyckf8003262012-03-03 02:35:52 +00001682 /* clear contents of buffer_info */
1683 rx_buffer->skb = NULL;
1684 rx_buffer->dma = 0;
1685 rx_buffer->page = NULL;
1686
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001687 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1688
Auke Kok9a799d72007-09-15 14:07:45 -07001689 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001690
Alexander Duyckf8003262012-03-03 02:35:52 +00001691 /* place incomplete frames back on ring for completion */
1692 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1693 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001694
Alexander Duyckf8003262012-03-03 02:35:52 +00001695 /* verify the packet layout is correct */
1696 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1697 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001698
1699 /* probably a little skewed due to removing CRC */
1700 total_rx_bytes += skb->len;
1701 total_rx_packets++;
1702
Alexander Duyck8a0da212012-01-31 02:59:49 +00001703 /* populate checksum, timestamp, VLAN, and protocol */
1704 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1705
Yi Zou332d4a72009-05-13 13:11:53 +00001706#ifdef IXGBE_FCOE
1707 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001708 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001709 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001710 if (!ddp_bytes) {
1711 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001712 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001713 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001714 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001715
Yi Zou332d4a72009-05-13 13:11:53 +00001716#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001717 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001718
Alexander Duyckf8003262012-03-03 02:35:52 +00001719 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001720 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001721 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001722
Yi Zou3d8fd382009-06-08 14:38:44 +00001723#ifdef IXGBE_FCOE
1724 /* include DDPed FCoE data */
1725 if (ddp_bytes > 0) {
1726 unsigned int mss;
1727
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001728 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001729 sizeof(struct fc_frame_header) -
1730 sizeof(struct fcoe_crc_eof);
1731 if (mss > 512)
1732 mss &= ~511;
1733 total_rx_bytes += ddp_bytes;
1734 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1735 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001736
Alexander Duyckf8003262012-03-03 02:35:52 +00001737#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001738 u64_stats_update_begin(&rx_ring->syncp);
1739 rx_ring->stats.packets += total_rx_packets;
1740 rx_ring->stats.bytes += total_rx_bytes;
1741 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001742 q_vector->rx.total_packets += total_rx_packets;
1743 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001744
Alexander Duyckf8003262012-03-03 02:35:52 +00001745 if (cleaned_count)
1746 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1747
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001748 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001749}
1750
Auke Kok9a799d72007-09-15 14:07:45 -07001751/**
1752 * ixgbe_configure_msix - Configure MSI-X hardware
1753 * @adapter: board private structure
1754 *
1755 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1756 * interrupts.
1757 **/
1758static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1759{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001760 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001761 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001762 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001763
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001764 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1765
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001766 /* Populate MSIX to EITR Select */
1767 if (adapter->num_vfs > 32) {
1768 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1769 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1770 }
1771
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001772 /*
1773 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001774 * corresponding register.
1775 */
1776 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001777 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001778 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001779
Alexander Duycka5579282012-02-08 07:50:04 +00001780 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001781 ixgbe_set_ivar(adapter, 0, ring->reg_idx, 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->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001784 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001785
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001786 if (q_vector->tx.ring && !q_vector->rx.ring) {
1787 /* tx only vector */
1788 if (adapter->tx_itr_setting == 1)
1789 q_vector->itr = IXGBE_10K_ITR;
1790 else
1791 q_vector->itr = adapter->tx_itr_setting;
1792 } else {
1793 /* rx or rx/tx vector */
1794 if (adapter->rx_itr_setting == 1)
1795 q_vector->itr = IXGBE_20K_ITR;
1796 else
1797 q_vector->itr = adapter->rx_itr_setting;
1798 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001799
Alexander Duyckfe49f042009-06-04 16:00:09 +00001800 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001801 }
1802
Alexander Duyckbd508172010-11-16 19:27:03 -08001803 switch (adapter->hw.mac.type) {
1804 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001805 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001806 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001807 break;
1808 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001809 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001810 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001811 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001812 default:
1813 break;
1814 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001815 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001816
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001817 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001818 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001819 mask &= ~(IXGBE_EIMS_OTHER |
1820 IXGBE_EIMS_MAILBOX |
1821 IXGBE_EIMS_LSC);
1822
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001823 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001824}
1825
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001826enum latency_range {
1827 lowest_latency = 0,
1828 low_latency = 1,
1829 bulk_latency = 2,
1830 latency_invalid = 255
1831};
1832
1833/**
1834 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001835 * @q_vector: structure containing interrupt and ring information
1836 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001837 *
1838 * Stores a new ITR value based on packets and byte
1839 * counts during the last interrupt. The advantage of per interrupt
1840 * computation is faster updates and more accurate ITR for the current
1841 * traffic pattern. Constants in this function were computed
1842 * based on theoretical maximum wire speed and thresholds were set based
1843 * on testing data as well as attempting to minimize response time
1844 * while increasing bulk throughput.
1845 * this functionality is controlled by the InterruptThrottleRate module
1846 * parameter (see ixgbe_param.c)
1847 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001848static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1849 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001850{
Alexander Duyckbd198052011-06-11 01:45:08 +00001851 int bytes = ring_container->total_bytes;
1852 int packets = ring_container->total_packets;
1853 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001854 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001855 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001856
1857 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001858 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001859
1860 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001861 * 0-10MB/s lowest (100000 ints/s)
1862 * 10-20MB/s low (20000 ints/s)
1863 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001864 */
1865 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001866 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001867 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1868
1869 switch (itr_setting) {
1870 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001871 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001872 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001873 break;
1874 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001875 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001876 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001877 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001878 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001879 break;
1880 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001881 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001882 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001883 break;
1884 }
1885
Alexander Duyckbd198052011-06-11 01:45:08 +00001886 /* clear work counters since we have the values we need */
1887 ring_container->total_bytes = 0;
1888 ring_container->total_packets = 0;
1889
1890 /* write updated itr to ring container */
1891 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001892}
1893
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001894/**
1895 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001896 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001897 *
1898 * This function is made to be called by ethtool and by the driver
1899 * when it needs to update EITR registers at runtime. Hardware
1900 * specific quirks/differences are taken care of here.
1901 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001902void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001903{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001904 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001905 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001906 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001907 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001908
Alexander Duyckbd508172010-11-16 19:27:03 -08001909 switch (adapter->hw.mac.type) {
1910 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001911 /* must write high and low 16 bits to reset counter */
1912 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001913 break;
1914 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001915 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001916 /*
1917 * set the WDIS bit to not clear the timer bits and cause an
1918 * immediate assertion of the interrupt
1919 */
1920 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001921 break;
1922 default:
1923 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001924 }
1925 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1926}
1927
Alexander Duyckbd198052011-06-11 01:45:08 +00001928static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001929{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001930 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001931 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001932
Alexander Duyckbd198052011-06-11 01:45:08 +00001933 ixgbe_update_itr(q_vector, &q_vector->tx);
1934 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001935
Alexander Duyck08c88332011-06-11 01:45:03 +00001936 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001937
1938 switch (current_itr) {
1939 /* counts and packets in update_itr are dependent on these numbers */
1940 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001941 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001942 break;
1943 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001944 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001945 break;
1946 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001947 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001948 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001949 default:
1950 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001951 }
1952
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001953 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001954 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001955 new_itr = (10 * new_itr * q_vector->itr) /
1956 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001957
Alexander Duyckbd198052011-06-11 01:45:08 +00001958 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001959 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001960
1961 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001962 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001963}
1964
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001965/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00001966 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00001967 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001968 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001969static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001970{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001971 struct ixgbe_hw *hw = &adapter->hw;
1972 u32 eicr = adapter->interrupt_event;
1973
Alexander Duyckf0f97782011-04-22 04:08:09 +00001974 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001975 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001976
Alexander Duyckf0f97782011-04-22 04:08:09 +00001977 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1978 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1979 return;
1980
1981 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1982
Joe Perches7ca647b2010-09-07 21:35:40 +00001983 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001984 case IXGBE_DEV_ID_82599_T3_LOM:
1985 /*
1986 * Since the warning interrupt is for both ports
1987 * we don't have to check if:
1988 * - This interrupt wasn't for our port.
1989 * - We may have missed the interrupt so always have to
1990 * check if we got a LSC
1991 */
1992 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1993 !(eicr & IXGBE_EICR_LSC))
1994 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001995
Alexander Duyckf0f97782011-04-22 04:08:09 +00001996 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1997 u32 autoneg;
1998 bool link_up = false;
1999
Joe Perches7ca647b2010-09-07 21:35:40 +00002000 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2001
Alexander Duyckf0f97782011-04-22 04:08:09 +00002002 if (link_up)
2003 return;
2004 }
2005
2006 /* Check if this is not due to overtemp */
2007 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2008 return;
2009
2010 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002011 default:
2012 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2013 return;
2014 break;
2015 }
2016 e_crit(drv,
2017 "Network adapter has been stopped because it has over heated. "
2018 "Restart the computer. If the problem persists, "
2019 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002020
2021 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002022}
2023
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002024static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2025{
2026 struct ixgbe_hw *hw = &adapter->hw;
2027
2028 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2029 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002030 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002031 /* write to clear the interrupt */
2032 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2033 }
2034}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002035
Jacob Keller4f51bf72011-08-20 04:49:45 +00002036static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2037{
2038 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2039 return;
2040
2041 switch (adapter->hw.mac.type) {
2042 case ixgbe_mac_82599EB:
2043 /*
2044 * Need to check link state so complete overtemp check
2045 * on service task
2046 */
2047 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2048 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2049 adapter->interrupt_event = eicr;
2050 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2051 ixgbe_service_event_schedule(adapter);
2052 return;
2053 }
2054 return;
2055 case ixgbe_mac_X540:
2056 if (!(eicr & IXGBE_EICR_TS))
2057 return;
2058 break;
2059 default:
2060 return;
2061 }
2062
2063 e_crit(drv,
2064 "Network adapter has been stopped because it has over heated. "
2065 "Restart the computer. If the problem persists, "
2066 "power off the system and replace the adapter\n");
2067}
2068
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002069static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2070{
2071 struct ixgbe_hw *hw = &adapter->hw;
2072
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002073 if (eicr & IXGBE_EICR_GPI_SDP2) {
2074 /* Clear the interrupt */
2075 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002076 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2077 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2078 ixgbe_service_event_schedule(adapter);
2079 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002080 }
2081
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002082 if (eicr & IXGBE_EICR_GPI_SDP1) {
2083 /* Clear the interrupt */
2084 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002085 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2086 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2087 ixgbe_service_event_schedule(adapter);
2088 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002089 }
2090}
2091
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002092static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2093{
2094 struct ixgbe_hw *hw = &adapter->hw;
2095
2096 adapter->lsc_int++;
2097 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2098 adapter->link_check_timeout = jiffies;
2099 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2100 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002101 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002102 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002103 }
2104}
2105
Alexander Duyckfe49f042009-06-04 16:00:09 +00002106static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2107 u64 qmask)
2108{
2109 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002110 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002111
Alexander Duyckbd508172010-11-16 19:27:03 -08002112 switch (hw->mac.type) {
2113 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002114 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002115 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2116 break;
2117 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002118 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002119 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002120 if (mask)
2121 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002122 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002123 if (mask)
2124 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2125 break;
2126 default:
2127 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002128 }
2129 /* skip the flush */
2130}
2131
2132static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002133 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002134{
2135 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002136 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002137
Alexander Duyckbd508172010-11-16 19:27:03 -08002138 switch (hw->mac.type) {
2139 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002140 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002141 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2142 break;
2143 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002144 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002145 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002146 if (mask)
2147 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002148 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002149 if (mask)
2150 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2151 break;
2152 default:
2153 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002154 }
2155 /* skip the flush */
2156}
2157
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002158/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002159 * ixgbe_irq_enable - Enable default interrupt generation settings
2160 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002161 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002162static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2163 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002164{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002165 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002166
Alexander Duyck2c4af692011-07-15 07:29:55 +00002167 /* don't reenable LSC while waiting for link */
2168 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2169 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002170
Alexander Duyck2c4af692011-07-15 07:29:55 +00002171 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002172 switch (adapter->hw.mac.type) {
2173 case ixgbe_mac_82599EB:
2174 mask |= IXGBE_EIMS_GPI_SDP0;
2175 break;
2176 case ixgbe_mac_X540:
2177 mask |= IXGBE_EIMS_TS;
2178 break;
2179 default:
2180 break;
2181 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002182 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2183 mask |= IXGBE_EIMS_GPI_SDP1;
2184 switch (adapter->hw.mac.type) {
2185 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002186 mask |= IXGBE_EIMS_GPI_SDP1;
2187 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002188 case ixgbe_mac_X540:
2189 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002190 mask |= IXGBE_EIMS_MAILBOX;
2191 break;
2192 default:
2193 break;
2194 }
2195 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2196 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2197 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002198
Alexander Duyck2c4af692011-07-15 07:29:55 +00002199 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2200 if (queues)
2201 ixgbe_irq_enable_queues(adapter, ~0);
2202 if (flush)
2203 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002204}
2205
Alexander Duyck2c4af692011-07-15 07:29:55 +00002206static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002207{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002208 struct ixgbe_adapter *adapter = data;
2209 struct ixgbe_hw *hw = &adapter->hw;
2210 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002211
Alexander Duyck2c4af692011-07-15 07:29:55 +00002212 /*
2213 * Workaround for Silicon errata. Use clear-by-write instead
2214 * of clear-by-read. Reading with EICS will return the
2215 * interrupt causes without clearing, which later be done
2216 * with the write to EICR.
2217 */
2218 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2219 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002220
Alexander Duyck2c4af692011-07-15 07:29:55 +00002221 if (eicr & IXGBE_EICR_LSC)
2222 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002223
Alexander Duyck2c4af692011-07-15 07:29:55 +00002224 if (eicr & IXGBE_EICR_MAILBOX)
2225 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226
Alexander Duyck2c4af692011-07-15 07:29:55 +00002227 switch (hw->mac.type) {
2228 case ixgbe_mac_82599EB:
2229 case ixgbe_mac_X540:
2230 if (eicr & IXGBE_EICR_ECC)
2231 e_info(link, "Received unrecoverable ECC Err, please "
2232 "reboot\n");
2233 /* Handle Flow Director Full threshold interrupt */
2234 if (eicr & IXGBE_EICR_FLOW_DIR) {
2235 int reinit_count = 0;
2236 int i;
2237 for (i = 0; i < adapter->num_tx_queues; i++) {
2238 struct ixgbe_ring *ring = adapter->tx_ring[i];
2239 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2240 &ring->state))
2241 reinit_count++;
2242 }
2243 if (reinit_count) {
2244 /* no more flow director interrupts until after init */
2245 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2246 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2247 ixgbe_service_event_schedule(adapter);
2248 }
2249 }
2250 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002251 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002252 break;
2253 default:
2254 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002255 }
2256
Alexander Duyck2c4af692011-07-15 07:29:55 +00002257 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002258
Alexander Duyck2c4af692011-07-15 07:29:55 +00002259 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002260 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002261 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002262
Alexander Duyck2c4af692011-07-15 07:29:55 +00002263 return IRQ_HANDLED;
2264}
2265
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002266static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002267{
2268 struct ixgbe_q_vector *q_vector = data;
2269
Auke Kok9a799d72007-09-15 14:07:45 -07002270 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002271
2272 if (q_vector->rx.ring || q_vector->tx.ring)
2273 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002274
2275 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002276}
2277
Auke Kok9a799d72007-09-15 14:07:45 -07002278/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002279 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2280 * @adapter: board private structure
2281 *
2282 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2283 * interrupts from the kernel.
2284 **/
2285static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2286{
2287 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002288 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2289 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002290 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002291
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002293 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002294 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002295
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002296 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002297 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002298 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002299 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002300 } else if (q_vector->rx.ring) {
2301 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2302 "%s-%s-%d", netdev->name, "rx", ri++);
2303 } else if (q_vector->tx.ring) {
2304 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2305 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002306 } else {
2307 /* skip this unused q_vector */
2308 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002309 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002310 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2311 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002313 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002314 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315 goto free_queue_irqs;
2316 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002317 /* If Flow Director is enabled, set interrupt affinity */
2318 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2319 /* assign the mask for this irq */
2320 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002321 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002322 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002323 }
2324
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002326 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002328 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002329 goto free_queue_irqs;
2330 }
2331
2332 return 0;
2333
2334free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002335 while (vector) {
2336 vector--;
2337 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2338 NULL);
2339 free_irq(adapter->msix_entries[vector].vector,
2340 adapter->q_vector[vector]);
2341 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002342 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2343 pci_disable_msix(adapter->pdev);
2344 kfree(adapter->msix_entries);
2345 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 return err;
2347}
2348
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002349/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002350 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002351 * @irq: interrupt number
2352 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002353 **/
2354static irqreturn_t ixgbe_intr(int irq, void *data)
2355{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002356 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002357 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002358 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002359 u32 eicr;
2360
Don Skidmore54037502009-02-21 15:42:56 -08002361 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002362 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002363 * before the read of EICR.
2364 */
2365 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2366
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002367 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002368 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002370 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002371 /*
2372 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002373 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002374 * have disabled interrupts due to EIAM
2375 * finish the workaround of silicon errata on 82598. Unmask
2376 * the interrupt that we masked before the EICR read.
2377 */
2378 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2379 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002380 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002381 }
Auke Kok9a799d72007-09-15 14:07:45 -07002382
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002383 if (eicr & IXGBE_EICR_LSC)
2384 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002385
Alexander Duyckbd508172010-11-16 19:27:03 -08002386 switch (hw->mac.type) {
2387 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002388 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002389 /* Fall through */
2390 case ixgbe_mac_X540:
2391 if (eicr & IXGBE_EICR_ECC)
2392 e_info(link, "Received unrecoverable ECC err, please "
2393 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002394 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002395 break;
2396 default:
2397 break;
2398 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002399
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002400 ixgbe_check_fan_failure(adapter, eicr);
2401
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002402 /* would disable interrupts here but EIAM disabled it */
2403 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002404
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002405 /*
2406 * re-enable link(maybe) and non-queue interrupts, no flush.
2407 * ixgbe_poll will re-enable the queue interrupts
2408 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002409 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2410 ixgbe_irq_enable(adapter, false, false);
2411
Auke Kok9a799d72007-09-15 14:07:45 -07002412 return IRQ_HANDLED;
2413}
2414
2415/**
2416 * ixgbe_request_irq - initialize interrupts
2417 * @adapter: board private structure
2418 *
2419 * Attempts to configure interrupts using the best available
2420 * capabilities of the hardware and kernel.
2421 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002422static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002423{
2424 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002425 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002426
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002427 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002428 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002429 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002430 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002431 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002432 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002433 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002434 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002435
Alexander Duyckde88eee2012-02-08 07:49:59 +00002436 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002437 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002438
Auke Kok9a799d72007-09-15 14:07:45 -07002439 return err;
2440}
2441
2442static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2443{
Auke Kok9a799d72007-09-15 14:07:45 -07002444 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002445 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002446
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002447 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002449 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002451
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002453 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002454 if (!adapter->q_vector[i]->rx.ring &&
2455 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002456 continue;
2457
Alexander Duyck207867f2011-07-15 03:05:37 +00002458 /* clear the affinity_mask in the IRQ descriptor */
2459 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2460 NULL);
2461
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002462 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002463 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002464 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002465 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002466 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002467 }
2468}
2469
2470/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002471 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2472 * @adapter: board private structure
2473 **/
2474static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2475{
Alexander Duyckbd508172010-11-16 19:27:03 -08002476 switch (adapter->hw.mac.type) {
2477 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002478 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002479 break;
2480 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002481 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002482 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2483 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002484 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002485 break;
2486 default:
2487 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002488 }
2489 IXGBE_WRITE_FLUSH(&adapter->hw);
2490 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2491 int i;
2492 for (i = 0; i < adapter->num_msix_vectors; i++)
2493 synchronize_irq(adapter->msix_entries[i].vector);
2494 } else {
2495 synchronize_irq(adapter->pdev->irq);
2496 }
2497}
2498
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002499/**
Auke Kok9a799d72007-09-15 14:07:45 -07002500 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2501 *
2502 **/
2503static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2504{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002505 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002506
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002507 /* rx/tx vector */
2508 if (adapter->rx_itr_setting == 1)
2509 q_vector->itr = IXGBE_20K_ITR;
2510 else
2511 q_vector->itr = adapter->rx_itr_setting;
2512
2513 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002514
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002515 ixgbe_set_ivar(adapter, 0, 0, 0);
2516 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517
Emil Tantilov396e7992010-07-01 20:05:12 +00002518 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002519}
2520
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002521/**
2522 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2523 * @adapter: board private structure
2524 * @ring: structure containing ring specific data
2525 *
2526 * Configure the Tx descriptor ring after a reset.
2527 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002528void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2529 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002530{
2531 struct ixgbe_hw *hw = &adapter->hw;
2532 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002533 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002534 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002535 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002536
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002537 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002538 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002539 IXGBE_WRITE_FLUSH(hw);
2540
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002541 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002542 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002543 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2544 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2545 ring->count * sizeof(union ixgbe_adv_tx_desc));
2546 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2547 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002548 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002549
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002550 /*
2551 * set WTHRESH to encourage burst writeback, it should not be set
2552 * higher than 1 when ITR is 0 as it could cause false TX hangs
2553 *
2554 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2555 * to or less than the number of on chip descriptors, which is
2556 * currently 40.
2557 */
Alexander Duycke954b372012-02-08 07:49:38 +00002558 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002559 txdctl |= (1 << 16); /* WTHRESH = 1 */
2560 else
2561 txdctl |= (8 << 16); /* WTHRESH = 8 */
2562
Alexander Duycke954b372012-02-08 07:49:38 +00002563 /*
2564 * Setting PTHRESH to 32 both improves performance
2565 * and avoids a TX hang with DFP enabled
2566 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002567 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2568 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002569
2570 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002571 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2572 adapter->atr_sample_rate) {
2573 ring->atr_sample_rate = adapter->atr_sample_rate;
2574 ring->atr_count = 0;
2575 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2576 } else {
2577 ring->atr_sample_rate = 0;
2578 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002579
John Fastabendc84d3242010-11-16 19:27:12 -08002580 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2581
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002582 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002583 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2584
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002585 netdev_tx_reset_queue(txring_txq(ring));
2586
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002587 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2588 if (hw->mac.type == ixgbe_mac_82598EB &&
2589 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2590 return;
2591
2592 /* poll to verify queue is enabled */
2593 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002594 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002595 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2596 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2597 if (!wait_loop)
2598 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002599}
2600
Alexander Duyck120ff942010-08-19 13:34:50 +00002601static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2602{
2603 struct ixgbe_hw *hw = &adapter->hw;
2604 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002605 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002606 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002607
2608 if (hw->mac.type == ixgbe_mac_82598EB)
2609 return;
2610
2611 /* disable the arbiter while setting MTQC */
2612 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2613 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2614 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2615
2616 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002617 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002618 case (IXGBE_FLAG_SRIOV_ENABLED):
2619 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2620 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2621 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002622 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002623 if (!tcs)
2624 reg = IXGBE_MTQC_64Q_1PB;
2625 else if (tcs <= 4)
2626 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2627 else
2628 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2629
2630 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2631
2632 /* Enable Security TX Buffer IFG for multiple pb */
2633 if (tcs) {
2634 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2635 reg |= IXGBE_SECTX_DCB;
2636 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2637 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002638 break;
2639 }
2640
2641 /* re-enable the arbiter */
2642 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2643 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2644}
2645
Auke Kok9a799d72007-09-15 14:07:45 -07002646/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002647 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002648 * @adapter: board private structure
2649 *
2650 * Configure the Tx unit of the MAC after a reset.
2651 **/
2652static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2653{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002654 struct ixgbe_hw *hw = &adapter->hw;
2655 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002656 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002657
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002658 ixgbe_setup_mtqc(adapter);
2659
2660 if (hw->mac.type != ixgbe_mac_82598EB) {
2661 /* DMATXCTL.EN must be before Tx queues are enabled */
2662 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2663 dmatxctl |= IXGBE_DMATXCTL_TE;
2664 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2665 }
2666
Auke Kok9a799d72007-09-15 14:07:45 -07002667 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002668 for (i = 0; i < adapter->num_tx_queues; i++)
2669 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002670}
2671
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002672#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002673
Yi Zoua6616b42009-08-06 13:05:23 +00002674static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002675 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002676{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002677 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002678 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002679
Alexander Duyckbd508172010-11-16 19:27:03 -08002680 switch (adapter->hw.mac.type) {
2681 case ixgbe_mac_82598EB: {
2682 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2683 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002684 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002685 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002686 break;
2687 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002688 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002689 default:
2690 break;
2691 }
2692
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002693 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002694
2695 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2696 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002697 if (adapter->num_vfs)
2698 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002699
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002700 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2701 IXGBE_SRRCTL_BSIZEHDR_MASK;
2702
Alexander Duyckf8003262012-03-03 02:35:52 +00002703#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2704 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002705#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002706 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002707#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002708 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002709
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002710 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002711}
2712
Alexander Duyck05abb122010-08-19 13:35:41 +00002713static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002714{
Alexander Duyck05abb122010-08-19 13:35:41 +00002715 struct ixgbe_hw *hw = &adapter->hw;
2716 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002717 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2718 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002719 u32 mrqc = 0, reta = 0;
2720 u32 rxcsum;
2721 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002722 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002723 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2724
2725 if (tcs)
2726 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002727
Alexander Duyck05abb122010-08-19 13:35:41 +00002728 /* Fill out hash function seeds */
2729 for (i = 0; i < 10; i++)
2730 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002731
Alexander Duyck05abb122010-08-19 13:35:41 +00002732 /* Fill out redirection table */
2733 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002734 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002735 j = 0;
2736 /* reta = 4-byte sliding window of
2737 * 0x00..(indices-1)(indices-1)00..etc. */
2738 reta = (reta << 8) | (j * 0x11);
2739 if ((i & 3) == 3)
2740 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2741 }
2742
2743 /* Disable indicating checksum in descriptor, enables RSS hash */
2744 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2745 rxcsum |= IXGBE_RXCSUM_PCSD;
2746 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2747
John Fastabend8b1c0b22011-05-03 02:26:48 +00002748 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2749 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002750 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002751 } else {
2752 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2753 | IXGBE_FLAG_SRIOV_ENABLED);
2754
2755 switch (mask) {
2756 case (IXGBE_FLAG_RSS_ENABLED):
2757 if (!tcs)
2758 mrqc = IXGBE_MRQC_RSSEN;
2759 else if (tcs <= 4)
2760 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2761 else
2762 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2763 break;
2764 case (IXGBE_FLAG_SRIOV_ENABLED):
2765 mrqc = IXGBE_MRQC_VMDQEN;
2766 break;
2767 default:
2768 break;
2769 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002770 }
2771
Alexander Duyck05abb122010-08-19 13:35:41 +00002772 /* Perform hash on these packet types */
2773 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2774 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2775 | IXGBE_MRQC_RSS_FIELD_IPV6
2776 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2777
2778 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002779}
2780
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002781/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002782 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2783 * @adapter: address of board private structure
2784 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002785 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002786static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002787 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002788{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002789 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002790 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002791 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002792
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002793 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002794 return;
2795
Alexander Duyck73670962010-08-19 13:38:34 +00002796 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002797 rscctrl |= IXGBE_RSCCTL_RSCEN;
2798 /*
2799 * we must limit the number of descriptors so that the
2800 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002801 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002802 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002803#if (PAGE_SIZE <= 8192)
2804 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2805#elif (PAGE_SIZE <= 16384)
2806 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002807#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002808 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002809#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002810 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002811}
2812
Alexander Duyck9e10e042010-08-19 13:40:06 +00002813/**
2814 * ixgbe_set_uta - Set unicast filter table address
2815 * @adapter: board private structure
2816 *
2817 * The unicast table address is a register array of 32-bit registers.
2818 * The table is meant to be used in a way similar to how the MTA is used
2819 * however due to certain limitations in the hardware it is necessary to
2820 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2821 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2822 **/
2823static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2824{
2825 struct ixgbe_hw *hw = &adapter->hw;
2826 int i;
2827
2828 /* The UTA table only exists on 82599 hardware and newer */
2829 if (hw->mac.type < ixgbe_mac_82599EB)
2830 return;
2831
2832 /* we only need to do this if VMDq is enabled */
2833 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2834 return;
2835
2836 for (i = 0; i < 128; i++)
2837 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2838}
2839
2840#define IXGBE_MAX_RX_DESC_POLL 10
2841static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2842 struct ixgbe_ring *ring)
2843{
2844 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002845 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2846 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002847 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002848
2849 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2850 if (hw->mac.type == ixgbe_mac_82598EB &&
2851 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2852 return;
2853
2854 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002855 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002856 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2857 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2858
2859 if (!wait_loop) {
2860 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2861 "the polling period\n", reg_idx);
2862 }
2863}
2864
Yi Zou2d39d572011-01-06 14:29:56 +00002865void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2866 struct ixgbe_ring *ring)
2867{
2868 struct ixgbe_hw *hw = &adapter->hw;
2869 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2870 u32 rxdctl;
2871 u8 reg_idx = ring->reg_idx;
2872
2873 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2874 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2875
2876 /* write value back with RXDCTL.ENABLE bit cleared */
2877 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2878
2879 if (hw->mac.type == ixgbe_mac_82598EB &&
2880 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2881 return;
2882
2883 /* the hardware may take up to 100us to really disable the rx queue */
2884 do {
2885 udelay(10);
2886 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2887 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2888
2889 if (!wait_loop) {
2890 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2891 "the polling period\n", reg_idx);
2892 }
2893}
2894
Alexander Duyck84418e32010-08-19 13:40:54 +00002895void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2896 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002897{
2898 struct ixgbe_hw *hw = &adapter->hw;
2899 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002900 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002901 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002902
Alexander Duyck9e10e042010-08-19 13:40:06 +00002903 /* disable queue to avoid issues while updating state */
2904 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002905 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002906
Alexander Duyckacd37172010-08-19 13:36:05 +00002907 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2908 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2909 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2910 ring->count * sizeof(union ixgbe_adv_rx_desc));
2911 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2912 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002913 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002914
2915 ixgbe_configure_srrctl(adapter, ring);
2916 ixgbe_configure_rscctl(adapter, ring);
2917
Greg Rosee9f98072011-01-26 01:06:07 +00002918 /* If operating in IOV mode set RLPML for X540 */
2919 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2920 hw->mac.type == ixgbe_mac_X540) {
2921 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2922 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2923 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2924 }
2925
Alexander Duyck9e10e042010-08-19 13:40:06 +00002926 if (hw->mac.type == ixgbe_mac_82598EB) {
2927 /*
2928 * enable cache line friendly hardware writes:
2929 * PTHRESH=32 descriptors (half the internal cache),
2930 * this also removes ugly rx_no_buffer_count increment
2931 * HTHRESH=4 descriptors (to minimize latency on fetch)
2932 * WTHRESH=8 burst writeback up to two cache lines
2933 */
2934 rxdctl &= ~0x3FFFFF;
2935 rxdctl |= 0x080420;
2936 }
2937
2938 /* enable receive descriptor ring */
2939 rxdctl |= IXGBE_RXDCTL_ENABLE;
2940 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2941
2942 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002943 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002944}
2945
Alexander Duyck48654522010-08-19 13:36:27 +00002946static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2947{
2948 struct ixgbe_hw *hw = &adapter->hw;
2949 int p;
2950
2951 /* PSRTYPE must be initialized in non 82598 adapters */
2952 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002953 IXGBE_PSRTYPE_UDPHDR |
2954 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002955 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002956 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002957
2958 if (hw->mac.type == ixgbe_mac_82598EB)
2959 return;
2960
2961 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2962 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2963
2964 for (p = 0; p < adapter->num_rx_pools; p++)
2965 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2966 psrtype);
2967}
2968
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002969static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2970{
2971 struct ixgbe_hw *hw = &adapter->hw;
2972 u32 gcr_ext;
2973 u32 vt_reg_bits;
2974 u32 reg_offset, vf_shift;
2975 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00002976 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002977
2978 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2979 return;
2980
2981 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2982 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2983 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2984 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2985
2986 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00002987 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002988
2989 /* Enable only the PF's pool for Tx/Rx */
2990 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2991 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2992 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2993 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2994 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2995
2996 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2997 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
2998
2999 /*
3000 * Set up VF register offsets for selected VT Mode,
3001 * i.e. 32 or 64 VFs for SR-IOV
3002 */
3003 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3004 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3005 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3006 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3007
3008 /* enable Tx loopback for VF/PF communication */
3009 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003010 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003011 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003012 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003013 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003014 /* For VFs that have spoof checking turned off */
3015 for (i = 0; i < adapter->num_vfs; i++) {
3016 if (!adapter->vfinfo[i].spoofchk_enabled)
3017 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3018 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003019}
3020
Alexander Duyck477de6e2010-08-19 13:38:11 +00003021static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003022{
Auke Kok9a799d72007-09-15 14:07:45 -07003023 struct ixgbe_hw *hw = &adapter->hw;
3024 struct net_device *netdev = adapter->netdev;
3025 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003026 struct ixgbe_ring *rx_ring;
3027 int i;
3028 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003029
Alexander Duyck477de6e2010-08-19 13:38:11 +00003030#ifdef IXGBE_FCOE
3031 /* adjust max frame to be able to do baby jumbo for FCoE */
3032 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3033 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3034 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3035
3036#endif /* IXGBE_FCOE */
3037 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3038 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3039 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3040 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3041
3042 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003043 }
3044
Alexander Duyck919e78a2011-08-26 09:52:38 +00003045 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3046 max_frame += VLAN_HLEN;
3047
Auke Kok9a799d72007-09-15 14:07:45 -07003048 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003049 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3050 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003051 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3052
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003053 /*
3054 * Setup the HW Rx Head and Tail Descriptor Pointers and
3055 * the Base and Length of the Rx Descriptor Ring
3056 */
Auke Kok9a799d72007-09-15 14:07:45 -07003057 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003058 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003059 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3060 set_ring_rsc_enabled(rx_ring);
3061 else
3062 clear_ring_rsc_enabled(rx_ring);
Yi Zou63f39bd2009-05-17 12:34:35 +00003063#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003064 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003065 struct ixgbe_ring_feature *f;
3066 f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckf8003262012-03-03 02:35:52 +00003067 if ((i >= f->mask) && (i < f->mask + f->indices))
3068 set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state);
Yi Zou63f39bd2009-05-17 12:34:35 +00003069 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003070#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003071 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003072}
3073
Alexander Duyck73670962010-08-19 13:38:34 +00003074static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3075{
3076 struct ixgbe_hw *hw = &adapter->hw;
3077 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3078
3079 switch (hw->mac.type) {
3080 case ixgbe_mac_82598EB:
3081 /*
3082 * For VMDq support of different descriptor types or
3083 * buffer sizes through the use of multiple SRRCTL
3084 * registers, RDRXCTL.MVMEN must be set to 1
3085 *
3086 * also, the manual doesn't mention it clearly but DCA hints
3087 * will only use queue 0's tags unless this bit is set. Side
3088 * effects of setting this bit are only that SRRCTL must be
3089 * fully programmed [0..15]
3090 */
3091 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3092 break;
3093 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003094 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003095 /* Disable RSC for ACK packets */
3096 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3097 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3098 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3099 /* hardware requires some bits to be set by default */
3100 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3101 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3102 break;
3103 default:
3104 /* We should do nothing since we don't know this hardware */
3105 return;
3106 }
3107
3108 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3109}
3110
Alexander Duyck477de6e2010-08-19 13:38:11 +00003111/**
3112 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3113 * @adapter: board private structure
3114 *
3115 * Configure the Rx unit of the MAC after a reset.
3116 **/
3117static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3118{
3119 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003120 int i;
3121 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003122
3123 /* disable receives while setting up the descriptors */
3124 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3125 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3126
3127 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003128 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003129
Alexander Duyck9e10e042010-08-19 13:40:06 +00003130 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003131 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003132
Alexander Duyck9e10e042010-08-19 13:40:06 +00003133 ixgbe_set_uta(adapter);
3134
Alexander Duyck477de6e2010-08-19 13:38:11 +00003135 /* set_rx_buffer_len must be called before ring initialization */
3136 ixgbe_set_rx_buffer_len(adapter);
3137
3138 /*
3139 * Setup the HW Rx Head and Tail Descriptor Pointers and
3140 * the Base and Length of the Rx Descriptor Ring
3141 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003142 for (i = 0; i < adapter->num_rx_queues; i++)
3143 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003144
Alexander Duyck9e10e042010-08-19 13:40:06 +00003145 /* disable drop enable for 82598 parts */
3146 if (hw->mac.type == ixgbe_mac_82598EB)
3147 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3148
3149 /* enable all receives */
3150 rxctrl |= IXGBE_RXCTRL_RXEN;
3151 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003152}
3153
Jiri Pirko8e586132011-12-08 19:52:37 -05003154static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003155{
3156 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003157 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003158 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003159
3160 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003161 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003162 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003163
3164 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003165}
3166
Jiri Pirko8e586132011-12-08 19:52:37 -05003167static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003168{
3169 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003170 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003171 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003172
Auke Kok9a799d72007-09-15 14:07:45 -07003173 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003174 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003175 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003176
3177 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003178}
3179
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003180/**
3181 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3182 * @adapter: driver data
3183 */
3184static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3185{
3186 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003187 u32 vlnctrl;
3188
3189 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3190 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3191 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3192}
3193
3194/**
3195 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3196 * @adapter: driver data
3197 */
3198static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3199{
3200 struct ixgbe_hw *hw = &adapter->hw;
3201 u32 vlnctrl;
3202
3203 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3204 vlnctrl |= IXGBE_VLNCTRL_VFE;
3205 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3206 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3207}
3208
3209/**
3210 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3211 * @adapter: driver data
3212 */
3213static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3214{
3215 struct ixgbe_hw *hw = &adapter->hw;
3216 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003217 int i, j;
3218
3219 switch (hw->mac.type) {
3220 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003221 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3222 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003223 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3224 break;
3225 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003226 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003227 for (i = 0; i < adapter->num_rx_queues; i++) {
3228 j = adapter->rx_ring[i]->reg_idx;
3229 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3230 vlnctrl &= ~IXGBE_RXDCTL_VME;
3231 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3232 }
3233 break;
3234 default:
3235 break;
3236 }
3237}
3238
3239/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003240 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003241 * @adapter: driver data
3242 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003243static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003244{
3245 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003246 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003247 int i, j;
3248
3249 switch (hw->mac.type) {
3250 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003251 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3252 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003253 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3254 break;
3255 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003256 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003257 for (i = 0; i < adapter->num_rx_queues; i++) {
3258 j = adapter->rx_ring[i]->reg_idx;
3259 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3260 vlnctrl |= IXGBE_RXDCTL_VME;
3261 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3262 }
3263 break;
3264 default:
3265 break;
3266 }
3267}
3268
Auke Kok9a799d72007-09-15 14:07:45 -07003269static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3270{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003271 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003272
Jesse Grossf62bbb52010-10-20 13:56:10 +00003273 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3274
3275 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3276 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003277}
3278
3279/**
Alexander Duyck28500622010-06-15 09:25:48 +00003280 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3281 * @netdev: network interface device structure
3282 *
3283 * Writes unicast address list to the RAR table.
3284 * Returns: -ENOMEM on failure/insufficient address space
3285 * 0 on no addresses written
3286 * X on writing X addresses to the RAR table
3287 **/
3288static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3289{
3290 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3291 struct ixgbe_hw *hw = &adapter->hw;
3292 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003293 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003294 int count = 0;
3295
3296 /* return ENOMEM indicating insufficient memory for addresses */
3297 if (netdev_uc_count(netdev) > rar_entries)
3298 return -ENOMEM;
3299
3300 if (!netdev_uc_empty(netdev) && rar_entries) {
3301 struct netdev_hw_addr *ha;
3302 /* return error if we do not support writing to RAR table */
3303 if (!hw->mac.ops.set_rar)
3304 return -ENOMEM;
3305
3306 netdev_for_each_uc_addr(ha, netdev) {
3307 if (!rar_entries)
3308 break;
3309 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3310 vfn, IXGBE_RAH_AV);
3311 count++;
3312 }
3313 }
3314 /* write the addresses in reverse order to avoid write combining */
3315 for (; rar_entries > 0 ; rar_entries--)
3316 hw->mac.ops.clear_rar(hw, rar_entries);
3317
3318 return count;
3319}
3320
3321/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003322 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003323 * @netdev: network interface device structure
3324 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003325 * The set_rx_method entry point is called whenever the unicast/multicast
3326 * address list or the network interface flags are updated. This routine is
3327 * responsible for configuring the hardware for proper unicast, multicast and
3328 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003329 **/
Greg Rose7f870472010-01-09 02:25:29 +00003330void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003331{
3332 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3333 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003334 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3335 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003336
3337 /* Check for Promiscuous and All Multicast modes */
3338
3339 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3340
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003341 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003342 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003343 fctrl |= IXGBE_FCTRL_BAM;
3344 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3345 fctrl |= IXGBE_FCTRL_PMCF;
3346
Alexander Duyck28500622010-06-15 09:25:48 +00003347 /* clear the bits we are changing the status of */
3348 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3349
Auke Kok9a799d72007-09-15 14:07:45 -07003350 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003351 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003352 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003353 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003354 /* don't hardware filter vlans in promisc mode */
3355 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003356 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003357 if (netdev->flags & IFF_ALLMULTI) {
3358 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003359 vmolr |= IXGBE_VMOLR_MPE;
3360 } else {
3361 /*
3362 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003363 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003364 * that we can at least receive multicast traffic
3365 */
3366 hw->mac.ops.update_mc_addr_list(hw, netdev);
3367 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003368 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003369 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003370 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003371 /*
3372 * Write addresses to available RAR registers, if there is not
3373 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003374 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003375 */
3376 count = ixgbe_write_uc_addr_list(netdev);
3377 if (count < 0) {
3378 fctrl |= IXGBE_FCTRL_UPE;
3379 vmolr |= IXGBE_VMOLR_ROPE;
3380 }
3381 }
3382
3383 if (adapter->num_vfs) {
3384 ixgbe_restore_vf_multicasts(adapter);
3385 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3386 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3387 IXGBE_VMOLR_ROPE);
3388 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003389 }
3390
Ben Greear3f2d1c02012-03-08 08:28:41 +00003391 /* This is useful for sniffing bad packets. */
3392 if (adapter->netdev->features & NETIF_F_RXALL) {
3393 /* UPE and MPE will be handled by normal PROMISC logic
3394 * in e1000e_set_rx_mode */
3395 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3396 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3397 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3398
3399 fctrl &= ~(IXGBE_FCTRL_DPF);
3400 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3401 }
3402
Auke Kok9a799d72007-09-15 14:07:45 -07003403 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003404
3405 if (netdev->features & NETIF_F_HW_VLAN_RX)
3406 ixgbe_vlan_strip_enable(adapter);
3407 else
3408 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003409}
3410
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003411static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3412{
3413 int q_idx;
3414 struct ixgbe_q_vector *q_vector;
3415 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3416
3417 /* legacy and MSI only use one vector */
3418 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3419 q_vectors = 1;
3420
3421 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003422 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003423 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003424 }
3425}
3426
3427static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3428{
3429 int q_idx;
3430 struct ixgbe_q_vector *q_vector;
3431 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3432
3433 /* legacy and MSI only use one vector */
3434 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3435 q_vectors = 1;
3436
3437 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003438 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003439 napi_disable(&q_vector->napi);
3440 }
3441}
3442
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003443#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003444/*
3445 * ixgbe_configure_dcb - Configure DCB hardware
3446 * @adapter: ixgbe adapter struct
3447 *
3448 * This is called by the driver on open to configure the DCB hardware.
3449 * This is also called by the gennetlink interface when reconfiguring
3450 * the DCB state.
3451 */
3452static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3453{
3454 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003455 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003456
Alexander Duyck67ebd792010-08-19 13:34:04 +00003457 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3458 if (hw->mac.type == ixgbe_mac_82598EB)
3459 netif_set_gso_max_size(adapter->netdev, 65536);
3460 return;
3461 }
3462
3463 if (hw->mac.type == ixgbe_mac_82598EB)
3464 netif_set_gso_max_size(adapter->netdev, 32768);
3465
Alexander Duyck2f90b862008-11-20 20:52:10 -08003466
Alexander Duyck2f90b862008-11-20 20:52:10 -08003467 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003468 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003469
Alexander Duyck2f90b862008-11-20 20:52:10 -08003470 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003471
John Fastabendb1208182011-10-15 05:00:10 +00003472#ifdef IXGBE_FCOE
3473 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3474 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3475#endif
3476
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003477 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003478 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003479 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3480 DCB_TX_CONFIG);
3481 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3482 DCB_RX_CONFIG);
3483 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003484 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3485 ixgbe_dcb_hw_ets(&adapter->hw,
3486 adapter->ixgbe_ieee_ets,
3487 max_frame);
3488 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3489 adapter->ixgbe_ieee_pfc->pfc_en,
3490 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003491 }
John Fastabend8187cd42011-02-23 05:58:08 +00003492
3493 /* Enable RSS Hash per TC */
3494 if (hw->mac.type != ixgbe_mac_82598EB) {
3495 int i;
3496 u32 reg = 0;
3497
3498 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3499 u8 msb = 0;
3500 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3501
3502 while (cnt >>= 1)
3503 msb++;
3504
3505 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3506 }
3507 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3508 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003509}
John Fastabend9da712d2011-08-23 03:14:22 +00003510#endif
3511
3512/* Additional bittime to account for IXGBE framing */
3513#define IXGBE_ETH_FRAMING 20
3514
3515/*
3516 * ixgbe_hpbthresh - calculate high water mark for flow control
3517 *
3518 * @adapter: board private structure to calculate for
3519 * @pb - packet buffer to calculate
3520 */
3521static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3522{
3523 struct ixgbe_hw *hw = &adapter->hw;
3524 struct net_device *dev = adapter->netdev;
3525 int link, tc, kb, marker;
3526 u32 dv_id, rx_pba;
3527
3528 /* Calculate max LAN frame size */
3529 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3530
3531#ifdef IXGBE_FCOE
3532 /* FCoE traffic class uses FCOE jumbo frames */
3533 if (dev->features & NETIF_F_FCOE_MTU) {
3534 int fcoe_pb = 0;
3535
3536#ifdef CONFIG_IXGBE_DCB
3537 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003538
3539#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003540 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3541 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3542 }
3543#endif
3544
3545 /* Calculate delay value for device */
3546 switch (hw->mac.type) {
3547 case ixgbe_mac_X540:
3548 dv_id = IXGBE_DV_X540(link, tc);
3549 break;
3550 default:
3551 dv_id = IXGBE_DV(link, tc);
3552 break;
3553 }
3554
3555 /* Loopback switch introduces additional latency */
3556 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3557 dv_id += IXGBE_B2BT(tc);
3558
3559 /* Delay value is calculated in bit times convert to KB */
3560 kb = IXGBE_BT2KB(dv_id);
3561 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3562
3563 marker = rx_pba - kb;
3564
3565 /* It is possible that the packet buffer is not large enough
3566 * to provide required headroom. In this case throw an error
3567 * to user and a do the best we can.
3568 */
3569 if (marker < 0) {
3570 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3571 "headroom to support flow control."
3572 "Decrease MTU or number of traffic classes\n", pb);
3573 marker = tc + 1;
3574 }
3575
3576 return marker;
3577}
3578
3579/*
3580 * ixgbe_lpbthresh - calculate low water mark for for flow control
3581 *
3582 * @adapter: board private structure to calculate for
3583 * @pb - packet buffer to calculate
3584 */
3585static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3586{
3587 struct ixgbe_hw *hw = &adapter->hw;
3588 struct net_device *dev = adapter->netdev;
3589 int tc;
3590 u32 dv_id;
3591
3592 /* Calculate max LAN frame size */
3593 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3594
3595 /* Calculate delay value for device */
3596 switch (hw->mac.type) {
3597 case ixgbe_mac_X540:
3598 dv_id = IXGBE_LOW_DV_X540(tc);
3599 break;
3600 default:
3601 dv_id = IXGBE_LOW_DV(tc);
3602 break;
3603 }
3604
3605 /* Delay value is calculated in bit times convert to KB */
3606 return IXGBE_BT2KB(dv_id);
3607}
3608
3609/*
3610 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3611 */
3612static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3613{
3614 struct ixgbe_hw *hw = &adapter->hw;
3615 int num_tc = netdev_get_num_tc(adapter->netdev);
3616 int i;
3617
3618 if (!num_tc)
3619 num_tc = 1;
3620
3621 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3622
3623 for (i = 0; i < num_tc; i++) {
3624 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3625
3626 /* Low water marks must not be larger than high water marks */
3627 if (hw->fc.low_water > hw->fc.high_water[i])
3628 hw->fc.low_water = 0;
3629 }
3630}
John Fastabend80605c652011-05-02 12:34:10 +00003631
3632static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3633{
John Fastabend80605c652011-05-02 12:34:10 +00003634 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003635 int hdrm;
3636 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003637
3638 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3639 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003640 hdrm = 32 << adapter->fdir_pballoc;
3641 else
3642 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003643
Alexander Duyckf7e10272011-07-21 00:40:35 +00003644 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003645 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003646}
3647
Alexander Duycke4911d52011-05-11 07:18:52 +00003648static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3649{
3650 struct ixgbe_hw *hw = &adapter->hw;
3651 struct hlist_node *node, *node2;
3652 struct ixgbe_fdir_filter *filter;
3653
3654 spin_lock(&adapter->fdir_perfect_lock);
3655
3656 if (!hlist_empty(&adapter->fdir_filter_list))
3657 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3658
3659 hlist_for_each_entry_safe(filter, node, node2,
3660 &adapter->fdir_filter_list, fdir_node) {
3661 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003662 &filter->filter,
3663 filter->sw_idx,
3664 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3665 IXGBE_FDIR_DROP_QUEUE :
3666 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003667 }
3668
3669 spin_unlock(&adapter->fdir_perfect_lock);
3670}
3671
Auke Kok9a799d72007-09-15 14:07:45 -07003672static void ixgbe_configure(struct ixgbe_adapter *adapter)
3673{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003674 struct ixgbe_hw *hw = &adapter->hw;
3675
John Fastabend80605c652011-05-02 12:34:10 +00003676 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003677#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003678 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003679#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003680
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003681 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003682 ixgbe_restore_vlan(adapter);
3683
Yi Zoueacd73f2009-05-13 13:11:06 +00003684#ifdef IXGBE_FCOE
3685 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3686 ixgbe_configure_fcoe(adapter);
3687
3688#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003689
3690 switch (hw->mac.type) {
3691 case ixgbe_mac_82599EB:
3692 case ixgbe_mac_X540:
3693 hw->mac.ops.disable_rx_buff(hw);
3694 break;
3695 default:
3696 break;
3697 }
3698
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003699 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003700 ixgbe_init_fdir_signature_82599(&adapter->hw,
3701 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003702 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3703 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3704 adapter->fdir_pballoc);
3705 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003706 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003707
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003708 switch (hw->mac.type) {
3709 case ixgbe_mac_82599EB:
3710 case ixgbe_mac_X540:
3711 hw->mac.ops.enable_rx_buff(hw);
3712 break;
3713 default:
3714 break;
3715 }
3716
Alexander Duyck933d41f2010-09-07 21:34:29 +00003717 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003718
Auke Kok9a799d72007-09-15 14:07:45 -07003719 ixgbe_configure_tx(adapter);
3720 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003721}
3722
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003723static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3724{
3725 switch (hw->phy.type) {
3726 case ixgbe_phy_sfp_avago:
3727 case ixgbe_phy_sfp_ftl:
3728 case ixgbe_phy_sfp_intel:
3729 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003730 case ixgbe_phy_sfp_passive_tyco:
3731 case ixgbe_phy_sfp_passive_unknown:
3732 case ixgbe_phy_sfp_active_unknown:
3733 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003734 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003735 case ixgbe_phy_nl:
3736 if (hw->mac.type == ixgbe_mac_82598EB)
3737 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003738 default:
3739 return false;
3740 }
3741}
3742
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003743/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003744 * ixgbe_sfp_link_config - set up SFP+ link
3745 * @adapter: pointer to private adapter struct
3746 **/
3747static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3748{
Alexander Duyck70864002011-04-27 09:13:56 +00003749 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003750 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003751 * is that an SFP was inserted/removed after the reset
3752 * but before SFP detection was enabled. As such the best
3753 * solution is to just start searching as soon as we start
3754 */
3755 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3756 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003757
Alexander Duyck70864002011-04-27 09:13:56 +00003758 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003759}
3760
3761/**
3762 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003763 * @hw: pointer to private hardware struct
3764 *
3765 * Returns 0 on success, negative on failure
3766 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003767static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003768{
3769 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003770 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003771 u32 ret = IXGBE_ERR_LINK_SETUP;
3772
3773 if (hw->mac.ops.check_link)
3774 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3775
3776 if (ret)
3777 goto link_cfg_out;
3778
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003779 autoneg = hw->phy.autoneg_advertised;
3780 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003781 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3782 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003783 if (ret)
3784 goto link_cfg_out;
3785
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003786 if (hw->mac.ops.setup_link)
3787 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003788link_cfg_out:
3789 return ret;
3790}
3791
Alexander Duycka34bcff2010-08-19 13:39:20 +00003792static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003793{
Auke Kok9a799d72007-09-15 14:07:45 -07003794 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003795 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003796
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003797 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003798 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3799 IXGBE_GPIE_OCD;
3800 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003801 /*
3802 * use EIAM to auto-mask when MSI-X interrupt is asserted
3803 * this saves a register write for every interrupt
3804 */
3805 switch (hw->mac.type) {
3806 case ixgbe_mac_82598EB:
3807 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3808 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003809 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003810 case ixgbe_mac_X540:
3811 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003812 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3813 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3814 break;
3815 }
3816 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003817 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3818 * specifically only auto mask tx and rx interrupts */
3819 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003820 }
3821
Alexander Duycka34bcff2010-08-19 13:39:20 +00003822 /* XXX: to interrupt immediately for EICS writes, enable this */
3823 /* gpie |= IXGBE_GPIE_EIMEN; */
3824
3825 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3826 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3827 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003828 }
3829
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003830 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003831 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3832 switch (adapter->hw.mac.type) {
3833 case ixgbe_mac_82599EB:
3834 gpie |= IXGBE_SDP0_GPIEN;
3835 break;
3836 case ixgbe_mac_X540:
3837 gpie |= IXGBE_EIMS_TS;
3838 break;
3839 default:
3840 break;
3841 }
3842 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003843
Alexander Duycka34bcff2010-08-19 13:39:20 +00003844 /* Enable fan failure interrupt */
3845 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003846 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003847
Don Skidmore2698b202011-04-13 07:01:52 +00003848 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003849 gpie |= IXGBE_SDP1_GPIEN;
3850 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003851 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003852
3853 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3854}
3855
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003856static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003857{
3858 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003859 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003860 u32 ctrl_ext;
3861
3862 ixgbe_get_hw_control(adapter);
3863 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003864
Auke Kok9a799d72007-09-15 14:07:45 -07003865 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3866 ixgbe_configure_msix(adapter);
3867 else
3868 ixgbe_configure_msi_and_legacy(adapter);
3869
Don Skidmorec6ecf392010-12-03 03:31:51 +00003870 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3871 if (hw->mac.ops.enable_tx_laser &&
3872 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003873 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003874 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003875 hw->mac.ops.enable_tx_laser(hw);
3876
Auke Kok9a799d72007-09-15 14:07:45 -07003877 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003878 ixgbe_napi_enable_all(adapter);
3879
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003880 if (ixgbe_is_sfp(hw)) {
3881 ixgbe_sfp_link_config(adapter);
3882 } else {
3883 err = ixgbe_non_sfp_link_config(hw);
3884 if (err)
3885 e_err(probe, "link_config FAILED %d\n", err);
3886 }
3887
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003888 /* clear any pending interrupts, may auto mask */
3889 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003890 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003891
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003892 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003893 * If this adapter has a fan, check to see if we had a failure
3894 * before we enabled the interrupt.
3895 */
3896 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3897 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3898 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003899 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003900 }
3901
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003902 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003903 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003904
Auke Kok9a799d72007-09-15 14:07:45 -07003905 /* bring the link up in the watchdog, this could race with our first
3906 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003907 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3908 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003909 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003910
3911 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3912 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3913 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3914 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003915}
3916
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003917void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3918{
3919 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003920 /* put off any impending NetWatchDogTimeout */
3921 adapter->netdev->trans_start = jiffies;
3922
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003923 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003924 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003925 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003926 /*
3927 * If SR-IOV enabled then wait a bit before bringing the adapter
3928 * back up to give the VFs time to respond to the reset. The
3929 * two second wait is based upon the watchdog timer cycle in
3930 * the VF driver.
3931 */
3932 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3933 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003934 ixgbe_up(adapter);
3935 clear_bit(__IXGBE_RESETTING, &adapter->state);
3936}
3937
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003938void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003939{
3940 /* hardware has been reset, we need to reload some things */
3941 ixgbe_configure(adapter);
3942
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003943 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003944}
3945
3946void ixgbe_reset(struct ixgbe_adapter *adapter)
3947{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003948 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003949 int err;
3950
Alexander Duyck70864002011-04-27 09:13:56 +00003951 /* lock SFP init bit to prevent race conditions with the watchdog */
3952 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3953 usleep_range(1000, 2000);
3954
3955 /* clear all SFP and link config related flags while holding SFP_INIT */
3956 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3957 IXGBE_FLAG2_SFP_NEEDS_RESET);
3958 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3959
Don Skidmore8ca783a2009-05-26 20:40:47 -07003960 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003961 switch (err) {
3962 case 0:
3963 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003964 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003965 break;
3966 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003967 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003968 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003969 case IXGBE_ERR_EEPROM_VERSION:
3970 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003971 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003972 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00003973 "your hardware. If you are experiencing problems "
3974 "please contact your Intel or hardware "
3975 "representative who provided you with this "
3976 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003977 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003978 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003979 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003980 }
Auke Kok9a799d72007-09-15 14:07:45 -07003981
Alexander Duyck70864002011-04-27 09:13:56 +00003982 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3983
Auke Kok9a799d72007-09-15 14:07:45 -07003984 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003985 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3986 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003987}
3988
Auke Kok9a799d72007-09-15 14:07:45 -07003989/**
Alexander Duyckf8003262012-03-03 02:35:52 +00003990 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
3991 * @rx_ring: ring to setup
3992 *
3993 * On many IA platforms the L1 cache has a critical stride of 4K, this
3994 * results in each receive buffer starting in the same cache set. To help
3995 * reduce the pressure on this cache set we can interleave the offsets so
3996 * that only every other buffer will be in the same cache set.
3997 **/
3998static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
3999{
4000 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4001 u16 i;
4002
4003 for (i = 0; i < rx_ring->count; i += 2) {
4004 rx_buffer[0].page_offset = 0;
4005 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4006 rx_buffer = &rx_buffer[2];
4007 }
4008}
4009
4010/**
Auke Kok9a799d72007-09-15 14:07:45 -07004011 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004012 * @rx_ring: ring to free buffers from
4013 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004014static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004015{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004016 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004017 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004018 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004019
Alexander Duyck84418e32010-08-19 13:40:54 +00004020 /* ring already cleared, nothing to do */
4021 if (!rx_ring->rx_buffer_info)
4022 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004023
Alexander Duyck84418e32010-08-19 13:40:54 +00004024 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004025 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004026 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004027
Alexander Duyckf8003262012-03-03 02:35:52 +00004028 rx_buffer = &rx_ring->rx_buffer_info[i];
4029 if (rx_buffer->skb) {
4030 struct sk_buff *skb = rx_buffer->skb;
4031 if (IXGBE_CB(skb)->page_released) {
4032 dma_unmap_page(dev,
4033 IXGBE_CB(skb)->dma,
4034 ixgbe_rx_bufsz(rx_ring),
4035 DMA_FROM_DEVICE);
4036 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004037 }
4038 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004039 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004040 rx_buffer->skb = NULL;
4041 if (rx_buffer->dma)
4042 dma_unmap_page(dev, rx_buffer->dma,
4043 ixgbe_rx_pg_size(rx_ring),
4044 DMA_FROM_DEVICE);
4045 rx_buffer->dma = 0;
4046 if (rx_buffer->page)
4047 put_page(rx_buffer->page);
4048 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004049 }
4050
4051 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4052 memset(rx_ring->rx_buffer_info, 0, size);
4053
Alexander Duyckf8003262012-03-03 02:35:52 +00004054 ixgbe_init_rx_page_offset(rx_ring);
4055
Auke Kok9a799d72007-09-15 14:07:45 -07004056 /* Zero out the descriptor ring */
4057 memset(rx_ring->desc, 0, rx_ring->size);
4058
Alexander Duyckf8003262012-03-03 02:35:52 +00004059 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004060 rx_ring->next_to_clean = 0;
4061 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004062}
4063
4064/**
4065 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004066 * @tx_ring: ring to be cleaned
4067 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004068static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004069{
4070 struct ixgbe_tx_buffer *tx_buffer_info;
4071 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004072 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004073
Alexander Duyck84418e32010-08-19 13:40:54 +00004074 /* ring already cleared, nothing to do */
4075 if (!tx_ring->tx_buffer_info)
4076 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004077
Alexander Duyck84418e32010-08-19 13:40:54 +00004078 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004079 for (i = 0; i < tx_ring->count; i++) {
4080 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004081 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004082 }
4083
4084 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4085 memset(tx_ring->tx_buffer_info, 0, size);
4086
4087 /* Zero out the descriptor ring */
4088 memset(tx_ring->desc, 0, tx_ring->size);
4089
4090 tx_ring->next_to_use = 0;
4091 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004092}
4093
4094/**
Auke Kok9a799d72007-09-15 14:07:45 -07004095 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4096 * @adapter: board private structure
4097 **/
4098static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4099{
4100 int i;
4101
4102 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004103 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004104}
4105
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004106/**
4107 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4108 * @adapter: board private structure
4109 **/
4110static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4111{
4112 int i;
4113
4114 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004115 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004116}
4117
Alexander Duycke4911d52011-05-11 07:18:52 +00004118static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4119{
4120 struct hlist_node *node, *node2;
4121 struct ixgbe_fdir_filter *filter;
4122
4123 spin_lock(&adapter->fdir_perfect_lock);
4124
4125 hlist_for_each_entry_safe(filter, node, node2,
4126 &adapter->fdir_filter_list, fdir_node) {
4127 hlist_del(&filter->fdir_node);
4128 kfree(filter);
4129 }
4130 adapter->fdir_filter_count = 0;
4131
4132 spin_unlock(&adapter->fdir_perfect_lock);
4133}
4134
Auke Kok9a799d72007-09-15 14:07:45 -07004135void ixgbe_down(struct ixgbe_adapter *adapter)
4136{
4137 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004138 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004139 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004140 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004141
4142 /* signal that we are down to the interrupt handler */
4143 set_bit(__IXGBE_DOWN, &adapter->state);
4144
4145 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004146 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4147 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004148
Yi Zou2d39d572011-01-06 14:29:56 +00004149 /* disable all enabled rx queues */
4150 for (i = 0; i < adapter->num_rx_queues; i++)
4151 /* this call also flushes the previous write */
4152 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4153
Don Skidmore032b4322011-03-18 09:32:53 +00004154 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004155
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004156 netif_tx_stop_all_queues(netdev);
4157
Alexander Duyck70864002011-04-27 09:13:56 +00004158 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004159 netif_carrier_off(netdev);
4160 netif_tx_disable(netdev);
4161
4162 ixgbe_irq_disable(adapter);
4163
4164 ixgbe_napi_disable_all(adapter);
4165
Alexander Duyckd034acf2011-04-27 09:25:34 +00004166 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4167 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004168 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4169
4170 del_timer_sync(&adapter->service_timer);
4171
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004172 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004173 /* Clear EITR Select mapping */
4174 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4175
4176 /* Mark all the VFs as inactive */
4177 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004178 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004179
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004180 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004181 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004182
Auke Kok9a799d72007-09-15 14:07:45 -07004183 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004184 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004185 }
4186
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004187 /* disable transmits in the hardware now that interrupts are off */
4188 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004189 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004190 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004191 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004192
4193 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004194 switch (hw->mac.type) {
4195 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004196 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004197 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004198 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4199 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004200 break;
4201 default:
4202 break;
4203 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004204
Paul Larson6f4a0e42008-06-24 17:00:56 -07004205 if (!pci_channel_offline(adapter->pdev))
4206 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004207
4208 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4209 if (hw->mac.ops.disable_tx_laser &&
4210 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004211 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004212 (hw->mac.type == ixgbe_mac_82599EB))))
4213 hw->mac.ops.disable_tx_laser(hw);
4214
Auke Kok9a799d72007-09-15 14:07:45 -07004215 ixgbe_clean_all_tx_rings(adapter);
4216 ixgbe_clean_all_rx_rings(adapter);
4217
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004218#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004219 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004220 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004221#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004222}
4223
Auke Kok9a799d72007-09-15 14:07:45 -07004224/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004225 * ixgbe_poll - NAPI Rx polling callback
4226 * @napi: structure for representing this polling device
4227 * @budget: how many packets driver is allowed to clean
4228 *
4229 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004230 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004231static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004232{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004233 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004234 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004235 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004236 struct ixgbe_ring *ring;
4237 int per_ring_budget;
4238 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004239
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004240#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004241 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4242 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004243#endif
4244
Alexander Duycka5579282012-02-08 07:50:04 +00004245 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004246 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004247
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004248 /* attempt to distribute budget to each queue fairly, but don't allow
4249 * the budget to go below 1 because we'll exit polling */
4250 if (q_vector->rx.count > 1)
4251 per_ring_budget = max(budget/q_vector->rx.count, 1);
4252 else
4253 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004254
Alexander Duycka5579282012-02-08 07:50:04 +00004255 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004256 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4257 per_ring_budget);
4258
4259 /* If all work not completed, return budget and keep polling */
4260 if (!clean_complete)
4261 return budget;
4262
4263 /* all work done, exit the polling mode */
4264 napi_complete(napi);
4265 if (adapter->rx_itr_setting & 1)
4266 ixgbe_set_itr(q_vector);
4267 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4268 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4269
4270 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004271}
4272
4273/**
4274 * ixgbe_tx_timeout - Respond to a Tx Hang
4275 * @netdev: network interface device structure
4276 **/
4277static void ixgbe_tx_timeout(struct net_device *netdev)
4278{
4279 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4280
4281 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004282 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004283}
4284
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004285/**
4286 * ixgbe_set_rss_queues: Allocate queues for RSS
4287 * @adapter: board private structure to initialize
4288 *
4289 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4290 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4291 *
4292 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004293static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4294{
4295 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004296 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004297
4298 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004299 f->mask = 0xF;
4300 adapter->num_rx_queues = f->indices;
4301 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004302 ret = true;
4303 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004304 ret = false;
4305 }
4306
4307 return ret;
4308}
4309
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004310/**
4311 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4312 * @adapter: board private structure to initialize
4313 *
4314 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4315 * to the original CPU that initiated the Tx session. This runs in addition
4316 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4317 * Rx load across CPUs using RSS.
4318 *
4319 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004320static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004321{
4322 bool ret = false;
4323 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4324
4325 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4326 f_fdir->mask = 0;
4327
Alexander Duyck24ddd962012-02-10 02:08:32 +00004328 /*
4329 * Use RSS in addition to Flow Director to ensure the best
4330 * distribution of flows across cores, even when an FDIR flow
4331 * isn't matched.
4332 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004333 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4334 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004335 adapter->num_tx_queues = f_fdir->indices;
4336 adapter->num_rx_queues = f_fdir->indices;
4337 ret = true;
4338 } else {
4339 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004340 }
4341 return ret;
4342}
4343
Yi Zou0331a832009-05-17 12:33:52 +00004344#ifdef IXGBE_FCOE
4345/**
4346 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4347 * @adapter: board private structure to initialize
4348 *
4349 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4350 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4351 * rx queues out of the max number of rx queues, instead, it is used as the
4352 * index of the first rx queue used by FCoE.
4353 *
4354 **/
4355static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4356{
Yi Zou0331a832009-05-17 12:33:52 +00004357 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4358
John Fastabende5b64632011-03-08 03:44:52 +00004359 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4360 return false;
4361
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004362 f->indices = min_t(int, num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004363
John Fastabende901acd2011-04-26 07:26:08 +00004364 adapter->num_rx_queues = 1;
4365 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004366
John Fastabende901acd2011-04-26 07:26:08 +00004367 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4368 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004369 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004370 ixgbe_set_fdir_queues(adapter);
4371 else
4372 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004373 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004374
John Fastabende901acd2011-04-26 07:26:08 +00004375 /* adding FCoE rx rings to the end */
4376 f->mask = adapter->num_rx_queues;
4377 adapter->num_rx_queues += f->indices;
4378 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004379
John Fastabende5b64632011-03-08 03:44:52 +00004380 return true;
4381}
4382#endif /* IXGBE_FCOE */
4383
John Fastabende901acd2011-04-26 07:26:08 +00004384/* Artificial max queue cap per traffic class in DCB mode */
4385#define DCB_QUEUE_CAP 8
4386
John Fastabende5b64632011-03-08 03:44:52 +00004387#ifdef CONFIG_IXGBE_DCB
4388static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4389{
John Fastabende901acd2011-04-26 07:26:08 +00004390 int per_tc_q, q, i, offset = 0;
4391 struct net_device *dev = adapter->netdev;
4392 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004393
John Fastabende901acd2011-04-26 07:26:08 +00004394 if (!tcs)
4395 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004396
John Fastabende901acd2011-04-26 07:26:08 +00004397 /* Map queue offset and counts onto allocated tx queues */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004398 per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP);
4399 q = min_t(int, num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004400
John Fastabend8b1c0b22011-05-03 02:26:48 +00004401 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004402 netdev_set_tc_queue(dev, i, q, offset);
4403 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004404 }
4405
John Fastabende901acd2011-04-26 07:26:08 +00004406 adapter->num_tx_queues = q * tcs;
4407 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004408
4409#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004410 /* FCoE enabled queues require special configuration indexed
4411 * by feature specific indices and mask. Here we map FCoE
4412 * indices onto the DCB queue pairs allowing FCoE to own
4413 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004414 */
John Fastabende901acd2011-04-26 07:26:08 +00004415 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
John Fastabendcdf485b2012-02-11 06:26:00 +00004416 u8 prio_tc[MAX_USER_PRIORITY] = {0};
John Fastabende901acd2011-04-26 07:26:08 +00004417 int tc;
4418 struct ixgbe_ring_feature *f =
4419 &adapter->ring_feature[RING_F_FCOE];
4420
John Fastabendcdf485b2012-02-11 06:26:00 +00004421 ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc);
4422 tc = prio_tc[adapter->fcoe.up];
John Fastabende901acd2011-04-26 07:26:08 +00004423 f->indices = dev->tc_to_txq[tc].count;
4424 f->mask = dev->tc_to_txq[tc].offset;
4425 }
John Fastabende5b64632011-03-08 03:44:52 +00004426#endif
4427
John Fastabende901acd2011-04-26 07:26:08 +00004428 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004429}
John Fastabende5b64632011-03-08 03:44:52 +00004430#endif
Yi Zou0331a832009-05-17 12:33:52 +00004431
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004432/**
4433 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4434 * @adapter: board private structure to initialize
4435 *
4436 * IOV doesn't actually use anything, so just NAK the
4437 * request for now and let the other queue routines
4438 * figure out what to do.
4439 */
4440static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4441{
4442 return false;
4443}
4444
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004445/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004446 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004447 * @adapter: board private structure to initialize
4448 *
4449 * This is the top level queue allocation routine. The order here is very
4450 * important, starting with the "most" number of features turned on at once,
4451 * and ending with the smallest set of features. This way large combinations
4452 * can be allocated if they're turned on, and smaller combinations are the
4453 * fallthrough conditions.
4454 *
4455 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004456static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004457{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004458 /* Start with base case */
4459 adapter->num_rx_queues = 1;
4460 adapter->num_tx_queues = 1;
4461 adapter->num_rx_pools = adapter->num_rx_queues;
4462 adapter->num_rx_queues_per_pool = 1;
4463
4464 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004465 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004466
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004467#ifdef CONFIG_IXGBE_DCB
4468 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004469 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004470
4471#endif
John Fastabende5b64632011-03-08 03:44:52 +00004472#ifdef IXGBE_FCOE
4473 if (ixgbe_set_fcoe_queues(adapter))
4474 goto done;
4475
4476#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004477 if (ixgbe_set_fdir_queues(adapter))
4478 goto done;
4479
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004480 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004481 goto done;
4482
4483 /* fallback to base case */
4484 adapter->num_rx_queues = 1;
4485 adapter->num_tx_queues = 1;
4486
4487done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004488 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4489 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4490 return 0;
4491
Ben Hutchings847f53f2010-09-27 08:28:56 +00004492 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004493 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004494 return netif_set_real_num_rx_queues(adapter->netdev,
4495 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004496}
4497
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004498static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004499 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004500{
4501 int err, vector_threshold;
4502
Alexander Duyck8f154862012-02-10 02:08:37 +00004503 /* We'll want at least 2 (vector_threshold):
4504 * 1) TxQ[0] + RxQ[0] handler
4505 * 2) Other (Link Status Change, etc.)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004506 */
4507 vector_threshold = MIN_MSIX_COUNT;
4508
Alexander Duyck24ddd962012-02-10 02:08:32 +00004509 /*
4510 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004511 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4512 * Right now, we simply care about how many we'll get; we'll
4513 * set them up later while requesting irq's.
4514 */
4515 while (vectors >= vector_threshold) {
4516 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004517 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004518 if (!err) /* Success in acquiring all requested vectors. */
4519 break;
4520 else if (err < 0)
4521 vectors = 0; /* Nasty failure, quit now */
4522 else /* err == number of vectors we should try again with */
4523 vectors = err;
4524 }
4525
4526 if (vectors < vector_threshold) {
4527 /* Can't allocate enough MSI-X interrupts? Oh well.
4528 * This just means we'll go with either a single MSI
4529 * vector or fall back to legacy interrupts.
4530 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004531 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4532 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004533 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4534 kfree(adapter->msix_entries);
4535 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004536 } else {
4537 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004538 /*
4539 * Adjust for only the vectors we'll use, which is minimum
4540 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4541 * vectors we were allocated.
4542 */
4543 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004544 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004545 }
4546}
4547
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004548/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004549 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004550 * @adapter: board private structure to initialize
4551 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004552 * Cache the descriptor ring offsets for RSS to the assigned rings.
4553 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004554 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004555static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004556{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004557 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004558
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004559 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4560 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004561
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004562 for (i = 0; i < adapter->num_rx_queues; i++)
4563 adapter->rx_ring[i]->reg_idx = i;
4564 for (i = 0; i < adapter->num_tx_queues; i++)
4565 adapter->tx_ring[i]->reg_idx = i;
4566
4567 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004568}
4569
4570#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004571
4572/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004573static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4574 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004575{
4576 struct net_device *dev = adapter->netdev;
4577 struct ixgbe_hw *hw = &adapter->hw;
4578 u8 num_tcs = netdev_get_num_tc(dev);
4579
4580 *tx = 0;
4581 *rx = 0;
4582
4583 switch (hw->mac.type) {
4584 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004585 *tx = tc << 2;
4586 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004587 break;
4588 case ixgbe_mac_82599EB:
4589 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004590 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004591 if (tc < 3) {
4592 *tx = tc << 5;
4593 *rx = tc << 4;
4594 } else if (tc < 5) {
4595 *tx = ((tc + 2) << 4);
4596 *rx = tc << 4;
4597 } else if (tc < num_tcs) {
4598 *tx = ((tc + 8) << 3);
4599 *rx = tc << 4;
4600 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004601 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004602 *rx = tc << 5;
4603 switch (tc) {
4604 case 0:
4605 *tx = 0;
4606 break;
4607 case 1:
4608 *tx = 64;
4609 break;
4610 case 2:
4611 *tx = 96;
4612 break;
4613 case 3:
4614 *tx = 112;
4615 break;
4616 default:
4617 break;
4618 }
4619 }
4620 break;
4621 default:
4622 break;
4623 }
4624}
4625
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004626/**
4627 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4628 * @adapter: board private structure to initialize
4629 *
4630 * Cache the descriptor ring offsets for DCB to the assigned rings.
4631 *
4632 **/
4633static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4634{
John Fastabende5b64632011-03-08 03:44:52 +00004635 struct net_device *dev = adapter->netdev;
4636 int i, j, k;
4637 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004638
John Fastabend8b1c0b22011-05-03 02:26:48 +00004639 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004640 return false;
4641
John Fastabende5b64632011-03-08 03:44:52 +00004642 for (i = 0, k = 0; i < num_tcs; i++) {
4643 unsigned int tx_s, rx_s;
4644 u16 count = dev->tc_to_txq[i].count;
4645
4646 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4647 for (j = 0; j < count; j++, k++) {
4648 adapter->tx_ring[k]->reg_idx = tx_s + j;
4649 adapter->rx_ring[k]->reg_idx = rx_s + j;
4650 adapter->tx_ring[k]->dcb_tc = i;
4651 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004652 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004653 }
John Fastabende5b64632011-03-08 03:44:52 +00004654
4655 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004656}
4657#endif
4658
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004659/**
4660 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4661 * @adapter: board private structure to initialize
4662 *
4663 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4664 *
4665 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004666static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004667{
4668 int i;
4669 bool ret = false;
4670
Alexander Duyck03ecf912011-05-20 07:36:17 +00004671 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4672 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004673 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004674 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004675 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004676 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004677 ret = true;
4678 }
4679
4680 return ret;
4681}
4682
Yi Zou0331a832009-05-17 12:33:52 +00004683#ifdef IXGBE_FCOE
4684/**
4685 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4686 * @adapter: board private structure to initialize
4687 *
4688 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4689 *
4690 */
4691static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4692{
Yi Zou0331a832009-05-17 12:33:52 +00004693 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004694 int i;
4695 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004696
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004697 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4698 return false;
4699
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004700 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004701 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004702 ixgbe_cache_ring_fdir(adapter);
4703 else
4704 ixgbe_cache_ring_rss(adapter);
4705
4706 fcoe_rx_i = f->mask;
4707 fcoe_tx_i = f->mask;
4708 }
4709 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4710 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4711 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4712 }
4713 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004714}
4715
4716#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004717/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004718 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4719 * @adapter: board private structure to initialize
4720 *
4721 * SR-IOV doesn't use any descriptor rings but changes the default if
4722 * no other mapping is used.
4723 *
4724 */
4725static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4726{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004727 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4728 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004729 if (adapter->num_vfs)
4730 return true;
4731 else
4732 return false;
4733}
4734
4735/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004736 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4737 * @adapter: board private structure to initialize
4738 *
4739 * Once we know the feature-set enabled for the device, we'll cache
4740 * the register offset the descriptor ring is assigned to.
4741 *
4742 * Note, the order the various feature calls is important. It must start with
4743 * the "most" features enabled at the same time, then trickle down to the
4744 * least amount of features turned on at once.
4745 **/
4746static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4747{
4748 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004749 adapter->rx_ring[0]->reg_idx = 0;
4750 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004751
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004752 if (ixgbe_cache_ring_sriov(adapter))
4753 return;
4754
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004755#ifdef CONFIG_IXGBE_DCB
4756 if (ixgbe_cache_ring_dcb(adapter))
4757 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004758#endif
John Fastabende5b64632011-03-08 03:44:52 +00004759
4760#ifdef IXGBE_FCOE
4761 if (ixgbe_cache_ring_fcoe(adapter))
4762 return;
4763#endif /* IXGBE_FCOE */
4764
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004765 if (ixgbe_cache_ring_fdir(adapter))
4766 return;
4767
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004768 if (ixgbe_cache_ring_rss(adapter))
4769 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004770}
4771
Auke Kok9a799d72007-09-15 14:07:45 -07004772/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004773 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4774 * @adapter: board private structure to initialize
4775 *
4776 * Attempt to configure the interrupts using the best available
4777 * capabilities of the hardware and the kernel.
4778 **/
Al Virofeea6a52008-11-27 15:34:07 -08004779static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004780{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004781 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004782 int err = 0;
4783 int vector, v_budget;
4784
4785 /*
4786 * It's easy to be greedy for MSI-X vectors, but it really
4787 * doesn't do us much good if we have a lot more vectors
4788 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004789 * (roughly) the same number of vectors as there are CPU's.
Alexander Duyck8f154862012-02-10 02:08:37 +00004790 * The default is to use pairs of vectors.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004791 */
Alexander Duyck8f154862012-02-10 02:08:37 +00004792 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
4793 v_budget = min_t(int, v_budget, num_online_cpus());
4794 v_budget += NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004795
4796 /*
4797 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004798 * hw.mac->max_msix_vectors vectors. With features
4799 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4800 * descriptor queues supported by our device. Thus, we cap it off in
4801 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004802 */
Alexander Duyckde88eee2012-02-08 07:49:59 +00004803 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004804
4805 /* A failure in MSI-X entry allocation isn't fatal, but it does
4806 * mean we disable MSI-X capabilities of the adapter. */
4807 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004808 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004809 if (adapter->msix_entries) {
4810 for (vector = 0; vector < v_budget; vector++)
4811 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004812
Alexander Duyck7a921c92009-05-06 10:43:28 +00004813 ixgbe_acquire_msix_vectors(adapter, v_budget);
4814
4815 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4816 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004817 }
David S. Miller26d27842010-05-03 15:18:22 -07004818
Alexander Duyck7a921c92009-05-06 10:43:28 +00004819 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4820 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004821 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004822 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004823 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004824 "queues are disabled. Disabling Flow Director\n");
4825 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004826 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004827 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004828 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4829 ixgbe_disable_sriov(adapter);
4830
Ben Hutchings847f53f2010-09-27 08:28:56 +00004831 err = ixgbe_set_num_queues(adapter);
4832 if (err)
4833 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004834
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004835 err = pci_enable_msi(adapter->pdev);
4836 if (!err) {
4837 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4838 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004839 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4840 "Unable to allocate MSI interrupt, "
4841 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004842 /* reset err */
4843 err = 0;
4844 }
4845
4846out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004847 return err;
4848}
4849
Alexander Duyckde88eee2012-02-08 07:49:59 +00004850static void ixgbe_add_ring(struct ixgbe_ring *ring,
4851 struct ixgbe_ring_container *head)
4852{
4853 ring->next = head->ring;
4854 head->ring = ring;
4855 head->count++;
4856}
4857
4858/**
4859 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
4860 * @adapter: board private structure to initialize
4861 * @v_idx: index of vector in adapter struct
4862 *
4863 * We allocate one q_vector. If allocation fails we return -ENOMEM.
4864 **/
4865static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
4866 int txr_count, int txr_idx,
4867 int rxr_count, int rxr_idx)
4868{
4869 struct ixgbe_q_vector *q_vector;
4870 struct ixgbe_ring *ring;
4871 int node = -1;
4872 int cpu = -1;
4873 int ring_count, size;
4874
4875 ring_count = txr_count + rxr_count;
4876 size = sizeof(struct ixgbe_q_vector) +
4877 (sizeof(struct ixgbe_ring) * ring_count);
4878
4879 /* customize cpu for Flow Director mapping */
4880 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4881 if (cpu_online(v_idx)) {
4882 cpu = v_idx;
4883 node = cpu_to_node(cpu);
4884 }
4885 }
4886
4887 /* allocate q_vector and rings */
4888 q_vector = kzalloc_node(size, GFP_KERNEL, node);
4889 if (!q_vector)
4890 q_vector = kzalloc(size, GFP_KERNEL);
4891 if (!q_vector)
4892 return -ENOMEM;
4893
4894 /* setup affinity mask and node */
4895 if (cpu != -1)
4896 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
4897 else
4898 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
4899 q_vector->numa_node = node;
4900
4901 /* initialize NAPI */
4902 netif_napi_add(adapter->netdev, &q_vector->napi,
4903 ixgbe_poll, 64);
4904
4905 /* tie q_vector and adapter together */
4906 adapter->q_vector[v_idx] = q_vector;
4907 q_vector->adapter = adapter;
4908 q_vector->v_idx = v_idx;
4909
4910 /* initialize work limits */
4911 q_vector->tx.work_limit = adapter->tx_work_limit;
4912
4913 /* initialize pointer to rings */
4914 ring = q_vector->ring;
4915
4916 while (txr_count) {
4917 /* assign generic ring traits */
4918 ring->dev = &adapter->pdev->dev;
4919 ring->netdev = adapter->netdev;
4920
4921 /* configure backlink on ring */
4922 ring->q_vector = q_vector;
4923
4924 /* update q_vector Tx values */
4925 ixgbe_add_ring(ring, &q_vector->tx);
4926
4927 /* apply Tx specific ring traits */
4928 ring->count = adapter->tx_ring_count;
4929 ring->queue_index = txr_idx;
4930
4931 /* assign ring to adapter */
4932 adapter->tx_ring[txr_idx] = ring;
4933
4934 /* update count and index */
4935 txr_count--;
4936 txr_idx++;
4937
4938 /* push pointer to next ring */
4939 ring++;
4940 }
4941
4942 while (rxr_count) {
4943 /* assign generic ring traits */
4944 ring->dev = &adapter->pdev->dev;
4945 ring->netdev = adapter->netdev;
4946
4947 /* configure backlink on ring */
4948 ring->q_vector = q_vector;
4949
4950 /* update q_vector Rx values */
4951 ixgbe_add_ring(ring, &q_vector->rx);
4952
4953 /*
4954 * 82599 errata, UDP frames with a 0 checksum
4955 * can be marked as checksum errors.
4956 */
4957 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4958 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4959
4960 /* apply Rx specific ring traits */
4961 ring->count = adapter->rx_ring_count;
4962 ring->queue_index = rxr_idx;
4963
4964 /* assign ring to adapter */
4965 adapter->rx_ring[rxr_idx] = ring;
4966
4967 /* update count and index */
4968 rxr_count--;
4969 rxr_idx++;
4970
4971 /* push pointer to next ring */
4972 ring++;
4973 }
4974
4975 return 0;
4976}
4977
4978/**
4979 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
4980 * @adapter: board private structure to initialize
4981 * @v_idx: Index of vector to be freed
4982 *
4983 * This function frees the memory allocated to the q_vector. In addition if
4984 * NAPI is enabled it will delete any references to the NAPI struct prior
4985 * to freeing the q_vector.
4986 **/
4987static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
4988{
4989 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4990 struct ixgbe_ring *ring;
4991
Alexander Duycka5579282012-02-08 07:50:04 +00004992 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004993 adapter->tx_ring[ring->queue_index] = NULL;
4994
Alexander Duycka5579282012-02-08 07:50:04 +00004995 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004996 adapter->rx_ring[ring->queue_index] = NULL;
4997
4998 adapter->q_vector[v_idx] = NULL;
4999 netif_napi_del(&q_vector->napi);
5000
5001 /*
5002 * ixgbe_get_stats64() might access the rings on this vector,
5003 * we must wait a grace period before freeing it.
5004 */
5005 kfree_rcu(q_vector, rcu);
5006}
5007
Alexander Duyck7a921c92009-05-06 10:43:28 +00005008/**
5009 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
5010 * @adapter: board private structure to initialize
5011 *
5012 * We allocate one q_vector per queue interrupt. If allocation fails we
5013 * return -ENOMEM.
5014 **/
5015static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5016{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005017 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5018 int rxr_remaining = adapter->num_rx_queues;
5019 int txr_remaining = adapter->num_tx_queues;
5020 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
5021 int err;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005022
Alexander Duyckde88eee2012-02-08 07:49:59 +00005023 /* only one q_vector if MSI-X is disabled. */
5024 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
5025 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005026
Alexander Duyckde88eee2012-02-08 07:49:59 +00005027 if (q_vectors >= (rxr_remaining + txr_remaining)) {
5028 for (; rxr_remaining; v_idx++, q_vectors--) {
5029 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5030 err = ixgbe_alloc_q_vector(adapter, v_idx,
5031 0, 0, rqpv, rxr_idx);
5032
5033 if (err)
5034 goto err_out;
5035
5036 /* update counts and index */
5037 rxr_remaining -= rqpv;
5038 rxr_idx += rqpv;
5039 }
5040 }
5041
5042 for (; q_vectors; v_idx++, q_vectors--) {
5043 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5044 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors);
5045 err = ixgbe_alloc_q_vector(adapter, v_idx,
5046 tqpv, txr_idx,
5047 rqpv, rxr_idx);
5048
5049 if (err)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005050 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005051
Alexander Duyckde88eee2012-02-08 07:49:59 +00005052 /* update counts and index */
5053 rxr_remaining -= rqpv;
5054 rxr_idx += rqpv;
5055 txr_remaining -= tqpv;
5056 txr_idx += tqpv;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005057 }
5058
5059 return 0;
5060
5061err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005062 while (v_idx) {
5063 v_idx--;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005064 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005065 }
Alexander Duyckde88eee2012-02-08 07:49:59 +00005066
Alexander Duyck7a921c92009-05-06 10:43:28 +00005067 return -ENOMEM;
5068}
5069
5070/**
5071 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5072 * @adapter: board private structure to initialize
5073 *
5074 * This function frees the memory allocated to the q_vectors. In addition if
5075 * NAPI is enabled it will delete any references to the NAPI struct prior
5076 * to freeing the q_vector.
5077 **/
5078static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5079{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005080 int v_idx, q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005081
Alexander Duyck91281fd2009-06-04 16:00:27 +00005082 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005083 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005084 else
Alexander Duyckde88eee2012-02-08 07:49:59 +00005085 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005086
Alexander Duyckde88eee2012-02-08 07:49:59 +00005087 for (v_idx = 0; v_idx < q_vectors; v_idx++)
5088 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005089}
5090
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005091static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005092{
5093 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5094 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5095 pci_disable_msix(adapter->pdev);
5096 kfree(adapter->msix_entries);
5097 adapter->msix_entries = NULL;
5098 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5099 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5100 pci_disable_msi(adapter->pdev);
5101 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005102}
5103
5104/**
5105 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5106 * @adapter: board private structure to initialize
5107 *
5108 * We determine which interrupt scheme to use based on...
5109 * - Kernel support (MSI, MSI-X)
5110 * - which can be user-defined (via MODULE_PARAM)
5111 * - Hardware queue count (num_*_queues)
5112 * - defined by miscellaneous hardware support/features (RSS, etc.)
5113 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005114int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005115{
5116 int err;
5117
5118 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005119 err = ixgbe_set_num_queues(adapter);
5120 if (err)
5121 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005122
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005123 err = ixgbe_set_interrupt_capability(adapter);
5124 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005125 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005126 goto err_set_interrupt;
5127 }
5128
Alexander Duyck7a921c92009-05-06 10:43:28 +00005129 err = ixgbe_alloc_q_vectors(adapter);
5130 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005131 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005132 goto err_alloc_q_vectors;
5133 }
5134
Alexander Duyckde88eee2012-02-08 07:49:59 +00005135 ixgbe_cache_ring_register(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005136
Emil Tantilov849c4542010-06-03 16:53:41 +00005137 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005138 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5139 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005140
5141 set_bit(__IXGBE_DOWN, &adapter->state);
5142
5143 return 0;
5144
Alexander Duyck7a921c92009-05-06 10:43:28 +00005145err_alloc_q_vectors:
5146 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005147err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005148 return err;
5149}
5150
5151/**
5152 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5153 * @adapter: board private structure to clear interrupt scheme on
5154 *
5155 * We go through and clear interrupt specific resources and reset the structure
5156 * to pre-load conditions
5157 **/
5158void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5159{
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005160 adapter->num_tx_queues = 0;
5161 adapter->num_rx_queues = 0;
5162
Alexander Duyck7a921c92009-05-06 10:43:28 +00005163 ixgbe_free_q_vectors(adapter);
5164 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005165}
5166
5167/**
5168 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5169 * @adapter: board private structure to initialize
5170 *
5171 * ixgbe_sw_init initializes the Adapter private data structure.
5172 * Fields are initialized based on PCI device information and
5173 * OS network device settings (MTU size).
5174 **/
5175static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5176{
5177 struct ixgbe_hw *hw = &adapter->hw;
5178 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005179 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005180#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005181 int j;
5182 struct tc_configuration *tc;
5183#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005184
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005185 /* PCI config space info */
5186
5187 hw->vendor_id = pdev->vendor;
5188 hw->device_id = pdev->device;
5189 hw->revision_id = pdev->revision;
5190 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5191 hw->subsystem_device_id = pdev->subsystem_device;
5192
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005193 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005194 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005195 adapter->ring_feature[RING_F_RSS].indices = rss;
5196 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005197 switch (hw->mac.type) {
5198 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005199 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5200 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005201 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005202 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005203 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005204 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5205 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005206 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005207 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5208 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005209 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5210 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005211 /* Flow Director hash filters enabled */
5212 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5213 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005214 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005215 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005216 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005217#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005218 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5219 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5220 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005221#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005222 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005223 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005224#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005225#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005226 break;
5227 default:
5228 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005229 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005230
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005231 /* n-tuple support exists, always init our spinlock */
5232 spin_lock_init(&adapter->fdir_perfect_lock);
5233
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005234#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005235 switch (hw->mac.type) {
5236 case ixgbe_mac_X540:
5237 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5238 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5239 break;
5240 default:
5241 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5242 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5243 break;
5244 }
5245
Alexander Duyck2f90b862008-11-20 20:52:10 -08005246 /* Configure DCB traffic classes */
5247 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5248 tc = &adapter->dcb_cfg.tc_config[j];
5249 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5250 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5251 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5252 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5253 tc->dcb_pfc = pfc_disabled;
5254 }
John Fastabend4de2a022011-09-27 03:52:01 +00005255
5256 /* Initialize default user to priority mapping, UPx->TC0 */
5257 tc = &adapter->dcb_cfg.tc_config[0];
5258 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5259 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5260
Alexander Duyck2f90b862008-11-20 20:52:10 -08005261 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5262 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005263 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005264 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005265 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005266 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005267 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005268
5269#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005270
5271 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005272 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005273 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005274#ifdef CONFIG_DCB
5275 adapter->last_lfc_mode = hw->fc.current_mode;
5276#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005277 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005278 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5279 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005280 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005281
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005282 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005283 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005284 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005285
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005286 /* set default ring sizes */
5287 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5288 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5289
Alexander Duyckbd198052011-06-11 01:45:08 +00005290 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005291 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005292
Auke Kok9a799d72007-09-15 14:07:45 -07005293 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005294 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005295 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005296 return -EIO;
5297 }
5298
Auke Kok9a799d72007-09-15 14:07:45 -07005299 set_bit(__IXGBE_DOWN, &adapter->state);
5300
5301 return 0;
5302}
5303
5304/**
5305 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005306 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005307 *
5308 * Return 0 on success, negative on failure
5309 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005310int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005311{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005312 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005313 int orig_node = dev_to_node(dev);
5314 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005315 int size;
5316
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005317 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005318
5319 if (tx_ring->q_vector)
5320 numa_node = tx_ring->q_vector->numa_node;
5321
5322 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005323 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005324 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005325 if (!tx_ring->tx_buffer_info)
5326 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005327
5328 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005329 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005330 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005331
Alexander Duyckde88eee2012-02-08 07:49:59 +00005332 set_dev_node(dev, numa_node);
5333 tx_ring->desc = dma_alloc_coherent(dev,
5334 tx_ring->size,
5335 &tx_ring->dma,
5336 GFP_KERNEL);
5337 set_dev_node(dev, orig_node);
5338 if (!tx_ring->desc)
5339 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5340 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005341 if (!tx_ring->desc)
5342 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005343
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005344 tx_ring->next_to_use = 0;
5345 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005346 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005347
5348err:
5349 vfree(tx_ring->tx_buffer_info);
5350 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005351 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005352 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005353}
5354
5355/**
Alexander Duyck69888672008-09-11 20:05:39 -07005356 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5357 * @adapter: board private structure
5358 *
5359 * If this function returns with an error, then it's possible one or
5360 * more of the rings is populated (while the rest are not). It is the
5361 * callers duty to clean those orphaned rings.
5362 *
5363 * Return 0 on success, negative on failure
5364 **/
5365static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5366{
5367 int i, err = 0;
5368
5369 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005370 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005371 if (!err)
5372 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005373 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005374 break;
5375 }
5376
5377 return err;
5378}
5379
5380/**
Auke Kok9a799d72007-09-15 14:07:45 -07005381 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005382 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005383 *
5384 * Returns 0 on success, negative on failure
5385 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005387{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005388 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005389 int orig_node = dev_to_node(dev);
5390 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005391 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005392
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005393 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005394
5395 if (rx_ring->q_vector)
5396 numa_node = rx_ring->q_vector->numa_node;
5397
5398 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005399 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005400 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005401 if (!rx_ring->rx_buffer_info)
5402 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005403
Auke Kok9a799d72007-09-15 14:07:45 -07005404 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005405 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5406 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005407
Alexander Duyckde88eee2012-02-08 07:49:59 +00005408 set_dev_node(dev, numa_node);
5409 rx_ring->desc = dma_alloc_coherent(dev,
5410 rx_ring->size,
5411 &rx_ring->dma,
5412 GFP_KERNEL);
5413 set_dev_node(dev, orig_node);
5414 if (!rx_ring->desc)
5415 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5416 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005417 if (!rx_ring->desc)
5418 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005419
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005420 rx_ring->next_to_clean = 0;
5421 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005422
Alexander Duyckf8003262012-03-03 02:35:52 +00005423 ixgbe_init_rx_page_offset(rx_ring);
5424
Auke Kok9a799d72007-09-15 14:07:45 -07005425 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005426err:
5427 vfree(rx_ring->rx_buffer_info);
5428 rx_ring->rx_buffer_info = NULL;
5429 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005430 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005431}
5432
5433/**
Alexander Duyck69888672008-09-11 20:05:39 -07005434 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5435 * @adapter: board private structure
5436 *
5437 * If this function returns with an error, then it's possible one or
5438 * more of the rings is populated (while the rest are not). It is the
5439 * callers duty to clean those orphaned rings.
5440 *
5441 * Return 0 on success, negative on failure
5442 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005443static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5444{
5445 int i, err = 0;
5446
5447 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005448 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005449 if (!err)
5450 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005451 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005452 break;
5453 }
5454
5455 return err;
5456}
5457
5458/**
Auke Kok9a799d72007-09-15 14:07:45 -07005459 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005460 * @tx_ring: Tx descriptor ring for a specific queue
5461 *
5462 * Free all transmit software resources
5463 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005464void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005465{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005466 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005467
5468 vfree(tx_ring->tx_buffer_info);
5469 tx_ring->tx_buffer_info = NULL;
5470
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005471 /* if not set, then don't free */
5472 if (!tx_ring->desc)
5473 return;
5474
5475 dma_free_coherent(tx_ring->dev, tx_ring->size,
5476 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005477
5478 tx_ring->desc = NULL;
5479}
5480
5481/**
5482 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5483 * @adapter: board private structure
5484 *
5485 * Free all transmit software resources
5486 **/
5487static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5488{
5489 int i;
5490
5491 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005492 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005493 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005494}
5495
5496/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005497 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005498 * @rx_ring: ring to clean the resources from
5499 *
5500 * Free all receive software resources
5501 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005502void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005503{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005504 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005505
5506 vfree(rx_ring->rx_buffer_info);
5507 rx_ring->rx_buffer_info = NULL;
5508
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005509 /* if not set, then don't free */
5510 if (!rx_ring->desc)
5511 return;
5512
5513 dma_free_coherent(rx_ring->dev, rx_ring->size,
5514 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005515
5516 rx_ring->desc = NULL;
5517}
5518
5519/**
5520 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5521 * @adapter: board private structure
5522 *
5523 * Free all receive software resources
5524 **/
5525static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5526{
5527 int i;
5528
5529 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005530 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005531 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005532}
5533
5534/**
Auke Kok9a799d72007-09-15 14:07:45 -07005535 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5536 * @netdev: network interface device structure
5537 * @new_mtu: new value for maximum frame size
5538 *
5539 * Returns 0 on success, negative on failure
5540 **/
5541static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5542{
5543 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5544 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5545
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005546 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005547 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5548 return -EINVAL;
5549
5550 /*
5551 * For 82599EB we cannot allow PF to change MTU greater than 1500
5552 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
5553 * don't allocate and chain buffers correctly.
5554 */
5555 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5556 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
5557 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00005558 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07005559
Emil Tantilov396e7992010-07-01 20:05:12 +00005560 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005561
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005562 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005563 netdev->mtu = new_mtu;
5564
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005565 if (netif_running(netdev))
5566 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005567
5568 return 0;
5569}
5570
5571/**
5572 * ixgbe_open - Called when a network interface is made active
5573 * @netdev: network interface device structure
5574 *
5575 * Returns 0 on success, negative value on failure
5576 *
5577 * The open entry point is called when a network interface is made
5578 * active by the system (IFF_UP). At this point all resources needed
5579 * for transmit and receive operations are allocated, the interrupt
5580 * handler is registered with the OS, the watchdog timer is started,
5581 * and the stack is notified that the interface is ready.
5582 **/
5583static int ixgbe_open(struct net_device *netdev)
5584{
5585 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5586 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005587
Auke Kok4bebfaa2008-02-11 09:26:01 -08005588 /* disallow open during test */
5589 if (test_bit(__IXGBE_TESTING, &adapter->state))
5590 return -EBUSY;
5591
Jesse Brandeburg54386462009-04-17 20:44:27 +00005592 netif_carrier_off(netdev);
5593
Auke Kok9a799d72007-09-15 14:07:45 -07005594 /* allocate transmit descriptors */
5595 err = ixgbe_setup_all_tx_resources(adapter);
5596 if (err)
5597 goto err_setup_tx;
5598
Auke Kok9a799d72007-09-15 14:07:45 -07005599 /* allocate receive descriptors */
5600 err = ixgbe_setup_all_rx_resources(adapter);
5601 if (err)
5602 goto err_setup_rx;
5603
5604 ixgbe_configure(adapter);
5605
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005606 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005607 if (err)
5608 goto err_req_irq;
5609
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005610 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005611
5612 return 0;
5613
Auke Kok9a799d72007-09-15 14:07:45 -07005614err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005615err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005616 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005617err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005618 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005619 ixgbe_reset(adapter);
5620
5621 return err;
5622}
5623
5624/**
5625 * ixgbe_close - Disables a network interface
5626 * @netdev: network interface device structure
5627 *
5628 * Returns 0, this is not allowed to fail
5629 *
5630 * The close entry point is called when an interface is de-activated
5631 * by the OS. The hardware is still under the drivers control, but
5632 * needs to be disabled. A global MAC reset is issued to stop the
5633 * hardware, and all transmit and receive resources are freed.
5634 **/
5635static int ixgbe_close(struct net_device *netdev)
5636{
5637 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005638
5639 ixgbe_down(adapter);
5640 ixgbe_free_irq(adapter);
5641
Alexander Duycke4911d52011-05-11 07:18:52 +00005642 ixgbe_fdir_filter_exit(adapter);
5643
Auke Kok9a799d72007-09-15 14:07:45 -07005644 ixgbe_free_all_tx_resources(adapter);
5645 ixgbe_free_all_rx_resources(adapter);
5646
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005647 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005648
5649 return 0;
5650}
5651
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005652#ifdef CONFIG_PM
5653static int ixgbe_resume(struct pci_dev *pdev)
5654{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005655 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5656 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005657 u32 err;
5658
5659 pci_set_power_state(pdev, PCI_D0);
5660 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005661 /*
5662 * pci_restore_state clears dev->state_saved so call
5663 * pci_save_state to restore it.
5664 */
5665 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005666
5667 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005668 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005669 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005670 return err;
5671 }
5672 pci_set_master(pdev);
5673
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005674 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005675
5676 err = ixgbe_init_interrupt_scheme(adapter);
5677 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005678 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005679 return err;
5680 }
5681
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005682 ixgbe_reset(adapter);
5683
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005684 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5685
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005686 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005687 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005688 if (err)
5689 return err;
5690 }
5691
5692 netif_device_attach(netdev);
5693
5694 return 0;
5695}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005696#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005697
5698static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005699{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005700 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5701 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005702 struct ixgbe_hw *hw = &adapter->hw;
5703 u32 ctrl, fctrl;
5704 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005705#ifdef CONFIG_PM
5706 int retval = 0;
5707#endif
5708
5709 netif_device_detach(netdev);
5710
5711 if (netif_running(netdev)) {
5712 ixgbe_down(adapter);
5713 ixgbe_free_irq(adapter);
5714 ixgbe_free_all_tx_resources(adapter);
5715 ixgbe_free_all_rx_resources(adapter);
5716 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005717
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005718 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005719#ifdef CONFIG_DCB
5720 kfree(adapter->ixgbe_ieee_pfc);
5721 kfree(adapter->ixgbe_ieee_ets);
5722#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005723
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005724#ifdef CONFIG_PM
5725 retval = pci_save_state(pdev);
5726 if (retval)
5727 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005728
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005729#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005730 if (wufc) {
5731 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005732
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005733 /* turn on all-multi mode if wake on multicast is enabled */
5734 if (wufc & IXGBE_WUFC_MC) {
5735 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5736 fctrl |= IXGBE_FCTRL_MPE;
5737 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5738 }
5739
5740 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5741 ctrl |= IXGBE_CTRL_GIO_DIS;
5742 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5743
5744 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5745 } else {
5746 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5747 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5748 }
5749
Alexander Duyckbd508172010-11-16 19:27:03 -08005750 switch (hw->mac.type) {
5751 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005752 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005753 break;
5754 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005755 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005756 pci_wake_from_d3(pdev, !!wufc);
5757 break;
5758 default:
5759 break;
5760 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005761
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005762 *enable_wake = !!wufc;
5763
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005764 ixgbe_release_hw_control(adapter);
5765
5766 pci_disable_device(pdev);
5767
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005768 return 0;
5769}
5770
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005771#ifdef CONFIG_PM
5772static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5773{
5774 int retval;
5775 bool wake;
5776
5777 retval = __ixgbe_shutdown(pdev, &wake);
5778 if (retval)
5779 return retval;
5780
5781 if (wake) {
5782 pci_prepare_to_sleep(pdev);
5783 } else {
5784 pci_wake_from_d3(pdev, false);
5785 pci_set_power_state(pdev, PCI_D3hot);
5786 }
5787
5788 return 0;
5789}
5790#endif /* CONFIG_PM */
5791
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005792static void ixgbe_shutdown(struct pci_dev *pdev)
5793{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005794 bool wake;
5795
5796 __ixgbe_shutdown(pdev, &wake);
5797
5798 if (system_state == SYSTEM_POWER_OFF) {
5799 pci_wake_from_d3(pdev, wake);
5800 pci_set_power_state(pdev, PCI_D3hot);
5801 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005802}
5803
5804/**
Auke Kok9a799d72007-09-15 14:07:45 -07005805 * ixgbe_update_stats - Update the board statistics counters.
5806 * @adapter: board private structure
5807 **/
5808void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5809{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005810 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005811 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005812 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005813 u64 total_mpc = 0;
5814 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005815 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5816 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005817 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005818#ifdef IXGBE_FCOE
5819 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5820 unsigned int cpu;
5821 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5822#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005823
Don Skidmored08935c2010-06-11 13:20:29 +00005824 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5825 test_bit(__IXGBE_RESETTING, &adapter->state))
5826 return;
5827
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005828 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005829 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005830 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005831 for (i = 0; i < 16; i++)
5832 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005833 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005834 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005835 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5836 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005837 }
5838 adapter->rsc_total_count = rsc_count;
5839 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005840 }
5841
Alexander Duyck5b7da512010-11-16 19:26:50 -08005842 for (i = 0; i < adapter->num_rx_queues; i++) {
5843 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5844 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5845 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5846 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005847 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005848 bytes += rx_ring->stats.bytes;
5849 packets += rx_ring->stats.packets;
5850 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005851 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005852 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5853 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005854 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005855 netdev->stats.rx_bytes = bytes;
5856 netdev->stats.rx_packets = packets;
5857
5858 bytes = 0;
5859 packets = 0;
5860 /* gather some stats to the adapter struct that are per queue */
5861 for (i = 0; i < adapter->num_tx_queues; i++) {
5862 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5863 restart_queue += tx_ring->tx_stats.restart_queue;
5864 tx_busy += tx_ring->tx_stats.tx_busy;
5865 bytes += tx_ring->stats.bytes;
5866 packets += tx_ring->stats.packets;
5867 }
5868 adapter->restart_queue = restart_queue;
5869 adapter->tx_busy = tx_busy;
5870 netdev->stats.tx_bytes = bytes;
5871 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005872
Joe Perches7ca647b2010-09-07 21:35:40 +00005873 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005874
5875 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005876 for (i = 0; i < 8; i++) {
5877 /* for packet buffers not used, the register should read 0 */
5878 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5879 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005880 hwstats->mpc[i] += mpc;
5881 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005882 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5883 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005884 switch (hw->mac.type) {
5885 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005886 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5887 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5888 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005889 hwstats->pxonrxc[i] +=
5890 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005891 break;
5892 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005893 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005894 hwstats->pxonrxc[i] +=
5895 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005896 break;
5897 default:
5898 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005899 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005900 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005901
5902 /*16 register reads */
5903 for (i = 0; i < 16; i++) {
5904 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5905 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5906 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5907 (hw->mac.type == ixgbe_mac_X540)) {
5908 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5909 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5910 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5911 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5912 }
5913 }
5914
Joe Perches7ca647b2010-09-07 21:35:40 +00005915 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005916 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005917 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005918
John Fastabendc84d3242010-11-16 19:27:12 -08005919 ixgbe_update_xoff_received(adapter);
5920
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005921 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005922 switch (hw->mac.type) {
5923 case ixgbe_mac_82598EB:
5924 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005925 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5926 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5927 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5928 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005929 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005930 /* OS2BMC stats are X540 only*/
5931 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5932 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5933 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5934 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5935 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005936 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005937 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005938 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005939 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005940 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005941 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005942 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005943 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5944 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005945#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005946 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5947 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5948 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5949 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5950 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5951 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005952 /* Add up per cpu counters for total ddp aloc fail */
5953 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5954 for_each_possible_cpu(cpu) {
5955 fcoe_noddp_counts_sum +=
5956 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5957 fcoe_noddp_ext_buff_counts_sum +=
5958 *per_cpu_ptr(fcoe->
5959 pcpu_noddp_ext_buff, cpu);
5960 }
5961 }
5962 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5963 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005964#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005965 break;
5966 default:
5967 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005968 }
Auke Kok9a799d72007-09-15 14:07:45 -07005969 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005970 hwstats->bprc += bprc;
5971 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005972 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005973 hwstats->mprc -= bprc;
5974 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5975 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5976 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5977 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5978 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5979 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5980 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5981 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005982 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005983 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005984 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005985 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005986 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5987 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005988 /*
5989 * 82598 errata - tx of flow control packets is included in tx counters
5990 */
5991 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005992 hwstats->gptc -= xon_off_tot;
5993 hwstats->mptc -= xon_off_tot;
5994 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5995 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5996 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5997 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5998 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5999 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6000 hwstats->ptc64 -= xon_off_tot;
6001 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6002 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6003 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6004 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6005 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6006 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006007
6008 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006009 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006010
6011 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006012 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006013 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006014 netdev->stats.rx_length_errors = hwstats->rlec;
6015 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006016 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006017}
6018
6019/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006020 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6021 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006022 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006023static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006024{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006025 struct ixgbe_hw *hw = &adapter->hw;
6026 int i;
6027
Alexander Duyckd034acf2011-04-27 09:25:34 +00006028 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6029 return;
6030
6031 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6032
6033 /* if interface is down do nothing */
6034 if (test_bit(__IXGBE_DOWN, &adapter->state))
6035 return;
6036
6037 /* do nothing if we are not using signature filters */
6038 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6039 return;
6040
6041 adapter->fdir_overflow++;
6042
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006043 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6044 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006045 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006046 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006047 /* re-enable flow director interrupts */
6048 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006049 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006050 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006051 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006052 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006053}
6054
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006055/**
6056 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6057 * @adapter - pointer to the device adapter structure
6058 *
6059 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006060 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006061 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006062 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006063 */
6064static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6065{
Auke Kok9a799d72007-09-15 14:07:45 -07006066 struct ixgbe_hw *hw = &adapter->hw;
6067 u64 eics = 0;
6068 int i;
6069
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006070 /* If we're down or resetting, just bail */
6071 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6072 test_bit(__IXGBE_RESETTING, &adapter->state))
6073 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006074
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006075 /* Force detection of hung controller */
6076 if (netif_carrier_ok(adapter->netdev)) {
6077 for (i = 0; i < adapter->num_tx_queues; i++)
6078 set_check_for_tx_hang(adapter->tx_ring[i]);
6079 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006080
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006081 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006082 /*
6083 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006084 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006085 * would set *both* EIMS and EICS for any bit in EIAM
6086 */
6087 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6088 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006089 } else {
6090 /* get one bit for every active tx/rx interrupt vector */
6091 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6092 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006093 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006094 eics |= ((u64)1 << i);
6095 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006096 }
6097
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006098 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006099 ixgbe_irq_rearm_queues(adapter, eics);
6100
Alexander Duyckfe49f042009-06-04 16:00:09 +00006101}
6102
6103/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006104 * ixgbe_watchdog_update_link - update the link status
6105 * @adapter - pointer to the device adapter structure
6106 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006107 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006108static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006109{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006110 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006111 u32 link_speed = adapter->link_speed;
6112 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006113 int i;
6114
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006115 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6116 return;
6117
6118 if (hw->mac.ops.check_link) {
6119 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006120 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006121 /* always assume link is up, if no check link function */
6122 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6123 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006124 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006125 if (link_up) {
6126 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6127 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6128 hw->mac.ops.fc_enable(hw, i);
6129 } else {
6130 hw->mac.ops.fc_enable(hw, 0);
6131 }
6132 }
6133
6134 if (link_up ||
6135 time_after(jiffies, (adapter->link_check_timeout +
6136 IXGBE_TRY_LINK_TIMEOUT))) {
6137 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6138 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6139 IXGBE_WRITE_FLUSH(hw);
6140 }
6141
6142 adapter->link_up = link_up;
6143 adapter->link_speed = link_speed;
6144}
6145
6146/**
6147 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6148 * print link up message
6149 * @adapter - pointer to the device adapter structure
6150 **/
6151static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6152{
6153 struct net_device *netdev = adapter->netdev;
6154 struct ixgbe_hw *hw = &adapter->hw;
6155 u32 link_speed = adapter->link_speed;
6156 bool flow_rx, flow_tx;
6157
6158 /* only continue if link was previously down */
6159 if (netif_carrier_ok(netdev))
6160 return;
6161
6162 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6163
6164 switch (hw->mac.type) {
6165 case ixgbe_mac_82598EB: {
6166 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6167 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6168 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6169 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6170 }
6171 break;
6172 case ixgbe_mac_X540:
6173 case ixgbe_mac_82599EB: {
6174 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6175 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6176 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6177 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6178 }
6179 break;
6180 default:
6181 flow_tx = false;
6182 flow_rx = false;
6183 break;
6184 }
6185 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6186 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6187 "10 Gbps" :
6188 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6189 "1 Gbps" :
6190 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6191 "100 Mbps" :
6192 "unknown speed"))),
6193 ((flow_rx && flow_tx) ? "RX/TX" :
6194 (flow_rx ? "RX" :
6195 (flow_tx ? "TX" : "None"))));
6196
6197 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006198 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006199}
6200
6201/**
6202 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6203 * print link down message
6204 * @adapter - pointer to the adapter structure
6205 **/
6206static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6207{
6208 struct net_device *netdev = adapter->netdev;
6209 struct ixgbe_hw *hw = &adapter->hw;
6210
6211 adapter->link_up = false;
6212 adapter->link_speed = 0;
6213
6214 /* only continue if link was up previously */
6215 if (!netif_carrier_ok(netdev))
6216 return;
6217
6218 /* poll for SFP+ cable when link is down */
6219 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6220 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6221
6222 e_info(drv, "NIC Link is Down\n");
6223 netif_carrier_off(netdev);
6224}
6225
6226/**
6227 * ixgbe_watchdog_flush_tx - flush queues on link down
6228 * @adapter - pointer to the device adapter structure
6229 **/
6230static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6231{
6232 int i;
6233 int some_tx_pending = 0;
6234
6235 if (!netif_carrier_ok(adapter->netdev)) {
6236 for (i = 0; i < adapter->num_tx_queues; i++) {
6237 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6238 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6239 some_tx_pending = 1;
6240 break;
6241 }
6242 }
6243
6244 if (some_tx_pending) {
6245 /* We've lost link, so the controller stops DMA,
6246 * but we've got queued Tx work that's never going
6247 * to get done, so reset controller to flush Tx.
6248 * (Do the reset outside of interrupt context).
6249 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006250 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006251 }
6252 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006253}
6254
Greg Rosea985b6c32010-11-18 03:02:52 +00006255static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6256{
6257 u32 ssvpc;
6258
6259 /* Do not perform spoof check for 82598 */
6260 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6261 return;
6262
6263 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6264
6265 /*
6266 * ssvpc register is cleared on read, if zero then no
6267 * spoofed packets in the last interval.
6268 */
6269 if (!ssvpc)
6270 return;
6271
6272 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6273}
6274
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006275/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006276 * ixgbe_watchdog_subtask - check and bring link up
6277 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006278 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006279static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006280{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006281 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006282 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6283 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006284 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006285
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006286 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006287
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006288 if (adapter->link_up)
6289 ixgbe_watchdog_link_is_up(adapter);
6290 else
6291 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006292
Greg Rosea985b6c32010-11-18 03:02:52 +00006293 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006294 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006295
6296 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006297}
6298
Alexander Duyck70864002011-04-27 09:13:56 +00006299/**
6300 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6301 * @adapter - the ixgbe adapter structure
6302 **/
6303static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6304{
6305 struct ixgbe_hw *hw = &adapter->hw;
6306 s32 err;
6307
6308 /* not searching for SFP so there is nothing to do here */
6309 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6310 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6311 return;
6312
6313 /* someone else is in init, wait until next service event */
6314 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6315 return;
6316
6317 err = hw->phy.ops.identify_sfp(hw);
6318 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6319 goto sfp_out;
6320
6321 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6322 /* If no cable is present, then we need to reset
6323 * the next time we find a good cable. */
6324 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6325 }
6326
6327 /* exit on error */
6328 if (err)
6329 goto sfp_out;
6330
6331 /* exit if reset not needed */
6332 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6333 goto sfp_out;
6334
6335 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6336
6337 /*
6338 * A module may be identified correctly, but the EEPROM may not have
6339 * support for that module. setup_sfp() will fail in that case, so
6340 * we should not allow that module to load.
6341 */
6342 if (hw->mac.type == ixgbe_mac_82598EB)
6343 err = hw->phy.ops.reset(hw);
6344 else
6345 err = hw->mac.ops.setup_sfp(hw);
6346
6347 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6348 goto sfp_out;
6349
6350 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6351 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6352
6353sfp_out:
6354 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6355
6356 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6357 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6358 e_dev_err("failed to initialize because an unsupported "
6359 "SFP+ module type was detected.\n");
6360 e_dev_err("Reload the driver after installing a "
6361 "supported module.\n");
6362 unregister_netdev(adapter->netdev);
6363 }
6364}
6365
6366/**
6367 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6368 * @adapter - the ixgbe adapter structure
6369 **/
6370static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6371{
6372 struct ixgbe_hw *hw = &adapter->hw;
6373 u32 autoneg;
6374 bool negotiation;
6375
6376 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6377 return;
6378
6379 /* someone else is in init, wait until next service event */
6380 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6381 return;
6382
6383 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6384
6385 autoneg = hw->phy.autoneg_advertised;
6386 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6387 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006388 if (hw->mac.ops.setup_link)
6389 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6390
6391 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6392 adapter->link_check_timeout = jiffies;
6393 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6394}
6395
Greg Rose83c61fa2011-09-07 05:59:35 +00006396#ifdef CONFIG_PCI_IOV
6397static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6398{
6399 int vf;
6400 struct ixgbe_hw *hw = &adapter->hw;
6401 struct net_device *netdev = adapter->netdev;
6402 u32 gpc;
6403 u32 ciaa, ciad;
6404
6405 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6406 if (gpc) /* If incrementing then no need for the check below */
6407 return;
6408 /*
6409 * Check to see if a bad DMA write target from an errant or
6410 * malicious VF has caused a PCIe error. If so then we can
6411 * issue a VFLR to the offending VF(s) and then resume without
6412 * requesting a full slot reset.
6413 */
6414
6415 for (vf = 0; vf < adapter->num_vfs; vf++) {
6416 ciaa = (vf << 16) | 0x80000000;
6417 /* 32 bit read so align, we really want status at offset 6 */
6418 ciaa |= PCI_COMMAND;
6419 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6420 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6421 ciaa &= 0x7FFFFFFF;
6422 /* disable debug mode asap after reading data */
6423 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6424 /* Get the upper 16 bits which will be the PCI status reg */
6425 ciad >>= 16;
6426 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6427 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6428 /* Issue VFLR */
6429 ciaa = (vf << 16) | 0x80000000;
6430 ciaa |= 0xA8;
6431 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6432 ciad = 0x00008000; /* VFLR */
6433 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6434 ciaa &= 0x7FFFFFFF;
6435 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6436 }
6437 }
6438}
6439
6440#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006441/**
6442 * ixgbe_service_timer - Timer Call-back
6443 * @data: pointer to adapter cast into an unsigned long
6444 **/
6445static void ixgbe_service_timer(unsigned long data)
6446{
6447 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6448 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006449 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006450
Greg Rose83c61fa2011-09-07 05:59:35 +00006451#ifdef CONFIG_PCI_IOV
6452 ready = false;
6453
6454 /*
6455 * don't bother with SR-IOV VF DMA hang check if there are
6456 * no VFs or the link is down
6457 */
6458 if (!adapter->num_vfs ||
6459 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6460 ready = true;
6461 goto normal_timer_service;
6462 }
6463
6464 /* If we have VFs allocated then we must check for DMA hangs */
6465 ixgbe_check_for_bad_vf(adapter);
6466 next_event_offset = HZ / 50;
6467 adapter->timer_event_accumulator++;
6468
6469 if (adapter->timer_event_accumulator >= 100) {
6470 ready = true;
6471 adapter->timer_event_accumulator = 0;
6472 }
6473
6474 goto schedule_event;
6475
6476normal_timer_service:
6477#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006478 /* poll faster when waiting for link */
6479 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6480 next_event_offset = HZ / 10;
6481 else
6482 next_event_offset = HZ * 2;
6483
Greg Rose83c61fa2011-09-07 05:59:35 +00006484#ifdef CONFIG_PCI_IOV
6485schedule_event:
6486#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006487 /* Reset the timer */
6488 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6489
Greg Rose83c61fa2011-09-07 05:59:35 +00006490 if (ready)
6491 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006492}
6493
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006494static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6495{
6496 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6497 return;
6498
6499 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6500
6501 /* If we're already down or resetting, just bail */
6502 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6503 test_bit(__IXGBE_RESETTING, &adapter->state))
6504 return;
6505
6506 ixgbe_dump(adapter);
6507 netdev_err(adapter->netdev, "Reset adapter\n");
6508 adapter->tx_timeout_count++;
6509
6510 ixgbe_reinit_locked(adapter);
6511}
6512
Alexander Duyck70864002011-04-27 09:13:56 +00006513/**
6514 * ixgbe_service_task - manages and runs subtasks
6515 * @work: pointer to work_struct containing our data
6516 **/
6517static void ixgbe_service_task(struct work_struct *work)
6518{
6519 struct ixgbe_adapter *adapter = container_of(work,
6520 struct ixgbe_adapter,
6521 service_task);
6522
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006523 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006524 ixgbe_sfp_detection_subtask(adapter);
6525 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006526 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006527 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006528 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006529 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006530
6531 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006532}
6533
Alexander Duyck897ab152011-05-27 05:31:47 +00006534void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6535 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006536{
6537 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006538 u16 i = tx_ring->next_to_use;
6539
Alexander Duycke4f74022012-01-31 02:59:44 +00006540 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006541
6542 i++;
6543 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6544
6545 /* set bits to identify this as an advanced context descriptor */
6546 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6547
6548 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6549 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6550 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6551 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6552}
6553
6554static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6555 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6556{
Auke Kok9a799d72007-09-15 14:07:45 -07006557 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006558 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006559 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006560
Alexander Duyck897ab152011-05-27 05:31:47 +00006561 if (!skb_is_gso(skb))
6562 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006563
Alexander Duyck897ab152011-05-27 05:31:47 +00006564 if (skb_header_cloned(skb)) {
6565 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6566 if (err)
6567 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006568 }
6569
Alexander Duyck897ab152011-05-27 05:31:47 +00006570 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6571 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6572
6573 if (protocol == __constant_htons(ETH_P_IP)) {
6574 struct iphdr *iph = ip_hdr(skb);
6575 iph->tot_len = 0;
6576 iph->check = 0;
6577 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6578 iph->daddr, 0,
6579 IPPROTO_TCP,
6580 0);
6581 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6582 } else if (skb_is_gso_v6(skb)) {
6583 ipv6_hdr(skb)->payload_len = 0;
6584 tcp_hdr(skb)->check =
6585 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6586 &ipv6_hdr(skb)->daddr,
6587 0, IPPROTO_TCP, 0);
6588 }
6589
6590 l4len = tcp_hdrlen(skb);
6591 *hdr_len = skb_transport_offset(skb) + l4len;
6592
6593 /* mss_l4len_id: use 1 as index for TSO */
6594 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6595 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6596 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6597
6598 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6599 vlan_macip_lens = skb_network_header_len(skb);
6600 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6601 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6602
6603 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6604 mss_l4len_idx);
6605
6606 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006607}
6608
Alexander Duyck897ab152011-05-27 05:31:47 +00006609static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006610 struct sk_buff *skb, u32 tx_flags,
6611 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006612{
Alexander Duyck897ab152011-05-27 05:31:47 +00006613 u32 vlan_macip_lens = 0;
6614 u32 mss_l4len_idx = 0;
6615 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006616
Alexander Duyck897ab152011-05-27 05:31:47 +00006617 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006618 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6619 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006620 return false;
6621 } else {
6622 u8 l4_hdr = 0;
6623 switch (protocol) {
6624 case __constant_htons(ETH_P_IP):
6625 vlan_macip_lens |= skb_network_header_len(skb);
6626 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6627 l4_hdr = ip_hdr(skb)->protocol;
6628 break;
6629 case __constant_htons(ETH_P_IPV6):
6630 vlan_macip_lens |= skb_network_header_len(skb);
6631 l4_hdr = ipv6_hdr(skb)->nexthdr;
6632 break;
6633 default:
6634 if (unlikely(net_ratelimit())) {
6635 dev_warn(tx_ring->dev,
6636 "partial checksum but proto=%x!\n",
6637 skb->protocol);
6638 }
6639 break;
6640 }
Auke Kok9a799d72007-09-15 14:07:45 -07006641
Alexander Duyck897ab152011-05-27 05:31:47 +00006642 switch (l4_hdr) {
6643 case IPPROTO_TCP:
6644 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6645 mss_l4len_idx = tcp_hdrlen(skb) <<
6646 IXGBE_ADVTXD_L4LEN_SHIFT;
6647 break;
6648 case IPPROTO_SCTP:
6649 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6650 mss_l4len_idx = sizeof(struct sctphdr) <<
6651 IXGBE_ADVTXD_L4LEN_SHIFT;
6652 break;
6653 case IPPROTO_UDP:
6654 mss_l4len_idx = sizeof(struct udphdr) <<
6655 IXGBE_ADVTXD_L4LEN_SHIFT;
6656 break;
6657 default:
6658 if (unlikely(net_ratelimit())) {
6659 dev_warn(tx_ring->dev,
6660 "partial checksum but l4 proto=%x!\n",
6661 skb->protocol);
6662 }
6663 break;
6664 }
Auke Kok9a799d72007-09-15 14:07:45 -07006665 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006666
Alexander Duyck897ab152011-05-27 05:31:47 +00006667 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6668 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6669
6670 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6671 type_tucmd, mss_l4len_idx);
6672
6673 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006674}
6675
Alexander Duyckd3d00232011-07-15 02:31:25 +00006676static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6677{
6678 /* set type for advanced descriptor with frame checksum insertion */
6679 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6680 IXGBE_ADVTXD_DCMD_IFCS |
6681 IXGBE_ADVTXD_DCMD_DEXT);
6682
6683 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006684 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006685 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6686
6687 /* set segmentation enable bits for TSO/FSO */
6688#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006689 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006690#else
6691 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6692#endif
6693 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6694
6695 return cmd_type;
6696}
6697
6698static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6699{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006700 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006701
6702 /* enable L4 checksum for TSO and TX checksum offload */
6703 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6704 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6705
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006706 /* enble IPv4 checksum for TSO */
6707 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6708 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006709
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006710 /* use index 1 context for TSO/FSO/FCOE */
6711#ifdef IXGBE_FCOE
6712 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6713#else
6714 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006715#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006716 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6717
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006718 /*
6719 * Check Context must be set if Tx switch is enabled, which it
6720 * always is for case where virtual functions are running
6721 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006722#ifdef IXGBE_FCOE
6723 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6724#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006725 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006726#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006727 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6728
Alexander Duyckd3d00232011-07-15 02:31:25 +00006729 return olinfo_status;
6730}
6731
6732#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6733 IXGBE_TXD_CMD_RS)
6734
6735static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6736 struct sk_buff *skb,
6737 struct ixgbe_tx_buffer *first,
6738 u32 tx_flags,
6739 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006740{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006741 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006742 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006743 union ixgbe_adv_tx_desc *tx_desc;
6744 dma_addr_t dma;
6745 __le32 cmd_type, olinfo_status;
6746 struct skb_frag_struct *frag;
6747 unsigned int f = 0;
6748 unsigned int data_len = skb->data_len;
6749 unsigned int size = skb_headlen(skb);
6750 u32 offset = 0;
6751 u32 paylen = skb->len - hdr_len;
6752 u16 i = tx_ring->next_to_use;
6753 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006754
Alexander Duyckd3d00232011-07-15 02:31:25 +00006755#ifdef IXGBE_FCOE
6756 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6757 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6758 data_len -= sizeof(struct fcoe_crc_eof);
6759 } else {
6760 size -= sizeof(struct fcoe_crc_eof) - data_len;
6761 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006762 }
Auke Kok9a799d72007-09-15 14:07:45 -07006763 }
6764
Alexander Duyckd3d00232011-07-15 02:31:25 +00006765#endif
6766 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6767 if (dma_mapping_error(dev, dma))
6768 goto dma_error;
6769
6770 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6771 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6772
Alexander Duycke4f74022012-01-31 02:59:44 +00006773 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006774
6775 for (;;) {
6776 while (size > IXGBE_MAX_DATA_PER_TXD) {
6777 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6778 tx_desc->read.cmd_type_len =
6779 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6780 tx_desc->read.olinfo_status = olinfo_status;
6781
6782 offset += IXGBE_MAX_DATA_PER_TXD;
6783 size -= IXGBE_MAX_DATA_PER_TXD;
6784
6785 tx_desc++;
6786 i++;
6787 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006788 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006789 i = 0;
6790 }
6791 }
6792
6793 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6794 tx_buffer_info->length = offset + size;
6795 tx_buffer_info->tx_flags = tx_flags;
6796 tx_buffer_info->dma = dma;
6797
6798 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
Ben Greearf43f3132012-03-06 09:42:04 +00006799 if (unlikely(skb->no_fcs))
6800 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006801 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6802 tx_desc->read.olinfo_status = olinfo_status;
6803
6804 if (!data_len)
6805 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006806
6807 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006808#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006809 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006810#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006811 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006812#endif
6813 data_len -= size;
6814 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006815
Alexander Duyckd3d00232011-07-15 02:31:25 +00006816 offset = 0;
6817 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006818
Ian Campbell877749b2011-08-29 23:18:26 +00006819 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006820 if (dma_mapping_error(dev, dma))
6821 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006822
Alexander Duyckd3d00232011-07-15 02:31:25 +00006823 tx_desc++;
6824 i++;
6825 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006826 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006827 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006828 }
6829 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006830
Alexander Duyckd3d00232011-07-15 02:31:25 +00006831 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6832
6833 i++;
6834 if (i == tx_ring->count)
6835 i = 0;
6836
6837 tx_ring->next_to_use = i;
6838
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006839 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6840 gso_segs = skb_shinfo(skb)->gso_segs;
6841#ifdef IXGBE_FCOE
6842 /* adjust for FCoE Sequence Offload */
6843 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6844 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6845 skb_shinfo(skb)->gso_size);
6846#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006847 else
6848 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006849
6850 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006851 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6852 tx_buffer_info->gso_segs = gso_segs;
6853 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006854
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006855 netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount);
6856
Alexander Duyckd3d00232011-07-15 02:31:25 +00006857 /* set the timestamp */
6858 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006859
6860 /*
6861 * Force memory writes to complete before letting h/w
6862 * know there are new descriptors to fetch. (Only
6863 * applicable for weak-ordered memory model archs,
6864 * such as IA-64).
6865 */
6866 wmb();
6867
Alexander Duyckd3d00232011-07-15 02:31:25 +00006868 /* set next_to_watch value indicating a packet is present */
6869 first->next_to_watch = tx_desc;
6870
6871 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006872 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006873
6874 return;
6875dma_error:
6876 dev_err(dev, "TX DMA map failed\n");
6877
6878 /* clear dma mappings for failed tx_buffer_info map */
6879 for (;;) {
6880 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6881 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6882 if (tx_buffer_info == first)
6883 break;
6884 if (i == 0)
6885 i = tx_ring->count;
6886 i--;
6887 }
6888
6889 dev_kfree_skb_any(skb);
6890
6891 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006892}
6893
Alexander Duyck69830522011-01-06 14:29:58 +00006894static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6895 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006896{
Alexander Duyck69830522011-01-06 14:29:58 +00006897 struct ixgbe_q_vector *q_vector = ring->q_vector;
6898 union ixgbe_atr_hash_dword input = { .dword = 0 };
6899 union ixgbe_atr_hash_dword common = { .dword = 0 };
6900 union {
6901 unsigned char *network;
6902 struct iphdr *ipv4;
6903 struct ipv6hdr *ipv6;
6904 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006905 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006906 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006907
Alexander Duyck69830522011-01-06 14:29:58 +00006908 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6909 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006910 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006911
Alexander Duyck69830522011-01-06 14:29:58 +00006912 /* do nothing if sampling is disabled */
6913 if (!ring->atr_sample_rate)
6914 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006915
Alexander Duyck69830522011-01-06 14:29:58 +00006916 ring->atr_count++;
6917
6918 /* snag network header to get L4 type and address */
6919 hdr.network = skb_network_header(skb);
6920
6921 /* Currently only IPv4/IPv6 with TCP is supported */
6922 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6923 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6924 (protocol != __constant_htons(ETH_P_IP) ||
6925 hdr.ipv4->protocol != IPPROTO_TCP))
6926 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006927
6928 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006929
Alexander Duyck66f32a82011-06-29 05:43:22 +00006930 /* skip this packet since it is invalid or the socket is closing */
6931 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006932 return;
6933
6934 /* sample on all syn packets or once every atr sample count */
6935 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6936 return;
6937
6938 /* reset sample count */
6939 ring->atr_count = 0;
6940
6941 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6942
6943 /*
6944 * src and dst are inverted, think how the receiver sees them
6945 *
6946 * The input is broken into two sections, a non-compressed section
6947 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6948 * is XORed together and stored in the compressed dword.
6949 */
6950 input.formatted.vlan_id = vlan_id;
6951
6952 /*
6953 * since src port and flex bytes occupy the same word XOR them together
6954 * and write the value to source port portion of compressed dword
6955 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006956 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006957 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6958 else
6959 common.port.src ^= th->dest ^ protocol;
6960 common.port.dst ^= th->source;
6961
6962 if (protocol == __constant_htons(ETH_P_IP)) {
6963 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6964 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6965 } else {
6966 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6967 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6968 hdr.ipv6->saddr.s6_addr32[1] ^
6969 hdr.ipv6->saddr.s6_addr32[2] ^
6970 hdr.ipv6->saddr.s6_addr32[3] ^
6971 hdr.ipv6->daddr.s6_addr32[0] ^
6972 hdr.ipv6->daddr.s6_addr32[1] ^
6973 hdr.ipv6->daddr.s6_addr32[2] ^
6974 hdr.ipv6->daddr.s6_addr32[3];
6975 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006976
6977 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006978 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6979 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006980}
6981
Alexander Duyck63544e92011-05-27 05:31:42 +00006982static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006983{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006984 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006985 /* Herbert's original patch had:
6986 * smp_mb__after_netif_stop_queue();
6987 * but since that doesn't exist yet, just open code it. */
6988 smp_mb();
6989
6990 /* We need to check again in a case another CPU has just
6991 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006992 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006993 return -EBUSY;
6994
6995 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006996 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006997 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006998 return 0;
6999}
7000
Alexander Duyck82d4e462011-06-11 01:44:58 +00007001static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007002{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00007003 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007004 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007005 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007006}
7007
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007008static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
7009{
7010 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00007011 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7012 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00007013#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00007014 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00007015
John Fastabende5b64632011-03-08 03:44:52 +00007016 if (((protocol == htons(ETH_P_FCOE)) ||
7017 (protocol == htons(ETH_P_FIP))) &&
7018 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
7019 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
7020 txq += adapter->ring_feature[RING_F_FCOE].mask;
7021 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00007022 }
7023#endif
7024
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007025 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
7026 while (unlikely(txq >= dev->real_num_tx_queues))
7027 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00007028 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007029 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007030
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007031 return skb_tx_hash(dev, skb);
7032}
7033
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007034netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007035 struct ixgbe_adapter *adapter,
7036 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007037{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007038 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007039 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007040 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007041#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7042 unsigned short f;
7043#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007044 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007045 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007046 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007047
Alexander Duycka535c302011-05-27 05:31:52 +00007048 /*
7049 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007050 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007051 * + 2 desc gap to keep tail from touching head,
7052 * + 1 desc for context descriptor,
7053 * otherwise try next time
7054 */
7055#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7056 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7057 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7058#else
7059 count += skb_shinfo(skb)->nr_frags;
7060#endif
7061 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7062 tx_ring->tx_stats.tx_busy++;
7063 return NETDEV_TX_BUSY;
7064 }
7065
Alexander Duyck66f32a82011-06-29 05:43:22 +00007066 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007067 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007068 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7069 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7070 /* else if it is a SW VLAN check the next protocol and store the tag */
7071 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7072 struct vlan_hdr *vhdr, _vhdr;
7073 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7074 if (!vhdr)
7075 goto out_drop;
7076
7077 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007078 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7079 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007080 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007081 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007082
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007083#ifdef CONFIG_PCI_IOV
7084 /*
7085 * Use the l2switch_enable flag - would be false if the DMA
7086 * Tx switch had been disabled.
7087 */
7088 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7089 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7090
7091#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007092 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007093 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007094 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7095 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007096 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007097 tx_flags |= (skb->priority & 0x7) <<
7098 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007099 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7100 struct vlan_ethhdr *vhdr;
7101 if (skb_header_cloned(skb) &&
7102 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7103 goto out_drop;
7104 vhdr = (struct vlan_ethhdr *)skb->data;
7105 vhdr->h_vlan_TCI = htons(tx_flags >>
7106 IXGBE_TX_FLAGS_VLAN_SHIFT);
7107 } else {
7108 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7109 }
7110 }
Alexander Duycka535c302011-05-27 05:31:52 +00007111
Alexander Duycka535c302011-05-27 05:31:52 +00007112 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007113 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007114
Yi Zoueacd73f2009-05-13 13:11:06 +00007115#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007116 /* setup tx offload for FCoE */
7117 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7118 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007119 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7120 if (tso < 0)
7121 goto out_drop;
7122 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007123 tx_flags |= IXGBE_TX_FLAGS_FSO |
7124 IXGBE_TX_FLAGS_FCOE;
7125 else
7126 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007127
Alexander Duyck66f32a82011-06-29 05:43:22 +00007128 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007129 }
Auke Kok9a799d72007-09-15 14:07:45 -07007130
Auke Kok9a799d72007-09-15 14:07:45 -07007131#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007132 /* setup IPv4/IPv6 offloads */
7133 if (protocol == __constant_htons(ETH_P_IP))
7134 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007135
Alexander Duyck66f32a82011-06-29 05:43:22 +00007136 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7137 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007138 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007139 else if (tso)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007140 tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007141 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7142 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7143
7144 /* add the ATR filter if ATR is on */
7145 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7146 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7147
7148#ifdef IXGBE_FCOE
7149xmit_fcoe:
7150#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007151 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7152
7153 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007154
7155 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007156
7157out_drop:
7158 dev_kfree_skb_any(skb);
7159 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007160}
7161
Alexander Duycka50c29d2012-02-08 07:50:40 +00007162static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7163 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007164{
7165 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7166 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007167
Alexander Duycka50c29d2012-02-08 07:50:40 +00007168 if (skb->len <= 0) {
7169 dev_kfree_skb_any(skb);
7170 return NETDEV_TX_OK;
7171 }
7172
7173 /*
7174 * The minimum packet size for olinfo paylen is 17 so pad the skb
7175 * in order to meet this minimum size requirement.
7176 */
7177 if (skb->len < 17) {
7178 if (skb_padto(skb, 17))
7179 return NETDEV_TX_OK;
7180 skb->len = 17;
7181 }
7182
Auke Kok9a799d72007-09-15 14:07:45 -07007183 tx_ring = adapter->tx_ring[skb->queue_mapping];
7184 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7185}
7186
7187/**
7188 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007189 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007190 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007191 *
Auke Kok9a799d72007-09-15 14:07:45 -07007192 * Returns 0 on success, negative on failure
7193 **/
7194static int ixgbe_set_mac(struct net_device *netdev, void *p)
7195{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007196 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7197 struct ixgbe_hw *hw = &adapter->hw;
7198 struct sockaddr *addr = p;
7199
7200 if (!is_valid_ether_addr(addr->sa_data))
7201 return -EADDRNOTAVAIL;
7202
7203 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7204 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7205
7206 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7207 IXGBE_RAH_AV);
7208
7209 return 0;
7210}
7211
7212static int
7213ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7214{
7215 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7216 struct ixgbe_hw *hw = &adapter->hw;
7217 u16 value;
7218 int rc;
7219
7220 if (prtad != hw->phy.mdio.prtad)
7221 return -EINVAL;
7222 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7223 if (!rc)
7224 rc = value;
7225 return rc;
7226}
7227
7228static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7229 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007230{
7231 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007232 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007233
7234 if (prtad != hw->phy.mdio.prtad)
7235 return -EINVAL;
7236 return hw->phy.ops.write_reg(hw, addr, devad, value);
7237}
7238
7239static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7240{
7241 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7242
7243 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7244}
7245
7246/**
7247 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7248 * netdev->dev_addrs
7249 * @netdev: network interface device structure
7250 *
7251 * Returns non-zero on failure
7252 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007253static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007254{
7255 int err = 0;
7256 struct ixgbe_adapter *adapter = netdev_priv(dev);
7257 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7258
7259 if (is_valid_ether_addr(mac->san_addr)) {
7260 rtnl_lock();
7261 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7262 rtnl_unlock();
7263 }
7264 return err;
7265}
7266
7267/**
7268 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7269 * netdev->dev_addrs
7270 * @netdev: network interface device structure
7271 *
Auke Kok9a799d72007-09-15 14:07:45 -07007272 * Returns non-zero on failure
7273 **/
7274static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7275{
7276 int err = 0;
7277 struct ixgbe_adapter *adapter = netdev_priv(dev);
7278 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7279
7280 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007281 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007282 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007283 rtnl_unlock();
7284 }
7285 return err;
7286}
Auke Kok9a799d72007-09-15 14:07:45 -07007287
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007288#ifdef CONFIG_NET_POLL_CONTROLLER
7289/*
7290 * Polling 'interrupt' - used by things like netconsole to send skbs
7291 * without having to re-enable interrupts. It's not called while
7292 * the interrupt routine is executing.
7293 */
7294static void ixgbe_netpoll(struct net_device *netdev)
7295{
7296 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007297 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007298
7299 /* if interface is down do nothing */
7300 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007301 return;
7302
7303 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007304 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007305 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007306 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007307 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007308 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007309 }
7310 } else {
7311 ixgbe_intr(adapter->pdev->irq, netdev);
7312 }
7313 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7314}
7315#endif
7316
Eric Dumazetde1036b2010-10-20 23:00:04 +00007317static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7318 struct rtnl_link_stats64 *stats)
7319{
7320 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7321 int i;
7322
Eric Dumazet1a515022010-11-16 19:26:42 -08007323 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007324 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007325 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007326 u64 bytes, packets;
7327 unsigned int start;
7328
Eric Dumazet1a515022010-11-16 19:26:42 -08007329 if (ring) {
7330 do {
7331 start = u64_stats_fetch_begin_bh(&ring->syncp);
7332 packets = ring->stats.packets;
7333 bytes = ring->stats.bytes;
7334 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7335 stats->rx_packets += packets;
7336 stats->rx_bytes += bytes;
7337 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007338 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007339
7340 for (i = 0; i < adapter->num_tx_queues; i++) {
7341 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7342 u64 bytes, packets;
7343 unsigned int start;
7344
7345 if (ring) {
7346 do {
7347 start = u64_stats_fetch_begin_bh(&ring->syncp);
7348 packets = ring->stats.packets;
7349 bytes = ring->stats.bytes;
7350 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7351 stats->tx_packets += packets;
7352 stats->tx_bytes += bytes;
7353 }
7354 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007355 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007356 /* following stats updated by ixgbe_watchdog_task() */
7357 stats->multicast = netdev->stats.multicast;
7358 stats->rx_errors = netdev->stats.rx_errors;
7359 stats->rx_length_errors = netdev->stats.rx_length_errors;
7360 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7361 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7362 return stats;
7363}
7364
John Fastabend8b1c0b22011-05-03 02:26:48 +00007365/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7366 * #adapter: pointer to ixgbe_adapter
7367 * @tc: number of traffic classes currently enabled
7368 *
7369 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7370 * 802.1Q priority maps to a packet buffer that exists.
7371 */
7372static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7373{
7374 struct ixgbe_hw *hw = &adapter->hw;
7375 u32 reg, rsave;
7376 int i;
7377
7378 /* 82598 have a static priority to TC mapping that can not
7379 * be changed so no validation is needed.
7380 */
7381 if (hw->mac.type == ixgbe_mac_82598EB)
7382 return;
7383
7384 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7385 rsave = reg;
7386
7387 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7388 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7389
7390 /* If up2tc is out of bounds default to zero */
7391 if (up2tc > tc)
7392 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7393 }
7394
7395 if (reg != rsave)
7396 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7397
7398 return;
7399}
7400
7401
7402/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7403 * classes.
7404 *
7405 * @netdev: net device to configure
7406 * @tc: number of traffic classes to enable
7407 */
7408int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7409{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007410 struct ixgbe_adapter *adapter = netdev_priv(dev);
7411 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007412
John Fastabende7589ea2011-07-18 22:38:36 +00007413 /* Multiple traffic classes requires multiple queues */
7414 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7415 e_err(drv, "Enable failed, needs MSI-X\n");
7416 return -EINVAL;
7417 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007418
7419 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007420 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007421 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7422 return -EINVAL;
7423
7424 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007425 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007426 * hardware is not flexible enough to do this dynamically.
7427 */
7428 if (netif_running(dev))
7429 ixgbe_close(dev);
7430 ixgbe_clear_interrupt_scheme(adapter);
7431
John Fastabende7589ea2011-07-18 22:38:36 +00007432 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007433 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007434 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7435
7436 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7437 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7438
7439 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7440 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7441 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007442 netdev_reset_tc(dev);
7443
John Fastabende7589ea2011-07-18 22:38:36 +00007444 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7445
7446 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7447 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7448
7449 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7450 adapter->dcb_cfg.pfc_mode_enable = false;
7451 }
7452
John Fastabend8b1c0b22011-05-03 02:26:48 +00007453 ixgbe_init_interrupt_scheme(adapter);
7454 ixgbe_validate_rtr(adapter, tc);
7455 if (netif_running(dev))
7456 ixgbe_open(dev);
7457
7458 return 0;
7459}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007460
Don Skidmore082757a2011-07-21 05:55:00 +00007461void ixgbe_do_reset(struct net_device *netdev)
7462{
7463 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7464
7465 if (netif_running(netdev))
7466 ixgbe_reinit_locked(adapter);
7467 else
7468 ixgbe_reset(adapter);
7469}
7470
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007471static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7472 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007473{
7474 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7475
7476#ifdef CONFIG_DCB
7477 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7478 data &= ~NETIF_F_HW_VLAN_RX;
7479#endif
7480
7481 /* return error if RXHASH is being enabled when RSS is not supported */
7482 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7483 data &= ~NETIF_F_RXHASH;
7484
7485 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7486 if (!(data & NETIF_F_RXCSUM))
7487 data &= ~NETIF_F_LRO;
7488
7489 /* Turn off LRO if not RSC capable or invalid ITR settings */
7490 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7491 data &= ~NETIF_F_LRO;
7492 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7493 (adapter->rx_itr_setting != 1 &&
7494 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7495 data &= ~NETIF_F_LRO;
7496 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7497 }
7498
7499 return data;
7500}
7501
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007502static int ixgbe_set_features(struct net_device *netdev,
7503 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007504{
7505 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ben Greear3f2d1c02012-03-08 08:28:41 +00007506 netdev_features_t changed = netdev->features ^ data;
Don Skidmore082757a2011-07-21 05:55:00 +00007507 bool need_reset = false;
7508
Don Skidmore082757a2011-07-21 05:55:00 +00007509 /* Make sure RSC matches LRO, reset if change */
7510 if (!!(data & NETIF_F_LRO) !=
7511 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7512 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7513 switch (adapter->hw.mac.type) {
7514 case ixgbe_mac_X540:
7515 case ixgbe_mac_82599EB:
7516 need_reset = true;
7517 break;
7518 default:
7519 break;
7520 }
7521 }
7522
7523 /*
7524 * Check if Flow Director n-tuple support was enabled or disabled. If
7525 * the state changed, we need to reset.
7526 */
7527 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7528 /* turn off ATR, enable perfect filters and reset */
7529 if (data & NETIF_F_NTUPLE) {
7530 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7531 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7532 need_reset = true;
7533 }
7534 } else if (!(data & NETIF_F_NTUPLE)) {
7535 /* turn off Flow Director, set ATR and reset */
7536 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7537 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7538 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7539 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7540 need_reset = true;
7541 }
7542
Ben Greear3f2d1c02012-03-08 08:28:41 +00007543 if (changed & NETIF_F_RXALL)
7544 need_reset = true;
7545
7546 netdev->features = data;
Don Skidmore082757a2011-07-21 05:55:00 +00007547 if (need_reset)
7548 ixgbe_do_reset(netdev);
7549
7550 return 0;
7551
7552}
7553
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007554static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007555 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007556 .ndo_stop = ixgbe_close,
7557 .ndo_start_xmit = ixgbe_xmit_frame,
7558 .ndo_select_queue = ixgbe_select_queue,
7559 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007560 .ndo_validate_addr = eth_validate_addr,
7561 .ndo_set_mac_address = ixgbe_set_mac,
7562 .ndo_change_mtu = ixgbe_change_mtu,
7563 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007564 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7565 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007566 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007567 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7568 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7569 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007570 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007571 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007572 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007573 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007574#ifdef CONFIG_NET_POLL_CONTROLLER
7575 .ndo_poll_controller = ixgbe_netpoll,
7576#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007577#ifdef IXGBE_FCOE
7578 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007579 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007580 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007581 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7582 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007583 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007584 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007585#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007586 .ndo_set_features = ixgbe_set_features,
7587 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007588};
7589
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007590static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7591 const struct ixgbe_info *ii)
7592{
7593#ifdef CONFIG_PCI_IOV
7594 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007595
Greg Rosec6bda302011-08-24 02:37:55 +00007596 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007597 return;
7598
7599 /* The 82599 supports up to 64 VFs per physical function
7600 * but this implementation limits allocation to 63 so that
7601 * basic networking resources are still available to the
7602 * physical function
7603 */
7604 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007605 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007606#endif /* CONFIG_PCI_IOV */
7607}
7608
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007609/**
Auke Kok9a799d72007-09-15 14:07:45 -07007610 * ixgbe_probe - Device Initialization Routine
7611 * @pdev: PCI device information struct
7612 * @ent: entry in ixgbe_pci_tbl
7613 *
7614 * Returns 0 on success, negative on failure
7615 *
7616 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7617 * The OS initialization, configuring of the adapter private structure,
7618 * and a hardware reset occur.
7619 **/
7620static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007621 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007622{
7623 struct net_device *netdev;
7624 struct ixgbe_adapter *adapter = NULL;
7625 struct ixgbe_hw *hw;
7626 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007627 static int cards_found;
7628 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007629 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007630 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007631#ifdef IXGBE_FCOE
7632 u16 device_caps;
7633#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007634 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007635 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007636
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007637 /* Catch broken hardware that put the wrong VF device ID in
7638 * the PCIe SR-IOV capability.
7639 */
7640 if (pdev->is_virtfn) {
7641 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7642 pci_name(pdev), pdev->vendor, pdev->device);
7643 return -EINVAL;
7644 }
7645
gouji-new9ce77662009-05-06 10:44:45 +00007646 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007647 if (err)
7648 return err;
7649
Nick Nunley1b507732010-04-27 13:10:27 +00007650 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7651 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007652 pci_using_dac = 1;
7653 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007654 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007655 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007656 err = dma_set_coherent_mask(&pdev->dev,
7657 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007658 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007659 dev_err(&pdev->dev,
7660 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007661 goto err_dma;
7662 }
7663 }
7664 pci_using_dac = 0;
7665 }
7666
gouji-new9ce77662009-05-06 10:44:45 +00007667 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007668 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007669 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007670 dev_err(&pdev->dev,
7671 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007672 goto err_pci_reg;
7673 }
7674
Frans Pop19d5afd2009-10-02 10:04:12 -07007675 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007676
Auke Kok9a799d72007-09-15 14:07:45 -07007677 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007678 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007679
John Fastabende901acd2011-04-26 07:26:08 +00007680#ifdef CONFIG_IXGBE_DCB
7681 indices *= MAX_TRAFFIC_CLASS;
7682#endif
7683
John Fastabendc85a2612010-02-25 23:15:21 +00007684 if (ii->mac == ixgbe_mac_82598EB)
7685 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7686 else
7687 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7688
John Fastabende901acd2011-04-26 07:26:08 +00007689#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007690 indices += min_t(unsigned int, num_possible_cpus(),
7691 IXGBE_MAX_FCOE_INDICES);
7692#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007693 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007694 if (!netdev) {
7695 err = -ENOMEM;
7696 goto err_alloc_etherdev;
7697 }
7698
Auke Kok9a799d72007-09-15 14:07:45 -07007699 SET_NETDEV_DEV(netdev, &pdev->dev);
7700
Auke Kok9a799d72007-09-15 14:07:45 -07007701 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007702 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007703
7704 adapter->netdev = netdev;
7705 adapter->pdev = pdev;
7706 hw = &adapter->hw;
7707 hw->back = adapter;
7708 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7709
Jeff Kirsher05857982008-09-11 19:57:00 -07007710 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007711 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007712 if (!hw->hw_addr) {
7713 err = -EIO;
7714 goto err_ioremap;
7715 }
7716
7717 for (i = 1; i <= 5; i++) {
7718 if (pci_resource_len(pdev, i) == 0)
7719 continue;
7720 }
7721
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007722 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007723 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007724 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007725 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007726
Auke Kok9a799d72007-09-15 14:07:45 -07007727 adapter->bd_number = cards_found;
7728
Auke Kok9a799d72007-09-15 14:07:45 -07007729 /* Setup hw api */
7730 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007731 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007732
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007733 /* EEPROM */
7734 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7735 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7736 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7737 if (!(eec & (1 << 8)))
7738 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7739
7740 /* PHY */
7741 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007742 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007743 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7744 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7745 hw->phy.mdio.mmds = 0;
7746 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7747 hw->phy.mdio.dev = netdev;
7748 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7749 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007750
Don Skidmore8ca783a2009-05-26 20:40:47 -07007751 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007752
7753 /* setup the private structure */
7754 err = ixgbe_sw_init(adapter);
7755 if (err)
7756 goto err_sw_init;
7757
Don Skidmoree86bff02010-02-11 04:14:08 +00007758 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007759 switch (adapter->hw.mac.type) {
7760 case ixgbe_mac_82599EB:
7761 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007762 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007763 break;
7764 default:
7765 break;
7766 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007767
Don Skidmorebf069c92009-05-07 10:39:54 +00007768 /*
7769 * If there is a fan on this device and it has failed log the
7770 * failure.
7771 */
7772 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7773 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7774 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007775 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007776 }
7777
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007778 if (allow_unsupported_sfp)
7779 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7780
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007781 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007782 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007783 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007784 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007785 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7786 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007787 err = 0;
7788 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007789 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007790 "module type was detected.\n");
7791 e_dev_err("Reload the driver after installing a supported "
7792 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007793 goto err_sw_init;
7794 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007795 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007796 goto err_sw_init;
7797 }
7798
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007799 ixgbe_probe_vf(adapter, ii);
7800
Emil Tantilov396e7992010-07-01 20:05:12 +00007801 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007802 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007803 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007804 NETIF_F_HW_VLAN_TX |
7805 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007806 NETIF_F_HW_VLAN_FILTER |
7807 NETIF_F_TSO |
7808 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007809 NETIF_F_RXHASH |
7810 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007811
Don Skidmore082757a2011-07-21 05:55:00 +00007812 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007813
Don Skidmore58be7662011-04-12 09:42:11 +00007814 switch (adapter->hw.mac.type) {
7815 case ixgbe_mac_82599EB:
7816 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007817 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007818 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7819 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007820 break;
7821 default:
7822 break;
7823 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007824
Ben Greear3f2d1c02012-03-08 08:28:41 +00007825 netdev->hw_features |= NETIF_F_RXALL;
7826
Jeff Kirsherad31c402008-06-05 04:05:30 -07007827 netdev->vlan_features |= NETIF_F_TSO;
7828 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007829 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007830 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007831 netdev->vlan_features |= NETIF_F_SG;
7832
Jiri Pirko01789342011-08-16 06:29:00 +00007833 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007834 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007835
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007836 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7837 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7838 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007839
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007840#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007841 netdev->dcbnl_ops = &dcbnl_ops;
7842#endif
7843
Yi Zoueacd73f2009-05-13 13:11:06 +00007844#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007845 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007846 if (hw->mac.ops.get_device_caps) {
7847 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007848 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7849 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007850 }
7851 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007852 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7853 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7854 netdev->vlan_features |= NETIF_F_FSO;
7855 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7856 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007857#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007858 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007859 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007860 netdev->vlan_features |= NETIF_F_HIGHDMA;
7861 }
Auke Kok9a799d72007-09-15 14:07:45 -07007862
Don Skidmore082757a2011-07-21 05:55:00 +00007863 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7864 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007865 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007866 netdev->features |= NETIF_F_LRO;
7867
Auke Kok9a799d72007-09-15 14:07:45 -07007868 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007869 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007870 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007871 err = -EIO;
7872 goto err_eeprom;
7873 }
7874
7875 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7876 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7877
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007878 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007879 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007880 err = -EIO;
7881 goto err_eeprom;
7882 }
7883
Alexander Duyck70864002011-04-27 09:13:56 +00007884 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7885 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007886
Alexander Duyck70864002011-04-27 09:13:56 +00007887 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7888 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007889
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007890 err = ixgbe_init_interrupt_scheme(adapter);
7891 if (err)
7892 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007893
Don Skidmore082757a2011-07-21 05:55:00 +00007894 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7895 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007896 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007897 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007898
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007899 /* WOL not supported for all but the following */
7900 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007901 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007902 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007903 /* Only these subdevice supports WOL */
7904 switch (pdev->subsystem_device) {
7905 case IXGBE_SUBDEV_ID_82599_560FLR:
7906 /* only support first port */
7907 if (hw->bus.func != 0)
7908 break;
7909 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007910 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007911 break;
7912 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007913 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007914 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7915 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007916 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007917 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007918 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007919 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007920 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007921 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007922 case IXGBE_DEV_ID_X540T:
7923 /* Check eeprom to see if it is enabled */
7924 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7925 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7926
7927 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7928 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7929 (hw->bus.func == 0)))
7930 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007931 break;
7932 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007933 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7934
Emil Tantilov15e52092011-09-29 05:01:29 +00007935 /* save off EEPROM version number */
7936 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7937 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7938
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007939 /* pick up the PCI bus settings for reporting later */
7940 hw->mac.ops.get_bus_info(hw);
7941
Auke Kok9a799d72007-09-15 14:07:45 -07007942 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007943 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007944 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7945 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007946 "Unknown"),
7947 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7948 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7949 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7950 "Unknown"),
7951 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007952
7953 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7954 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007955 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007956 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007957 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007958 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007959 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007960 else
Don Skidmore289700db2010-12-03 03:32:58 +00007961 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7962 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007963
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007964 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007965 e_dev_warn("PCI-Express bandwidth available for this card is "
7966 "not sufficient for optimal performance.\n");
7967 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7968 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007969 }
7970
Auke Kok9a799d72007-09-15 14:07:45 -07007971 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007972 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007973
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007974 if (err == IXGBE_ERR_EEPROM_VERSION) {
7975 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007976 e_dev_warn("This device is a pre-production adapter/LOM. "
7977 "Please be aware there may be issues associated "
7978 "with your hardware. If you are experiencing "
7979 "problems please contact your Intel or hardware "
7980 "representative who provided you with this "
7981 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007982 }
Auke Kok9a799d72007-09-15 14:07:45 -07007983 strcpy(netdev->name, "eth%d");
7984 err = register_netdev(netdev);
7985 if (err)
7986 goto err_register;
7987
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007988 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7989 if (hw->mac.ops.disable_tx_laser &&
7990 ((hw->phy.multispeed_fiber) ||
7991 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7992 (hw->mac.type == ixgbe_mac_82599EB))))
7993 hw->mac.ops.disable_tx_laser(hw);
7994
Jesse Brandeburg54386462009-04-17 20:44:27 +00007995 /* carrier off reporting is important to ethtool even BEFORE open */
7996 netif_carrier_off(netdev);
7997
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007998#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007999 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008000 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008001 ixgbe_setup_dca(adapter);
8002 }
8003#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008004 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008005 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008006 for (i = 0; i < adapter->num_vfs; i++)
8007 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8008 }
8009
Jacob Keller2466dd92011-09-08 03:50:54 +00008010 /* firmware requires driver version to be 0xFFFFFFFF
8011 * since os does not support feature
8012 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008013 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008014 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8015 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008016
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008017 /* add san mac addr to netdev */
8018 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008019
Neerav Parikhea818752012-01-04 20:23:40 +00008020 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07008021 cards_found++;
8022 return 0;
8023
8024err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008025 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008026 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008027err_sw_init:
8028err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008029 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
8030 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008031 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07008032 iounmap(hw->hw_addr);
8033err_ioremap:
8034 free_netdev(netdev);
8035err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008036 pci_release_selected_regions(pdev,
8037 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008038err_pci_reg:
8039err_dma:
8040 pci_disable_device(pdev);
8041 return err;
8042}
8043
8044/**
8045 * ixgbe_remove - Device Removal Routine
8046 * @pdev: PCI device information struct
8047 *
8048 * ixgbe_remove is called by the PCI subsystem to alert the driver
8049 * that it should release a PCI device. The could be caused by a
8050 * Hot-Plug event, or because the driver is going to be removed from
8051 * memory.
8052 **/
8053static void __devexit ixgbe_remove(struct pci_dev *pdev)
8054{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008055 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8056 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008057
8058 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008059 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008060
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008061#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008062 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8063 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8064 dca_remove_requester(&pdev->dev);
8065 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8066 }
8067
8068#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008069#ifdef IXGBE_FCOE
8070 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8071 ixgbe_cleanup_fcoe(adapter);
8072
8073#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008074
8075 /* remove the added san mac */
8076 ixgbe_del_sanmac_netdev(netdev);
8077
Donald Skidmorec4900be2008-11-20 21:11:42 -08008078 if (netdev->reg_state == NETREG_REGISTERED)
8079 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008080
Greg Rosec6bda302011-08-24 02:37:55 +00008081 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8082 if (!(ixgbe_check_vf_assignment(adapter)))
8083 ixgbe_disable_sriov(adapter);
8084 else
8085 e_dev_warn("Unloading driver while VFs are assigned "
8086 "- VFs will not be deallocated\n");
8087 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008088
Alexander Duyck7a921c92009-05-06 10:43:28 +00008089 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008090
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008091 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008092
8093 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008094 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008095 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008096
Emil Tantilov849c4542010-06-03 16:53:41 +00008097 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008098
Auke Kok9a799d72007-09-15 14:07:45 -07008099 free_netdev(netdev);
8100
Frans Pop19d5afd2009-10-02 10:04:12 -07008101 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008102
Auke Kok9a799d72007-09-15 14:07:45 -07008103 pci_disable_device(pdev);
8104}
8105
8106/**
8107 * ixgbe_io_error_detected - called when PCI error is detected
8108 * @pdev: Pointer to PCI device
8109 * @state: The current pci connection state
8110 *
8111 * This function is called after a PCI bus error affecting
8112 * this device has been detected.
8113 */
8114static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008115 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008116{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008117 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8118 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008119
Greg Rose83c61fa2011-09-07 05:59:35 +00008120#ifdef CONFIG_PCI_IOV
8121 struct pci_dev *bdev, *vfdev;
8122 u32 dw0, dw1, dw2, dw3;
8123 int vf, pos;
8124 u16 req_id, pf_func;
8125
8126 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8127 adapter->num_vfs == 0)
8128 goto skip_bad_vf_detection;
8129
8130 bdev = pdev->bus->self;
8131 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8132 bdev = bdev->bus->self;
8133
8134 if (!bdev)
8135 goto skip_bad_vf_detection;
8136
8137 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8138 if (!pos)
8139 goto skip_bad_vf_detection;
8140
8141 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8142 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8143 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8144 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8145
8146 req_id = dw1 >> 16;
8147 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8148 if (!(req_id & 0x0080))
8149 goto skip_bad_vf_detection;
8150
8151 pf_func = req_id & 0x01;
8152 if ((pf_func & 1) == (pdev->devfn & 1)) {
8153 unsigned int device_id;
8154
8155 vf = (req_id & 0x7F) >> 1;
8156 e_dev_err("VF %d has caused a PCIe error\n", vf);
8157 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8158 "%8.8x\tdw3: %8.8x\n",
8159 dw0, dw1, dw2, dw3);
8160 switch (adapter->hw.mac.type) {
8161 case ixgbe_mac_82599EB:
8162 device_id = IXGBE_82599_VF_DEVICE_ID;
8163 break;
8164 case ixgbe_mac_X540:
8165 device_id = IXGBE_X540_VF_DEVICE_ID;
8166 break;
8167 default:
8168 device_id = 0;
8169 break;
8170 }
8171
8172 /* Find the pci device of the offending VF */
8173 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8174 while (vfdev) {
8175 if (vfdev->devfn == (req_id & 0xFF))
8176 break;
8177 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8178 device_id, vfdev);
8179 }
8180 /*
8181 * There's a slim chance the VF could have been hot plugged,
8182 * so if it is no longer present we don't need to issue the
8183 * VFLR. Just clean up the AER in that case.
8184 */
8185 if (vfdev) {
8186 e_dev_err("Issuing VFLR to VF %d\n", vf);
8187 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8188 }
8189
8190 pci_cleanup_aer_uncorrect_error_status(pdev);
8191 }
8192
8193 /*
8194 * Even though the error may have occurred on the other port
8195 * we still need to increment the vf error reference count for
8196 * both ports because the I/O resume function will be called
8197 * for both of them.
8198 */
8199 adapter->vferr_refcount++;
8200
8201 return PCI_ERS_RESULT_RECOVERED;
8202
8203skip_bad_vf_detection:
8204#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008205 netif_device_detach(netdev);
8206
Breno Leitao3044b8d2009-05-06 10:44:26 +00008207 if (state == pci_channel_io_perm_failure)
8208 return PCI_ERS_RESULT_DISCONNECT;
8209
Auke Kok9a799d72007-09-15 14:07:45 -07008210 if (netif_running(netdev))
8211 ixgbe_down(adapter);
8212 pci_disable_device(pdev);
8213
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008214 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008215 return PCI_ERS_RESULT_NEED_RESET;
8216}
8217
8218/**
8219 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8220 * @pdev: Pointer to PCI device
8221 *
8222 * Restart the card from scratch, as if from a cold-boot.
8223 */
8224static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8225{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008226 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008227 pci_ers_result_t result;
8228 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008229
gouji-new9ce77662009-05-06 10:44:45 +00008230 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008231 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008232 result = PCI_ERS_RESULT_DISCONNECT;
8233 } else {
8234 pci_set_master(pdev);
8235 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008236 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008237
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008238 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008239
8240 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008241 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008242 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008243 }
Auke Kok9a799d72007-09-15 14:07:45 -07008244
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008245 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8246 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008247 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8248 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008249 /* non-fatal, continue */
8250 }
Auke Kok9a799d72007-09-15 14:07:45 -07008251
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008252 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008253}
8254
8255/**
8256 * ixgbe_io_resume - called when traffic can start flowing again.
8257 * @pdev: Pointer to PCI device
8258 *
8259 * This callback is called when the error recovery driver tells us that
8260 * its OK to resume normal operation.
8261 */
8262static void ixgbe_io_resume(struct pci_dev *pdev)
8263{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008264 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8265 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008266
Greg Rose83c61fa2011-09-07 05:59:35 +00008267#ifdef CONFIG_PCI_IOV
8268 if (adapter->vferr_refcount) {
8269 e_info(drv, "Resuming after VF err\n");
8270 adapter->vferr_refcount--;
8271 return;
8272 }
8273
8274#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008275 if (netif_running(netdev))
8276 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008277
8278 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008279}
8280
8281static struct pci_error_handlers ixgbe_err_handler = {
8282 .error_detected = ixgbe_io_error_detected,
8283 .slot_reset = ixgbe_io_slot_reset,
8284 .resume = ixgbe_io_resume,
8285};
8286
8287static struct pci_driver ixgbe_driver = {
8288 .name = ixgbe_driver_name,
8289 .id_table = ixgbe_pci_tbl,
8290 .probe = ixgbe_probe,
8291 .remove = __devexit_p(ixgbe_remove),
8292#ifdef CONFIG_PM
8293 .suspend = ixgbe_suspend,
8294 .resume = ixgbe_resume,
8295#endif
8296 .shutdown = ixgbe_shutdown,
8297 .err_handler = &ixgbe_err_handler
8298};
8299
8300/**
8301 * ixgbe_init_module - Driver Registration Routine
8302 *
8303 * ixgbe_init_module is the first routine called when the driver is
8304 * loaded. All it does is register with the PCI subsystem.
8305 **/
8306static int __init ixgbe_init_module(void)
8307{
8308 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008309 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008310 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008311
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008312#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008313 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008314#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008315
Auke Kok9a799d72007-09-15 14:07:45 -07008316 ret = pci_register_driver(&ixgbe_driver);
8317 return ret;
8318}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008319
Auke Kok9a799d72007-09-15 14:07:45 -07008320module_init(ixgbe_init_module);
8321
8322/**
8323 * ixgbe_exit_module - Driver Exit Cleanup Routine
8324 *
8325 * ixgbe_exit_module is called just before the driver is removed
8326 * from memory.
8327 **/
8328static void __exit ixgbe_exit_module(void)
8329{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008330#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008331 dca_unregister_notify(&dca_notifier);
8332#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008333 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008334 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008335}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008336
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008337#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008338static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008339 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008340{
8341 int ret_val;
8342
8343 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008344 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008345
8346 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8347}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008348
Alexander Duyckb4533682009-03-31 21:32:42 +00008349#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008350
Auke Kok9a799d72007-09-15 14:07:45 -07008351module_exit(ixgbe_exit_module);
8352
8353/* ixgbe_main.c */