blob: bad9c0508dfe752540e78c0717f6a761cf49c6cd [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 Skidmorefe15e8e2010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
292 struct ixgbe_tx_buffer *tx_buffer_info;
293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
332 tx_buffer_info =
333 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000334 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000335 n, tx_ring->next_to_use, tx_ring->next_to_clean,
336 (u64)tx_buffer_info->dma,
337 tx_buffer_info->length,
338 tx_buffer_info->next_to_watch,
339 (u64)tx_buffer_info->time_stamp);
340 }
341
342 /* Print TX Rings */
343 if (!netif_msg_tx_done(adapter))
344 goto rx_ring_summary;
345
346 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
347
348 /* Transmit Descriptor Formats
349 *
350 * Advanced Transmit Descriptor
351 * +--------------------------------------------------------------+
352 * 0 | Buffer Address [63:0] |
353 * +--------------------------------------------------------------+
354 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
355 * +--------------------------------------------------------------+
356 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
357 */
358
359 for (n = 0; n < adapter->num_tx_queues; n++) {
360 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("------------------------------------\n");
362 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
363 pr_info("------------------------------------\n");
364 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 "[PlPOIdStDDt Ln] [bi->dma ] "
366 "leng ntw timestamp bi->skb\n");
367
368 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000369 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 tx_buffer_info = &tx_ring->tx_buffer_info[i];
371 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000372 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000373 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000374 le64_to_cpu(u0->a),
375 le64_to_cpu(u0->b),
376 (u64)tx_buffer_info->dma,
377 tx_buffer_info->length,
378 tx_buffer_info->next_to_watch,
379 (u64)tx_buffer_info->time_stamp,
380 tx_buffer_info->skb);
381 if (i == tx_ring->next_to_use &&
382 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000383 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000385 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000386 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000387 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 else
Joe Perchesc7689572010-09-07 21:35:17 +0000389 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000390
391 if (netif_msg_pktdata(adapter) &&
392 tx_buffer_info->dma != 0)
393 print_hex_dump(KERN_INFO, "",
394 DUMP_PREFIX_ADDRESS, 16, 1,
395 phys_to_virt(tx_buffer_info->dma),
396 tx_buffer_info->length, true);
397 }
398 }
399
400 /* Print RX Rings Summary */
401rx_ring_summary:
402 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000403 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000404 for (n = 0; n < adapter->num_rx_queues; n++) {
405 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000406 pr_info("%5d %5X %5X\n",
407 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000408 }
409
410 /* Print RX Rings */
411 if (!netif_msg_rx_status(adapter))
412 goto exit;
413
414 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
415
416 /* Advanced Receive Descriptor (Read) Format
417 * 63 1 0
418 * +-----------------------------------------------------+
419 * 0 | Packet Buffer Address [63:1] |A0/NSE|
420 * +----------------------------------------------+------+
421 * 8 | Header Buffer Address [63:1] | DD |
422 * +-----------------------------------------------------+
423 *
424 *
425 * Advanced Receive Descriptor (Write-Back) Format
426 *
427 * 63 48 47 32 31 30 21 20 16 15 4 3 0
428 * +------------------------------------------------------+
429 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
430 * | Checksum Ident | | | | Type | Type |
431 * +------------------------------------------------------+
432 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
433 * +------------------------------------------------------+
434 * 63 48 47 32 31 20 19 0
435 */
436 for (n = 0; n < adapter->num_rx_queues; n++) {
437 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("------------------------------------\n");
439 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
440 pr_info("------------------------------------\n");
441 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
443 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000444 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445 "[vl er S cks ln] ---------------- [bi->skb] "
446 "<-- Adv Rx Write-Back format\n");
447
448 for (i = 0; i < rx_ring->count; i++) {
449 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000450 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000451 u0 = (struct my_u0 *)rx_desc;
452 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
453 if (staterr & IXGBE_RXD_STAT_DD) {
454 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000455 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 "%016llX ---------------- %p", i,
457 le64_to_cpu(u0->a),
458 le64_to_cpu(u0->b),
459 rx_buffer_info->skb);
460 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000461 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462 "%016llX %016llX %p", i,
463 le64_to_cpu(u0->a),
464 le64_to_cpu(u0->b),
465 (u64)rx_buffer_info->dma,
466 rx_buffer_info->skb);
467
468 if (netif_msg_pktdata(adapter)) {
469 print_hex_dump(KERN_INFO, "",
470 DUMP_PREFIX_ADDRESS, 16, 1,
471 phys_to_virt(rx_buffer_info->dma),
472 rx_ring->rx_buf_len, true);
473
474 if (rx_ring->rx_buf_len
Alexander Duyck919e78a2011-08-26 09:52:38 +0000475 < IXGBE_RXBUFFER_2K)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000476 print_hex_dump(KERN_INFO, "",
477 DUMP_PREFIX_ADDRESS, 16, 1,
478 phys_to_virt(
479 rx_buffer_info->page_dma +
480 rx_buffer_info->page_offset
481 ),
482 PAGE_SIZE/2, true);
483 }
484 }
485
486 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000488 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000489 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000490 else
Joe Perchesc7689572010-09-07 21:35:17 +0000491 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000492
493 }
494 }
495
496exit:
497 return;
498}
499
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800500static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
501{
502 u32 ctrl_ext;
503
504 /* Let firmware take over control of h/w */
505 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000507 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800508}
509
510static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
511{
512 u32 ctrl_ext;
513
514 /* Let firmware know the driver has taken over */
515 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
516 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000517 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800518}
Auke Kok9a799d72007-09-15 14:07:45 -0700519
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000520/*
521 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
522 * @adapter: pointer to adapter struct
523 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
524 * @queue: queue to map the corresponding interrupt to
525 * @msix_vector: the vector to map to the corresponding queue
526 *
527 */
528static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000529 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700530{
531 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000532 struct ixgbe_hw *hw = &adapter->hw;
533 switch (hw->mac.type) {
534 case ixgbe_mac_82598EB:
535 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
536 if (direction == -1)
537 direction = 0;
538 index = (((direction * 64) + queue) >> 2) & 0x1F;
539 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
540 ivar &= ~(0xFF << (8 * (queue & 0x3)));
541 ivar |= (msix_vector << (8 * (queue & 0x3)));
542 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
543 break;
544 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800545 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000546 if (direction == -1) {
547 /* other causes */
548 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
549 index = ((queue & 1) * 8);
550 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
551 ivar &= ~(0xFF << index);
552 ivar |= (msix_vector << index);
553 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
554 break;
555 } else {
556 /* tx or rx causes */
557 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
558 index = ((16 * (queue & 1)) + (8 * direction));
559 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
560 ivar &= ~(0xFF << index);
561 ivar |= (msix_vector << index);
562 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
563 break;
564 }
565 default:
566 break;
567 }
Auke Kok9a799d72007-09-15 14:07:45 -0700568}
569
Alexander Duyckfe49f042009-06-04 16:00:09 +0000570static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572{
573 u32 mask;
574
Alexander Duyckbd508172010-11-16 19:27:03 -0800575 switch (adapter->hw.mac.type) {
576 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000577 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
578 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800579 break;
580 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800581 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000582 mask = (qmask & 0xFFFFFFFF);
583 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
584 mask = (qmask >> 32);
585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800586 break;
587 default:
588 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000589 }
590}
591
Alexander Duyckd3d00232011-07-15 02:31:25 +0000592static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
593 struct ixgbe_tx_buffer *tx_buffer)
594{
595 if (tx_buffer->dma) {
596 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
597 dma_unmap_page(ring->dev,
598 tx_buffer->dma,
599 tx_buffer->length,
600 DMA_TO_DEVICE);
601 else
602 dma_unmap_single(ring->dev,
603 tx_buffer->dma,
604 tx_buffer->length,
605 DMA_TO_DEVICE);
606 }
607 tx_buffer->dma = 0;
608}
609
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800610void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
611 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700612{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000613 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
614 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700615 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000616 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700617 /* tx_buffer_info must be completely set up in the transmit path */
618}
619
John Fastabendc84d3242010-11-16 19:27:12 -0800620static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700621{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700622 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800623 struct ixgbe_hw_stats *hwstats = &adapter->stats;
624 u32 data = 0;
625 u32 xoff[8] = {0};
626 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700627
John Fastabendc84d3242010-11-16 19:27:12 -0800628 if ((hw->fc.current_mode == ixgbe_fc_full) ||
629 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
630 switch (hw->mac.type) {
631 case ixgbe_mac_82598EB:
632 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
633 break;
634 default:
635 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
636 }
637 hwstats->lxoffrxc += data;
638
639 /* refill credits (no tx hang) if we received xoff */
640 if (!data)
641 return;
642
643 for (i = 0; i < adapter->num_tx_queues; i++)
644 clear_bit(__IXGBE_HANG_CHECK_ARMED,
645 &adapter->tx_ring[i]->state);
646 return;
647 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
648 return;
649
650 /* update stats for each tc, only valid with PFC enabled */
651 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
652 switch (hw->mac.type) {
653 case ixgbe_mac_82598EB:
654 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
655 break;
656 default:
657 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
658 }
659 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700660 }
661
John Fastabendc84d3242010-11-16 19:27:12 -0800662 /* disarm tx queues that have received xoff frames */
663 for (i = 0; i < adapter->num_tx_queues; i++) {
664 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000665 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800666
667 if (xoff[tc])
668 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
669 }
670}
671
672static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
673{
674 return ring->tx_stats.completed;
675}
676
677static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
678{
679 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
680 struct ixgbe_hw *hw = &adapter->hw;
681
682 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
683 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
684
685 if (head != tail)
686 return (head < tail) ?
687 tail - head : (tail + ring->count - head);
688
689 return 0;
690}
691
692static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
693{
694 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
695 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
696 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
697 bool ret = false;
698
699 clear_check_for_tx_hang(tx_ring);
700
701 /*
702 * Check for a hung queue, but be thorough. This verifies
703 * that a transmit has been completed since the previous
704 * check AND there is at least one packet pending. The
705 * ARMED bit is set to indicate a potential hang. The
706 * bit is cleared if a pause frame is received to remove
707 * false hang detection due to PFC or 802.3x frames. By
708 * requiring this to fail twice we avoid races with
709 * pfc clearing the ARMED bit and conditions where we
710 * run the check_tx_hang logic with a transmit completion
711 * pending but without time to complete it yet.
712 */
713 if ((tx_done_old == tx_done) && tx_pending) {
714 /* make sure it is true for two checks in a row */
715 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
716 &tx_ring->state);
717 } else {
718 /* update completed stats and continue */
719 tx_ring->tx_stats.tx_done_old = tx_done;
720 /* reset the countdown */
721 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
722 }
723
724 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700725}
726
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000727/**
728 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
729 * @adapter: driver private struct
730 **/
731static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
732{
733
734 /* Do the reset outside of interrupt context */
735 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
736 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
737 ixgbe_service_event_schedule(adapter);
738 }
739}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700740
Auke Kok9a799d72007-09-15 14:07:45 -0700741/**
742 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000743 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700744 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700745 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000746static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000747 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700748{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000749 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000750 struct ixgbe_tx_buffer *tx_buffer;
751 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700752 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000753 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000754 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700755
Alexander Duyckd3d00232011-07-15 02:31:25 +0000756 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000757 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800758
Alexander Duyck30065e62011-07-15 03:05:14 +0000759 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000760 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700761
Alexander Duyckd3d00232011-07-15 02:31:25 +0000762 /* if next_to_watch is not set then there is no work pending */
763 if (!eop_desc)
764 break;
765
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000766 /* prevent any other reads prior to eop_desc */
767 rmb();
768
Alexander Duyckd3d00232011-07-15 02:31:25 +0000769 /* if DD is not set pending work has not been completed */
770 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
771 break;
772
773 /* count the packet as being completed */
774 tx_ring->tx_stats.completed++;
775
776 /* clear next_to_watch to prevent false hangs */
777 tx_buffer->next_to_watch = NULL;
778
Alexander Duyckd3d00232011-07-15 02:31:25 +0000779 do {
780 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000781 if (likely(tx_desc == eop_desc)) {
782 eop_desc = NULL;
783 dev_kfree_skb_any(tx_buffer->skb);
784 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800785
Alexander Duyckd3d00232011-07-15 02:31:25 +0000786 total_bytes += tx_buffer->bytecount;
787 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800788 }
789
Alexander Duyckd3d00232011-07-15 02:31:25 +0000790 tx_buffer++;
791 tx_desc++;
792 i++;
793 if (unlikely(i == tx_ring->count)) {
794 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700795
Alexander Duyckd3d00232011-07-15 02:31:25 +0000796 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000797 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000798 }
799
800 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800801 }
802
Auke Kok9a799d72007-09-15 14:07:45 -0700803 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000804 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800805 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000806 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000807 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000808 q_vector->tx.total_bytes += total_bytes;
809 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800810
John Fastabendc84d3242010-11-16 19:27:12 -0800811 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800812 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800813 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycke4f74022012-01-31 02:59:44 +0000814 tx_desc = IXGBE_TX_DESC(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800815 e_err(drv, "Detected Tx Unit Hang\n"
816 " Tx Queue <%d>\n"
817 " TDH, TDT <%x>, <%x>\n"
818 " next_to_use <%x>\n"
819 " next_to_clean <%x>\n"
820 "tx_buffer_info[next_to_clean]\n"
821 " time_stamp <%lx>\n"
822 " jiffies <%lx>\n",
823 tx_ring->queue_index,
824 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
825 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000826 tx_ring->next_to_use, i,
827 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800828
829 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
830
831 e_info(probe,
832 "tx hang %d detected on queue %d, resetting adapter\n",
833 adapter->tx_timeout_count + 1, tx_ring->queue_index);
834
835 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000836 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800837
838 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000839 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800840 }
Auke Kok9a799d72007-09-15 14:07:45 -0700841
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000842 netdev_tx_completed_queue(txring_txq(tx_ring),
843 total_packets, total_bytes);
844
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800845#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000846 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000847 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800848 /* Make sure that anybody stopping the queue after this
849 * sees the new next_to_clean.
850 */
851 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800852 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800853 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800854 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800855 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800856 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800857 }
Auke Kok9a799d72007-09-15 14:07:45 -0700858
Alexander Duyck59224552011-08-31 00:01:06 +0000859 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700860}
861
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400862#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800863static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800864 struct ixgbe_ring *rx_ring,
865 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800866{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800867 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800868 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800869 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800870
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800871 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
872 switch (hw->mac.type) {
873 case ixgbe_mac_82598EB:
874 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000875 rxctrl |= dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800876 break;
877 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800878 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800879 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000880 rxctrl |= (dca3_get_tag(rx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800881 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
882 break;
883 default:
884 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800885 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800886 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
887 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
888 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800889 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800890}
891
892static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800893 struct ixgbe_ring *tx_ring,
894 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800895{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000896 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800897 u32 txctrl;
898 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800899
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800900 switch (hw->mac.type) {
901 case ixgbe_mac_82598EB:
902 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
903 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000904 txctrl |= dca3_get_tag(tx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800905 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800906 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
907 break;
908 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800909 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800910 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
911 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000912 txctrl |= (dca3_get_tag(tx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800913 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
914 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800915 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
916 break;
917 default:
918 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800919 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800920}
921
922static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
923{
924 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000925 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800926 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800927
928 if (q_vector->cpu == cpu)
929 goto out_no_update;
930
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000931 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
932 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800933
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000934 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
935 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800936
937 q_vector->cpu = cpu;
938out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800939 put_cpu();
940}
941
942static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
943{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800944 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800945 int i;
946
947 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
948 return;
949
Alexander Duycke35ec122009-05-21 13:07:12 +0000950 /* always use CB2 mode, difference is masked in the CB driver */
951 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
952
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800953 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
954 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
955 else
956 num_q_vectors = 1;
957
958 for (i = 0; i < num_q_vectors; i++) {
959 adapter->q_vector[i]->cpu = -1;
960 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800961 }
962}
963
964static int __ixgbe_notify_dca(struct device *dev, void *data)
965{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800966 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800967 unsigned long event = *(unsigned long *)data;
968
Don Skidmore2a72c312011-07-20 02:27:05 +0000969 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800970 return 0;
971
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800972 switch (event) {
973 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700974 /* if we're already enabled, don't do it again */
975 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
976 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300977 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700978 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800979 ixgbe_setup_dca(adapter);
980 break;
981 }
982 /* Fall Through since DCA is disabled. */
983 case DCA_PROVIDER_REMOVE:
984 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
985 dca_remove_requester(dev);
986 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
987 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
988 }
989 break;
990 }
991
Denis V. Lunev652f0932008-03-27 14:39:17 +0300992 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800993}
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400994#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000995
Alexander Duyck8a0da212012-01-31 02:59:49 +0000996static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
997 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000998 struct sk_buff *skb)
999{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001000 if (ring->netdev->features & NETIF_F_RXHASH)
1001 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001002}
1003
Auke Kok9a799d72007-09-15 14:07:45 -07001004/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001005 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1006 * @adapter: address of board private structure
1007 * @rx_desc: advanced rx descriptor
1008 *
1009 * Returns : true if it is FCoE pkt
1010 */
1011static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1012 union ixgbe_adv_rx_desc *rx_desc)
1013{
1014 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1015
1016 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1017 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1018 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1019 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1020}
1021
1022/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001023 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001024 * @ring: structure containing ring specific data
1025 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001026 * @skb: skb currently being received and modified
1027 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001028static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001029 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001030 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001031{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001032 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001033
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001034 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001035 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001036 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001037
1038 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001039 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1040 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001041 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001042 return;
1043 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001044
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001045 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001046 return;
1047
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001048 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001049 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1050
1051 /*
1052 * 82599 errata, UDP frames with a 0 checksum can be marked as
1053 * checksum errors.
1054 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001055 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1056 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001057 return;
1058
Alexander Duyck8a0da212012-01-31 02:59:49 +00001059 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001060 return;
1061 }
1062
Auke Kok9a799d72007-09-15 14:07:45 -07001063 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001064 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001065}
1066
Alexander Duyck84ea2592010-11-16 19:26:49 -08001067static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001068{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001069 rx_ring->next_to_use = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001070 /*
1071 * Force memory writes to complete before letting h/w
1072 * know there are new descriptors to fetch. (Only
1073 * applicable for weak-ordered memory model archs,
1074 * such as IA-64).
1075 */
1076 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001077 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001078}
1079
Alexander Duyckf990b792012-01-31 02:59:34 +00001080static bool ixgbe_alloc_mapped_skb(struct ixgbe_ring *rx_ring,
1081 struct ixgbe_rx_buffer *bi)
1082{
1083 struct sk_buff *skb = bi->skb;
1084 dma_addr_t dma = bi->dma;
1085
1086 if (dma)
1087 return true;
1088
1089 if (likely(!skb)) {
1090 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1091 rx_ring->rx_buf_len);
1092 bi->skb = skb;
1093 if (!skb) {
1094 rx_ring->rx_stats.alloc_rx_buff_failed++;
1095 return false;
1096 }
Alexander Duyckf990b792012-01-31 02:59:34 +00001097 }
1098
1099 dma = dma_map_single(rx_ring->dev, skb->data,
1100 rx_ring->rx_buf_len, DMA_FROM_DEVICE);
1101
1102 if (dma_mapping_error(rx_ring->dev, dma)) {
1103 rx_ring->rx_stats.alloc_rx_buff_failed++;
1104 return false;
1105 }
1106
1107 bi->dma = dma;
1108 return true;
1109}
1110
1111static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1112 struct ixgbe_rx_buffer *bi)
1113{
1114 struct page *page = bi->page;
1115 dma_addr_t page_dma = bi->page_dma;
1116 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
1117
1118 if (page_dma)
1119 return true;
1120
1121 if (!page) {
1122 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1123 bi->page = page;
1124 if (unlikely(!page)) {
1125 rx_ring->rx_stats.alloc_rx_page_failed++;
1126 return false;
1127 }
1128 }
1129
1130 page_dma = dma_map_page(rx_ring->dev, page,
1131 page_offset, PAGE_SIZE / 2,
1132 DMA_FROM_DEVICE);
1133
1134 if (dma_mapping_error(rx_ring->dev, page_dma)) {
1135 rx_ring->rx_stats.alloc_rx_page_failed++;
1136 return false;
1137 }
1138
1139 bi->page_dma = page_dma;
1140 bi->page_offset = page_offset;
1141 return true;
1142}
1143
Auke Kok9a799d72007-09-15 14:07:45 -07001144/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001145 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001146 * @rx_ring: ring to place buffers on
1147 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001148 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001149void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001150{
Auke Kok9a799d72007-09-15 14:07:45 -07001151 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001152 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001153 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001154
Alexander Duyckf990b792012-01-31 02:59:34 +00001155 /* nothing to do or no valid netdev defined */
1156 if (!cleaned_count || !rx_ring->netdev)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001157 return;
1158
Alexander Duycke4f74022012-01-31 02:59:44 +00001159 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001160 bi = &rx_ring->rx_buffer_info[i];
1161 i -= rx_ring->count;
1162
Auke Kok9a799d72007-09-15 14:07:45 -07001163 while (cleaned_count--) {
Alexander Duyckf990b792012-01-31 02:59:34 +00001164 if (!ixgbe_alloc_mapped_skb(rx_ring, bi))
1165 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001166
Alexander Duyckf990b792012-01-31 02:59:34 +00001167 /* Refresh the desc even if buffer_addrs didn't change
1168 * because each write-back erases this info. */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001169 if (ring_is_ps_enabled(rx_ring)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001170 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Alexander Duyckf990b792012-01-31 02:59:34 +00001171
1172 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1173 break;
1174
1175 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001176 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001177 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001178 }
1179
Alexander Duyckf990b792012-01-31 02:59:34 +00001180 rx_desc++;
1181 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001182 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001183 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001184 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001185 bi = rx_ring->rx_buffer_info;
1186 i -= rx_ring->count;
1187 }
1188
1189 /* clear the hdr_addr for the next_to_use descriptor */
1190 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001191 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001192
Alexander Duyckf990b792012-01-31 02:59:34 +00001193 i += rx_ring->count;
1194
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001195 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001196 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001197}
1198
Alexander Duyckc267fc12010-11-16 19:27:00 -08001199static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001200{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001201 /* HW will not DMA in data larger than the given buffer, even if it
1202 * parses the (NFS, of course) header to be larger. In that case, it
1203 * fills the header buffer and spills the rest into the page.
1204 */
1205 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1206 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1207 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1208 if (hlen > IXGBE_RX_HDR_SIZE)
1209 hlen = IXGBE_RX_HDR_SIZE;
1210 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001211}
1212
Alexander Duyckf8212f92009-04-27 22:42:37 +00001213/**
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001214 * ixgbe_merge_active_tail - merge active tail into lro skb
1215 * @tail: pointer to active tail in frag_list
Alexander Duyckf8212f92009-04-27 22:42:37 +00001216 *
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001217 * This function merges the length and data of an active tail into the
1218 * skb containing the frag_list. It resets the tail's pointer to the head,
1219 * but it leaves the heads pointer to tail intact.
Alexander Duyckf8212f92009-04-27 22:42:37 +00001220 **/
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001221static inline struct sk_buff *ixgbe_merge_active_tail(struct sk_buff *tail)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001222{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001223 struct sk_buff *head = IXGBE_CB(tail)->head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001224
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001225 if (!head)
1226 return tail;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001227
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001228 head->len += tail->len;
1229 head->data_len += tail->len;
1230 head->truesize += tail->len;
Alexander Duyckaa801752010-11-16 19:27:02 -08001231
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001232 IXGBE_CB(tail)->head = NULL;
1233
1234 return head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001235}
1236
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001237/**
1238 * ixgbe_add_active_tail - adds an active tail into the skb frag_list
1239 * @head: pointer to the start of the skb
1240 * @tail: pointer to active tail to add to frag_list
1241 *
1242 * This function adds an active tail to the end of the frag list. This tail
1243 * will still be receiving data so we cannot yet ad it's stats to the main
1244 * skb. That is done via ixgbe_merge_active_tail.
1245 **/
1246static inline void ixgbe_add_active_tail(struct sk_buff *head,
1247 struct sk_buff *tail)
Alexander Duyckaa801752010-11-16 19:27:02 -08001248{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001249 struct sk_buff *old_tail = IXGBE_CB(head)->tail;
1250
1251 if (old_tail) {
1252 ixgbe_merge_active_tail(old_tail);
1253 old_tail->next = tail;
1254 } else {
1255 skb_shinfo(head)->frag_list = tail;
1256 }
1257
1258 IXGBE_CB(tail)->head = head;
1259 IXGBE_CB(head)->tail = tail;
1260}
1261
1262/**
1263 * ixgbe_close_active_frag_list - cleanup pointers on a frag_list skb
1264 * @head: pointer to head of an active frag list
1265 *
1266 * This function will clear the frag_tail_tracker pointer on an active
1267 * frag_list and returns true if the pointer was actually set
1268 **/
1269static inline bool ixgbe_close_active_frag_list(struct sk_buff *head)
1270{
1271 struct sk_buff *tail = IXGBE_CB(head)->tail;
1272
1273 if (!tail)
1274 return false;
1275
1276 ixgbe_merge_active_tail(tail);
1277
1278 IXGBE_CB(head)->tail = NULL;
1279
1280 return true;
1281}
1282
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001283/**
1284 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1285 * @data: pointer to the start of the headers
1286 * @max_len: total length of section to find headers in
1287 *
1288 * This function is meant to determine the length of headers that will
1289 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1290 * motivation of doing this is to only perform one pull for IPv4 TCP
1291 * packets so that we can do basic things like calculating the gso_size
1292 * based on the average data per packet.
1293 **/
1294static unsigned int ixgbe_get_headlen(unsigned char *data,
1295 unsigned int max_len)
1296{
1297 union {
1298 unsigned char *network;
1299 /* l2 headers */
1300 struct ethhdr *eth;
1301 struct vlan_hdr *vlan;
1302 /* l3 headers */
1303 struct iphdr *ipv4;
1304 } hdr;
1305 __be16 protocol;
1306 u8 nexthdr = 0; /* default to not TCP */
1307 u8 hlen;
1308
1309 /* this should never happen, but better safe than sorry */
1310 if (max_len < ETH_HLEN)
1311 return max_len;
1312
1313 /* initialize network frame pointer */
1314 hdr.network = data;
1315
1316 /* set first protocol and move network header forward */
1317 protocol = hdr.eth->h_proto;
1318 hdr.network += ETH_HLEN;
1319
1320 /* handle any vlan tag if present */
1321 if (protocol == __constant_htons(ETH_P_8021Q)) {
1322 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1323 return max_len;
1324
1325 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1326 hdr.network += VLAN_HLEN;
1327 }
1328
1329 /* handle L3 protocols */
1330 if (protocol == __constant_htons(ETH_P_IP)) {
1331 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1332 return max_len;
1333
1334 /* access ihl as a u8 to avoid unaligned access on ia64 */
1335 hlen = (hdr.network[0] & 0x0F) << 2;
1336
1337 /* verify hlen meets minimum size requirements */
1338 if (hlen < sizeof(struct iphdr))
1339 return hdr.network - data;
1340
1341 /* record next protocol */
1342 nexthdr = hdr.ipv4->protocol;
1343 hdr.network += hlen;
1344#ifdef CONFIG_FCOE
1345 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1346 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1347 return max_len;
1348 hdr.network += FCOE_HEADER_LEN;
1349#endif
1350 } else {
1351 return hdr.network - data;
1352 }
1353
1354 /* finally sort out TCP */
1355 if (nexthdr == IPPROTO_TCP) {
1356 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1357 return max_len;
1358
1359 /* access doff as a u8 to avoid unaligned access on ia64 */
1360 hlen = (hdr.network[12] & 0xF0) >> 2;
1361
1362 /* verify hlen meets minimum size requirements */
1363 if (hlen < sizeof(struct tcphdr))
1364 return hdr.network - data;
1365
1366 hdr.network += hlen;
1367 }
1368
1369 /*
1370 * If everything has gone correctly hdr.network should be the
1371 * data section of the packet and will be the end of the header.
1372 * If not then it probably represents the end of the last recognized
1373 * header.
1374 */
1375 if ((hdr.network - data) < max_len)
1376 return hdr.network - data;
1377 else
1378 return max_len;
1379}
1380
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001381static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1382 union ixgbe_adv_rx_desc *rx_desc,
1383 struct sk_buff *skb)
1384{
1385 __le32 rsc_enabled;
1386 u32 rsc_cnt;
1387
1388 if (!ring_is_rsc_enabled(rx_ring))
1389 return;
1390
1391 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1392 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1393
1394 /* If this is an RSC frame rsc_cnt should be non-zero */
1395 if (!rsc_enabled)
1396 return;
1397
1398 rsc_cnt = le32_to_cpu(rsc_enabled);
1399 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1400
1401 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001402}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001403
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001404static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1405 struct sk_buff *skb)
1406{
1407 u16 hdr_len = ixgbe_get_headlen(skb->data, skb_headlen(skb));
1408
1409 /* set gso_size to avoid messing up TCP MSS */
1410 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1411 IXGBE_CB(skb)->append_cnt);
1412}
1413
1414static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1415 struct sk_buff *skb)
1416{
1417 /* if append_cnt is 0 then frame is not RSC */
1418 if (!IXGBE_CB(skb)->append_cnt)
1419 return;
1420
1421 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1422 rx_ring->rx_stats.rsc_flush++;
1423
1424 ixgbe_set_rsc_gso_size(rx_ring, skb);
1425
1426 /* gso_size is computed using append_cnt so always clear it last */
1427 IXGBE_CB(skb)->append_cnt = 0;
1428}
1429
Alexander Duyck8a0da212012-01-31 02:59:49 +00001430/**
1431 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1432 * @rx_ring: rx descriptor ring packet is being transacted on
1433 * @rx_desc: pointer to the EOP Rx descriptor
1434 * @skb: pointer to current skb being populated
1435 *
1436 * This function checks the ring, descriptor, and packet information in
1437 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1438 * other fields within the skb.
1439 **/
1440static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1441 union ixgbe_adv_rx_desc *rx_desc,
1442 struct sk_buff *skb)
1443{
1444 ixgbe_update_rsc_stats(rx_ring, skb);
1445
1446 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1447
1448 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1449
1450 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1451 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1452 __vlan_hwaccel_put_tag(skb, vid);
1453 }
1454
1455 skb_record_rx_queue(skb, rx_ring->queue_index);
1456
1457 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1458}
1459
1460static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1461 struct sk_buff *skb)
1462{
1463 struct ixgbe_adapter *adapter = q_vector->adapter;
1464
1465 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1466 napi_gro_receive(&q_vector->napi, skb);
1467 else
1468 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001469}
1470
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001471static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001472 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001473 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001474{
Auke Kok9a799d72007-09-15 14:07:45 -07001475 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001476 struct ixgbe_rx_buffer *rx_buffer_info;
Auke Kok9a799d72007-09-15 14:07:45 -07001477 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001478 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001479 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001480#ifdef IXGBE_FCOE
Alexander Duyck8a0da212012-01-31 02:59:49 +00001481 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001482 int ddp_bytes = 0;
1483#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001484 u16 i;
1485 u16 cleaned_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001486
1487 i = rx_ring->next_to_clean;
Alexander Duycke4f74022012-01-31 02:59:44 +00001488 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001489
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001490 while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001491 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001492
Milton Miller3c945e52010-02-19 17:44:42 +00001493 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Alexander Duyckc267fc12010-11-16 19:27:00 -08001495 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1496
Auke Kok9a799d72007-09-15 14:07:45 -07001497 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001498 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001499 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001500
David S. Miller8decf862011-09-22 03:23:13 -04001501 /* linear means we are building an skb from multiple pages */
1502 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001503 u16 hlen;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001504 if (ring_is_ps_enabled(rx_ring)) {
1505 hlen = ixgbe_get_hlen(rx_desc);
1506 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1507 } else {
1508 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1509 }
1510
1511 skb_put(skb, hlen);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001512
1513 /*
1514 * Delay unmapping of the first packet. It carries the
1515 * header information, HW may still access the header
1516 * after writeback. Only unmap it when EOP is reached
1517 */
1518 if (!IXGBE_CB(skb)->head) {
1519 IXGBE_CB(skb)->delay_unmap = true;
1520 IXGBE_CB(skb)->dma = rx_buffer_info->dma;
1521 } else {
1522 skb = ixgbe_merge_active_tail(skb);
1523 dma_unmap_single(rx_ring->dev,
1524 rx_buffer_info->dma,
1525 rx_ring->rx_buf_len,
1526 DMA_FROM_DEVICE);
1527 }
1528 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001529 } else {
1530 /* assume packet split since header is unmapped */
1531 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001532 }
1533
1534 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001535 dma_unmap_page(rx_ring->dev,
1536 rx_buffer_info->page_dma,
1537 PAGE_SIZE / 2,
1538 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001539 rx_buffer_info->page_dma = 0;
1540 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001541 rx_buffer_info->page,
1542 rx_buffer_info->page_offset,
1543 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001544
Alexander Duyckc267fc12010-11-16 19:27:00 -08001545 if ((page_count(rx_buffer_info->page) == 1) &&
1546 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001547 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001548 else
1549 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001550
1551 skb->len += upper_len;
1552 skb->data_len += upper_len;
Eric Dumazet98130642011-10-13 07:59:41 +00001553 skb->truesize += PAGE_SIZE / 2;
Auke Kok9a799d72007-09-15 14:07:45 -07001554 }
1555
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001556 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1557
Auke Kok9a799d72007-09-15 14:07:45 -07001558 i++;
1559 if (i == rx_ring->count)
1560 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001561
Alexander Duycke4f74022012-01-31 02:59:44 +00001562 next_rxd = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001563 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001564 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001565
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001566 if ((!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001567 struct ixgbe_rx_buffer *next_buffer;
1568 u32 nextp;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001569
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001570 if (IXGBE_CB(skb)->append_cnt) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001571 nextp = le32_to_cpu(
1572 rx_desc->wb.upper.status_error);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001573 nextp >>= IXGBE_RXDADV_NEXTP_SHIFT;
1574 } else {
1575 nextp = i;
1576 }
1577
1578 next_buffer = &rx_ring->rx_buffer_info[nextp];
1579
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001580 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001581 rx_buffer_info->skb = next_buffer->skb;
1582 rx_buffer_info->dma = next_buffer->dma;
1583 next_buffer->skb = skb;
1584 next_buffer->dma = 0;
1585 } else {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001586 struct sk_buff *next_skb = next_buffer->skb;
1587 ixgbe_add_active_tail(skb, next_skb);
1588 IXGBE_CB(next_skb)->head = skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001589 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001590 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001591 goto next_desc;
1592 }
1593
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001594 dma_unmap_single(rx_ring->dev,
1595 IXGBE_CB(skb)->dma,
1596 rx_ring->rx_buf_len,
1597 DMA_FROM_DEVICE);
1598 IXGBE_CB(skb)->dma = 0;
1599 IXGBE_CB(skb)->delay_unmap = false;
1600
1601 if (ixgbe_close_active_frag_list(skb) &&
1602 !IXGBE_CB(skb)->append_cnt) {
Alexander Duyckaa801752010-11-16 19:27:02 -08001603 /* if we got here without RSC the packet is invalid */
Alexander Duyckff886df2011-06-11 01:45:13 +00001604 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001605 goto next_desc;
1606 }
1607
Auke Kok9a799d72007-09-15 14:07:45 -07001608 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001609 if (unlikely(ixgbe_test_staterr(rx_desc,
1610 IXGBE_RXDADV_ERR_FRAME_ERR_MASK))) {
Auke Kok9a799d72007-09-15 14:07:45 -07001611 dev_kfree_skb_any(skb);
1612 goto next_desc;
1613 }
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001614
1615 /* probably a little skewed due to removing CRC */
1616 total_rx_bytes += skb->len;
1617 total_rx_packets++;
1618
Alexander Duyck8a0da212012-01-31 02:59:49 +00001619 /* populate checksum, timestamp, VLAN, and protocol */
1620 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1621
Yi Zou332d4a72009-05-13 13:11:53 +00001622#ifdef IXGBE_FCOE
1623 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001624 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001625 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001626 if (!ddp_bytes) {
1627 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001628 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001629 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001630 }
Yi Zou332d4a72009-05-13 13:11:53 +00001631#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001632 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001633
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001634 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001635next_desc:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001636 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001637 break;
1638
Auke Kok9a799d72007-09-15 14:07:45 -07001639 /* return some buffers to hardware, one at a time is too slow */
1640 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001641 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001642 cleaned_count = 0;
1643 }
1644
1645 /* use prefetched values */
1646 rx_desc = next_rxd;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001647 }
1648
Auke Kok9a799d72007-09-15 14:07:45 -07001649 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001650 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001651
1652 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001653 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001654
Yi Zou3d8fd382009-06-08 14:38:44 +00001655#ifdef IXGBE_FCOE
1656 /* include DDPed FCoE data */
1657 if (ddp_bytes > 0) {
1658 unsigned int mss;
1659
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001660 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001661 sizeof(struct fc_frame_header) -
1662 sizeof(struct fcoe_crc_eof);
1663 if (mss > 512)
1664 mss &= ~511;
1665 total_rx_bytes += ddp_bytes;
1666 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1667 }
1668#endif /* IXGBE_FCOE */
1669
Alexander Duyckc267fc12010-11-16 19:27:00 -08001670 u64_stats_update_begin(&rx_ring->syncp);
1671 rx_ring->stats.packets += total_rx_packets;
1672 rx_ring->stats.bytes += total_rx_bytes;
1673 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001674 q_vector->rx.total_packets += total_rx_packets;
1675 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001676
1677 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001678}
1679
Auke Kok9a799d72007-09-15 14:07:45 -07001680/**
1681 * ixgbe_configure_msix - Configure MSI-X hardware
1682 * @adapter: board private structure
1683 *
1684 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1685 * interrupts.
1686 **/
1687static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1688{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001689 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001690 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001691 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001692
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001693 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1694
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001695 /* Populate MSIX to EITR Select */
1696 if (adapter->num_vfs > 32) {
1697 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1698 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1699 }
1700
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001701 /*
1702 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001703 * corresponding register.
1704 */
1705 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001706 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001707 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001708
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001709 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1710 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001711
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001712 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1713 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001714
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001715 if (q_vector->tx.ring && !q_vector->rx.ring) {
1716 /* tx only vector */
1717 if (adapter->tx_itr_setting == 1)
1718 q_vector->itr = IXGBE_10K_ITR;
1719 else
1720 q_vector->itr = adapter->tx_itr_setting;
1721 } else {
1722 /* rx or rx/tx vector */
1723 if (adapter->rx_itr_setting == 1)
1724 q_vector->itr = IXGBE_20K_ITR;
1725 else
1726 q_vector->itr = adapter->rx_itr_setting;
1727 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001728
Alexander Duyckfe49f042009-06-04 16:00:09 +00001729 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001730 }
1731
Alexander Duyckbd508172010-11-16 19:27:03 -08001732 switch (adapter->hw.mac.type) {
1733 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001734 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001735 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001736 break;
1737 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001738 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001739 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001740 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001741 default:
1742 break;
1743 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001744 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001745
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001746 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001747 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001748 mask &= ~(IXGBE_EIMS_OTHER |
1749 IXGBE_EIMS_MAILBOX |
1750 IXGBE_EIMS_LSC);
1751
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001752 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001753}
1754
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001755enum latency_range {
1756 lowest_latency = 0,
1757 low_latency = 1,
1758 bulk_latency = 2,
1759 latency_invalid = 255
1760};
1761
1762/**
1763 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001764 * @q_vector: structure containing interrupt and ring information
1765 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001766 *
1767 * Stores a new ITR value based on packets and byte
1768 * counts during the last interrupt. The advantage of per interrupt
1769 * computation is faster updates and more accurate ITR for the current
1770 * traffic pattern. Constants in this function were computed
1771 * based on theoretical maximum wire speed and thresholds were set based
1772 * on testing data as well as attempting to minimize response time
1773 * while increasing bulk throughput.
1774 * this functionality is controlled by the InterruptThrottleRate module
1775 * parameter (see ixgbe_param.c)
1776 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001777static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1778 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001779{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001780 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001781 struct ixgbe_adapter *adapter = q_vector->adapter;
1782 int bytes = ring_container->total_bytes;
1783 int packets = ring_container->total_packets;
1784 u32 timepassed_us;
1785 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001786
1787 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001788 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001789
1790 /* simple throttlerate management
1791 * 0-20MB/s lowest (100000 ints/s)
1792 * 20-100MB/s low (20000 ints/s)
1793 * 100-1249MB/s bulk (8000 ints/s)
1794 */
1795 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001796 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001797 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1798
1799 switch (itr_setting) {
1800 case lowest_latency:
1801 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001802 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001803 break;
1804 case low_latency:
1805 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001806 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001807 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001808 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001809 break;
1810 case bulk_latency:
1811 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001812 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001813 break;
1814 }
1815
Alexander Duyckbd198052011-06-11 01:45:08 +00001816 /* clear work counters since we have the values we need */
1817 ring_container->total_bytes = 0;
1818 ring_container->total_packets = 0;
1819
1820 /* write updated itr to ring container */
1821 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001822}
1823
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001824/**
1825 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001826 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001827 *
1828 * This function is made to be called by ethtool and by the driver
1829 * when it needs to update EITR registers at runtime. Hardware
1830 * specific quirks/differences are taken care of here.
1831 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001832void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001833{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001834 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001835 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001836 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001837 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001838
Alexander Duyckbd508172010-11-16 19:27:03 -08001839 switch (adapter->hw.mac.type) {
1840 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001841 /* must write high and low 16 bits to reset counter */
1842 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001843 break;
1844 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001845 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001846 /*
1847 * set the WDIS bit to not clear the timer bits and cause an
1848 * immediate assertion of the interrupt
1849 */
1850 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001851 break;
1852 default:
1853 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001854 }
1855 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1856}
1857
Alexander Duyckbd198052011-06-11 01:45:08 +00001858static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001859{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001860 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001861 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001862
Alexander Duyckbd198052011-06-11 01:45:08 +00001863 ixgbe_update_itr(q_vector, &q_vector->tx);
1864 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001865
Alexander Duyck08c88332011-06-11 01:45:03 +00001866 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001867
1868 switch (current_itr) {
1869 /* counts and packets in update_itr are dependent on these numbers */
1870 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001871 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001872 break;
1873 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001874 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001875 break;
1876 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001877 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001878 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001879 default:
1880 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001881 }
1882
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001883 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001884 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001885 new_itr = (10 * new_itr * q_vector->itr) /
1886 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001887
Alexander Duyckbd198052011-06-11 01:45:08 +00001888 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001889 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001890
1891 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001892 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001893}
1894
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001895/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001896 * ixgbe_check_overtemp_subtask - check for over tempurature
1897 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001898 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001899static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001900{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001901 struct ixgbe_hw *hw = &adapter->hw;
1902 u32 eicr = adapter->interrupt_event;
1903
Alexander Duyckf0f97782011-04-22 04:08:09 +00001904 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001905 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001906
Alexander Duyckf0f97782011-04-22 04:08:09 +00001907 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1908 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1909 return;
1910
1911 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1912
Joe Perches7ca647b2010-09-07 21:35:40 +00001913 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001914 case IXGBE_DEV_ID_82599_T3_LOM:
1915 /*
1916 * Since the warning interrupt is for both ports
1917 * we don't have to check if:
1918 * - This interrupt wasn't for our port.
1919 * - We may have missed the interrupt so always have to
1920 * check if we got a LSC
1921 */
1922 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1923 !(eicr & IXGBE_EICR_LSC))
1924 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001925
Alexander Duyckf0f97782011-04-22 04:08:09 +00001926 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1927 u32 autoneg;
1928 bool link_up = false;
1929
Joe Perches7ca647b2010-09-07 21:35:40 +00001930 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1931
Alexander Duyckf0f97782011-04-22 04:08:09 +00001932 if (link_up)
1933 return;
1934 }
1935
1936 /* Check if this is not due to overtemp */
1937 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1938 return;
1939
1940 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001941 default:
1942 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1943 return;
1944 break;
1945 }
1946 e_crit(drv,
1947 "Network adapter has been stopped because it has over heated. "
1948 "Restart the computer. If the problem persists, "
1949 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001950
1951 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001952}
1953
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001954static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1955{
1956 struct ixgbe_hw *hw = &adapter->hw;
1957
1958 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1959 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001960 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001961 /* write to clear the interrupt */
1962 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1963 }
1964}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001965
Jacob Keller4f51bf72011-08-20 04:49:45 +00001966static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1967{
1968 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1969 return;
1970
1971 switch (adapter->hw.mac.type) {
1972 case ixgbe_mac_82599EB:
1973 /*
1974 * Need to check link state so complete overtemp check
1975 * on service task
1976 */
1977 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1978 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1979 adapter->interrupt_event = eicr;
1980 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1981 ixgbe_service_event_schedule(adapter);
1982 return;
1983 }
1984 return;
1985 case ixgbe_mac_X540:
1986 if (!(eicr & IXGBE_EICR_TS))
1987 return;
1988 break;
1989 default:
1990 return;
1991 }
1992
1993 e_crit(drv,
1994 "Network adapter has been stopped because it has over heated. "
1995 "Restart the computer. If the problem persists, "
1996 "power off the system and replace the adapter\n");
1997}
1998
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001999static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2000{
2001 struct ixgbe_hw *hw = &adapter->hw;
2002
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002003 if (eicr & IXGBE_EICR_GPI_SDP2) {
2004 /* Clear the interrupt */
2005 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002006 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2007 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2008 ixgbe_service_event_schedule(adapter);
2009 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002010 }
2011
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002012 if (eicr & IXGBE_EICR_GPI_SDP1) {
2013 /* Clear the interrupt */
2014 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002015 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2016 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2017 ixgbe_service_event_schedule(adapter);
2018 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002019 }
2020}
2021
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002022static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2023{
2024 struct ixgbe_hw *hw = &adapter->hw;
2025
2026 adapter->lsc_int++;
2027 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2028 adapter->link_check_timeout = jiffies;
2029 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2030 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002031 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002032 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002033 }
2034}
2035
Alexander Duyckfe49f042009-06-04 16:00:09 +00002036static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2037 u64 qmask)
2038{
2039 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002040 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002041
Alexander Duyckbd508172010-11-16 19:27:03 -08002042 switch (hw->mac.type) {
2043 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002044 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002045 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2046 break;
2047 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002048 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002049 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002050 if (mask)
2051 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002052 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002053 if (mask)
2054 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2055 break;
2056 default:
2057 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002058 }
2059 /* skip the flush */
2060}
2061
2062static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002063 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002064{
2065 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002066 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002067
Alexander Duyckbd508172010-11-16 19:27:03 -08002068 switch (hw->mac.type) {
2069 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002070 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002071 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2072 break;
2073 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002074 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002075 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002076 if (mask)
2077 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002078 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002079 if (mask)
2080 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2081 break;
2082 default:
2083 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002084 }
2085 /* skip the flush */
2086}
2087
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002088/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002089 * ixgbe_irq_enable - Enable default interrupt generation settings
2090 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002091 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002092static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2093 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002094{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002095 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002096
Alexander Duyck2c4af692011-07-15 07:29:55 +00002097 /* don't reenable LSC while waiting for link */
2098 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2099 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002100
Alexander Duyck2c4af692011-07-15 07:29:55 +00002101 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002102 switch (adapter->hw.mac.type) {
2103 case ixgbe_mac_82599EB:
2104 mask |= IXGBE_EIMS_GPI_SDP0;
2105 break;
2106 case ixgbe_mac_X540:
2107 mask |= IXGBE_EIMS_TS;
2108 break;
2109 default:
2110 break;
2111 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002112 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2113 mask |= IXGBE_EIMS_GPI_SDP1;
2114 switch (adapter->hw.mac.type) {
2115 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002116 mask |= IXGBE_EIMS_GPI_SDP1;
2117 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002118 case ixgbe_mac_X540:
2119 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002120 mask |= IXGBE_EIMS_MAILBOX;
2121 break;
2122 default:
2123 break;
2124 }
2125 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2126 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2127 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002128
Alexander Duyck2c4af692011-07-15 07:29:55 +00002129 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2130 if (queues)
2131 ixgbe_irq_enable_queues(adapter, ~0);
2132 if (flush)
2133 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002134}
2135
Alexander Duyck2c4af692011-07-15 07:29:55 +00002136static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002137{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002138 struct ixgbe_adapter *adapter = data;
2139 struct ixgbe_hw *hw = &adapter->hw;
2140 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002141
Alexander Duyck2c4af692011-07-15 07:29:55 +00002142 /*
2143 * Workaround for Silicon errata. Use clear-by-write instead
2144 * of clear-by-read. Reading with EICS will return the
2145 * interrupt causes without clearing, which later be done
2146 * with the write to EICR.
2147 */
2148 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2149 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002150
Alexander Duyck2c4af692011-07-15 07:29:55 +00002151 if (eicr & IXGBE_EICR_LSC)
2152 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002153
Alexander Duyck2c4af692011-07-15 07:29:55 +00002154 if (eicr & IXGBE_EICR_MAILBOX)
2155 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002156
Alexander Duyck2c4af692011-07-15 07:29:55 +00002157 switch (hw->mac.type) {
2158 case ixgbe_mac_82599EB:
2159 case ixgbe_mac_X540:
2160 if (eicr & IXGBE_EICR_ECC)
2161 e_info(link, "Received unrecoverable ECC Err, please "
2162 "reboot\n");
2163 /* Handle Flow Director Full threshold interrupt */
2164 if (eicr & IXGBE_EICR_FLOW_DIR) {
2165 int reinit_count = 0;
2166 int i;
2167 for (i = 0; i < adapter->num_tx_queues; i++) {
2168 struct ixgbe_ring *ring = adapter->tx_ring[i];
2169 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2170 &ring->state))
2171 reinit_count++;
2172 }
2173 if (reinit_count) {
2174 /* no more flow director interrupts until after init */
2175 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2176 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2177 ixgbe_service_event_schedule(adapter);
2178 }
2179 }
2180 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002181 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002182 break;
2183 default:
2184 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002185 }
2186
Alexander Duyck2c4af692011-07-15 07:29:55 +00002187 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002188
Alexander Duyck2c4af692011-07-15 07:29:55 +00002189 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002190 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002191 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002192
Alexander Duyck2c4af692011-07-15 07:29:55 +00002193 return IRQ_HANDLED;
2194}
2195
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002196static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002197{
2198 struct ixgbe_q_vector *q_vector = data;
2199
Auke Kok9a799d72007-09-15 14:07:45 -07002200 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002201
2202 if (q_vector->rx.ring || q_vector->tx.ring)
2203 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002204
2205 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002206}
2207
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002208static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002209 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002210{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002211 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002212 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002213
Alexander Duyck22745432010-11-16 19:27:10 -08002214 rx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002215 rx_ring->next = q_vector->rx.ring;
2216 q_vector->rx.ring = rx_ring;
2217 q_vector->rx.count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002218}
Auke Kok9a799d72007-09-15 14:07:45 -07002219
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002220static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002221 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002222{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002223 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002224 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002225
Alexander Duyck22745432010-11-16 19:27:10 -08002226 tx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002227 tx_ring->next = q_vector->tx.ring;
2228 q_vector->tx.ring = tx_ring;
2229 q_vector->tx.count++;
Alexander Duyckbd198052011-06-11 01:45:08 +00002230 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002231}
Auke Kok9a799d72007-09-15 14:07:45 -07002232
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002233/**
2234 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2235 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002236 *
2237 * This function maps descriptor rings to the queue-specific vectors
2238 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2239 * one vector per ring/queue, but on a constrained vector budget, we
2240 * group the rings as "efficiently" as possible. You would add new
2241 * mapping configurations in here.
2242 **/
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002243static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244{
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002245 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2246 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2247 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002248 int v_start = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002249
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002250 /* only one q_vector if MSI-X is disabled. */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002251 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002252 q_vectors = 1;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002253
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002254 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002255 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2256 * group them so there are multiple queues per vector.
2257 *
2258 * Re-adjusting *qpv takes care of the remainder.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002259 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002260 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2261 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2262 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263 map_vector_to_rxq(adapter, v_start, rxr_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002264 }
2265
2266 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002267 * If there are not enough q_vectors for each ring to have it's own
2268 * vector then we must pair up Rx/Tx on a each vector
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002269 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002270 if ((v_start + txr_remaining) > q_vectors)
2271 v_start = 0;
2272
2273 for (; v_start < q_vectors && txr_remaining; v_start++) {
2274 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2275 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2276 map_vector_to_txq(adapter, v_start, txr_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07002277 }
Auke Kok9a799d72007-09-15 14:07:45 -07002278}
2279
2280/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002281 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2282 * @adapter: board private structure
2283 *
2284 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2285 * interrupts from the kernel.
2286 **/
2287static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2288{
2289 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002290 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2291 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002292 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002293
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002295 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002296 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002297
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002298 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002299 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002300 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002301 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002302 } else if (q_vector->rx.ring) {
2303 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2304 "%s-%s-%d", netdev->name, "rx", ri++);
2305 } else if (q_vector->tx.ring) {
2306 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2307 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002308 } else {
2309 /* skip this unused q_vector */
2310 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002311 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002312 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2313 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002314 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002315 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002316 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002317 goto free_queue_irqs;
2318 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002319 /* If Flow Director is enabled, set interrupt affinity */
2320 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2321 /* assign the mask for this irq */
2322 irq_set_affinity_hint(entry->vector,
2323 q_vector->affinity_mask);
2324 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325 }
2326
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002328 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002329 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002330 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002331 goto free_queue_irqs;
2332 }
2333
2334 return 0;
2335
2336free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002337 while (vector) {
2338 vector--;
2339 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2340 NULL);
2341 free_irq(adapter->msix_entries[vector].vector,
2342 adapter->q_vector[vector]);
2343 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2345 pci_disable_msix(adapter->pdev);
2346 kfree(adapter->msix_entries);
2347 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 return err;
2349}
2350
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002351/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002352 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002353 * @irq: interrupt number
2354 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002355 **/
2356static irqreturn_t ixgbe_intr(int irq, void *data)
2357{
Alexander Duycka65151b2011-05-27 05:31:32 +00002358 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002359 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002360 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002361 u32 eicr;
2362
Don Skidmore54037502009-02-21 15:42:56 -08002363 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002364 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002365 * before the read of EICR.
2366 */
2367 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2368
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002370 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002371 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002372 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002373 /*
2374 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002375 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002376 * have disabled interrupts due to EIAM
2377 * finish the workaround of silicon errata on 82598. Unmask
2378 * the interrupt that we masked before the EICR read.
2379 */
2380 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2381 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002382 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002383 }
Auke Kok9a799d72007-09-15 14:07:45 -07002384
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002385 if (eicr & IXGBE_EICR_LSC)
2386 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002387
Alexander Duyckbd508172010-11-16 19:27:03 -08002388 switch (hw->mac.type) {
2389 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002390 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002391 /* Fall through */
2392 case ixgbe_mac_X540:
2393 if (eicr & IXGBE_EICR_ECC)
2394 e_info(link, "Received unrecoverable ECC err, please "
2395 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002396 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002397 break;
2398 default:
2399 break;
2400 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002401
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002402 ixgbe_check_fan_failure(adapter, eicr);
2403
Alexander Duyck7a921c92009-05-06 10:43:28 +00002404 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002405 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002406 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002407 }
2408
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002409 /*
2410 * re-enable link(maybe) and non-queue interrupts, no flush.
2411 * ixgbe_poll will re-enable the queue interrupts
2412 */
2413
2414 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2415 ixgbe_irq_enable(adapter, false, false);
2416
Auke Kok9a799d72007-09-15 14:07:45 -07002417 return IRQ_HANDLED;
2418}
2419
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002420static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2421{
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002422 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2423 int i;
2424
2425 /* legacy and MSI only use one vector */
2426 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2427 q_vectors = 1;
2428
2429 for (i = 0; i < adapter->num_rx_queues; i++) {
2430 adapter->rx_ring[i]->q_vector = NULL;
2431 adapter->rx_ring[i]->next = NULL;
2432 }
2433 for (i = 0; i < adapter->num_tx_queues; i++) {
2434 adapter->tx_ring[i]->q_vector = NULL;
2435 adapter->tx_ring[i]->next = NULL;
2436 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002437
2438 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002439 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002440 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2441 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002442 }
2443}
2444
Auke Kok9a799d72007-09-15 14:07:45 -07002445/**
2446 * ixgbe_request_irq - initialize interrupts
2447 * @adapter: board private structure
2448 *
2449 * Attempts to configure interrupts using the best available
2450 * capabilities of the hardware and kernel.
2451 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002453{
2454 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002455 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002456
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002457 /* map all of the rings to the q_vectors */
2458 ixgbe_map_rings_to_vectors(adapter);
2459
2460 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002461 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002462 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002463 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151b2011-05-27 05:31:32 +00002464 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002465 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002466 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151b2011-05-27 05:31:32 +00002467 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002468
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002469 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002470 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002471
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002472 /* place q_vectors and rings back into a known good state */
2473 ixgbe_reset_q_vectors(adapter);
2474 }
2475
Auke Kok9a799d72007-09-15 14:07:45 -07002476 return err;
2477}
2478
2479static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2480{
Auke Kok9a799d72007-09-15 14:07:45 -07002481 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002482 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002483
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002484 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002485 i = q_vectors - 1;
Alexander Duycka65151b2011-05-27 05:31:32 +00002486 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002487 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002488
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002489 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002490 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002491 if (!adapter->q_vector[i]->rx.ring &&
2492 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002493 continue;
2494
Alexander Duyck207867f2011-07-15 03:05:37 +00002495 /* clear the affinity_mask in the IRQ descriptor */
2496 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2497 NULL);
2498
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002499 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002500 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002501 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002502 } else {
Alexander Duycka65151b2011-05-27 05:31:32 +00002503 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002504 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002505
2506 /* clear q_vector state information */
2507 ixgbe_reset_q_vectors(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002508}
2509
2510/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002511 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2512 * @adapter: board private structure
2513 **/
2514static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2515{
Alexander Duyckbd508172010-11-16 19:27:03 -08002516 switch (adapter->hw.mac.type) {
2517 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002518 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002519 break;
2520 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002521 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002522 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2523 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002524 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002525 break;
2526 default:
2527 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002528 }
2529 IXGBE_WRITE_FLUSH(&adapter->hw);
2530 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2531 int i;
2532 for (i = 0; i < adapter->num_msix_vectors; i++)
2533 synchronize_irq(adapter->msix_entries[i].vector);
2534 } else {
2535 synchronize_irq(adapter->pdev->irq);
2536 }
2537}
2538
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002539/**
Auke Kok9a799d72007-09-15 14:07:45 -07002540 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2541 *
2542 **/
2543static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2544{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002545 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002546
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002547 /* rx/tx vector */
2548 if (adapter->rx_itr_setting == 1)
2549 q_vector->itr = IXGBE_20K_ITR;
2550 else
2551 q_vector->itr = adapter->rx_itr_setting;
2552
2553 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002554
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002555 ixgbe_set_ivar(adapter, 0, 0, 0);
2556 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557
Emil Tantilov396e7992010-07-01 20:05:12 +00002558 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002559}
2560
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002561/**
2562 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2563 * @adapter: board private structure
2564 * @ring: structure containing ring specific data
2565 *
2566 * Configure the Tx descriptor ring after a reset.
2567 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002568void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2569 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002570{
2571 struct ixgbe_hw *hw = &adapter->hw;
2572 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002573 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002574 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002575 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002576
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002577 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002578 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002579 IXGBE_WRITE_FLUSH(hw);
2580
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002581 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002582 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002583 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2584 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2585 ring->count * sizeof(union ixgbe_adv_tx_desc));
2586 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2587 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002588 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002589
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002590 /*
2591 * set WTHRESH to encourage burst writeback, it should not be set
2592 * higher than 1 when ITR is 0 as it could cause false TX hangs
2593 *
2594 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2595 * to or less than the number of on chip descriptors, which is
2596 * currently 40.
2597 */
Alexander Duycke954b372012-02-08 07:49:38 +00002598 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002599 txdctl |= (1 << 16); /* WTHRESH = 1 */
2600 else
2601 txdctl |= (8 << 16); /* WTHRESH = 8 */
2602
Alexander Duycke954b372012-02-08 07:49:38 +00002603 /*
2604 * Setting PTHRESH to 32 both improves performance
2605 * and avoids a TX hang with DFP enabled
2606 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002607 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2608 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002609
2610 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002611 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2612 adapter->atr_sample_rate) {
2613 ring->atr_sample_rate = adapter->atr_sample_rate;
2614 ring->atr_count = 0;
2615 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2616 } else {
2617 ring->atr_sample_rate = 0;
2618 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002619
John Fastabendc84d3242010-11-16 19:27:12 -08002620 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2621
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002622 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002623 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2624
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002625 netdev_tx_reset_queue(txring_txq(ring));
2626
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002627 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2628 if (hw->mac.type == ixgbe_mac_82598EB &&
2629 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2630 return;
2631
2632 /* poll to verify queue is enabled */
2633 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002634 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002635 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2636 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2637 if (!wait_loop)
2638 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002639}
2640
Alexander Duyck120ff942010-08-19 13:34:50 +00002641static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2642{
2643 struct ixgbe_hw *hw = &adapter->hw;
2644 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002645 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002646 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002647
2648 if (hw->mac.type == ixgbe_mac_82598EB)
2649 return;
2650
2651 /* disable the arbiter while setting MTQC */
2652 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2653 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2654 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2655
2656 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002657 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002658 case (IXGBE_FLAG_SRIOV_ENABLED):
2659 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2660 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2661 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002662 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002663 if (!tcs)
2664 reg = IXGBE_MTQC_64Q_1PB;
2665 else if (tcs <= 4)
2666 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2667 else
2668 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2669
2670 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2671
2672 /* Enable Security TX Buffer IFG for multiple pb */
2673 if (tcs) {
2674 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2675 reg |= IXGBE_SECTX_DCB;
2676 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2677 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002678 break;
2679 }
2680
2681 /* re-enable the arbiter */
2682 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2683 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2684}
2685
Auke Kok9a799d72007-09-15 14:07:45 -07002686/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002687 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002688 * @adapter: board private structure
2689 *
2690 * Configure the Tx unit of the MAC after a reset.
2691 **/
2692static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2693{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002694 struct ixgbe_hw *hw = &adapter->hw;
2695 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002696 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002697
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002698 ixgbe_setup_mtqc(adapter);
2699
2700 if (hw->mac.type != ixgbe_mac_82598EB) {
2701 /* DMATXCTL.EN must be before Tx queues are enabled */
2702 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2703 dmatxctl |= IXGBE_DMATXCTL_TE;
2704 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2705 }
2706
Auke Kok9a799d72007-09-15 14:07:45 -07002707 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002708 for (i = 0; i < adapter->num_tx_queues; i++)
2709 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002710}
2711
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002712#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002713
Yi Zoua6616b42009-08-06 13:05:23 +00002714static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002715 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002716{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002717 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002718 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002719
Alexander Duyckbd508172010-11-16 19:27:03 -08002720 switch (adapter->hw.mac.type) {
2721 case ixgbe_mac_82598EB: {
2722 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2723 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002724 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002725 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002726 break;
2727 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002728 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002729 default:
2730 break;
2731 }
2732
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002733 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002734
2735 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2736 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002737 if (adapter->num_vfs)
2738 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002739
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002740 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2741 IXGBE_SRRCTL_BSIZEHDR_MASK;
2742
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002743 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002744#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2745 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2746#else
2747 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2748#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002749 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002750 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002751 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2752 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002753 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002754 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002755
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002756 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002757}
2758
Alexander Duyck05abb122010-08-19 13:35:41 +00002759static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002760{
Alexander Duyck05abb122010-08-19 13:35:41 +00002761 struct ixgbe_hw *hw = &adapter->hw;
2762 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002763 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2764 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002765 u32 mrqc = 0, reta = 0;
2766 u32 rxcsum;
2767 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002768 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002769 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2770
2771 if (tcs)
2772 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002773
Alexander Duyck05abb122010-08-19 13:35:41 +00002774 /* Fill out hash function seeds */
2775 for (i = 0; i < 10; i++)
2776 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002777
Alexander Duyck05abb122010-08-19 13:35:41 +00002778 /* Fill out redirection table */
2779 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002780 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002781 j = 0;
2782 /* reta = 4-byte sliding window of
2783 * 0x00..(indices-1)(indices-1)00..etc. */
2784 reta = (reta << 8) | (j * 0x11);
2785 if ((i & 3) == 3)
2786 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2787 }
2788
2789 /* Disable indicating checksum in descriptor, enables RSS hash */
2790 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2791 rxcsum |= IXGBE_RXCSUM_PCSD;
2792 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2793
John Fastabend8b1c0b22011-05-03 02:26:48 +00002794 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2795 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002796 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002797 } else {
2798 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2799 | IXGBE_FLAG_SRIOV_ENABLED);
2800
2801 switch (mask) {
2802 case (IXGBE_FLAG_RSS_ENABLED):
2803 if (!tcs)
2804 mrqc = IXGBE_MRQC_RSSEN;
2805 else if (tcs <= 4)
2806 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2807 else
2808 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2809 break;
2810 case (IXGBE_FLAG_SRIOV_ENABLED):
2811 mrqc = IXGBE_MRQC_VMDQEN;
2812 break;
2813 default:
2814 break;
2815 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002816 }
2817
Alexander Duyck05abb122010-08-19 13:35:41 +00002818 /* Perform hash on these packet types */
2819 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2820 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2821 | IXGBE_MRQC_RSS_FIELD_IPV6
2822 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2823
2824 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002825}
2826
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002827/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002828 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2829 * @adapter: address of board private structure
2830 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002831 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002832static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002833 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002834{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002835 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002836 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002837 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002838 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002839
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002840 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002841 return;
2842
2843 rx_buf_len = ring->rx_buf_len;
2844 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002845 rscctrl |= IXGBE_RSCCTL_RSCEN;
2846 /*
2847 * we must limit the number of descriptors so that the
2848 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002849 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002850 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002851 if (ring_is_ps_enabled(ring)) {
Alexander Duyck642c6802011-11-10 09:09:17 +00002852#if (PAGE_SIZE < 8192)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002853 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002854#elif (PAGE_SIZE < 16384)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002855 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duyck642c6802011-11-10 09:09:17 +00002856#elif (PAGE_SIZE < 32768)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002857 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2858#else
2859 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2860#endif
2861 } else {
Alexander Duyck642c6802011-11-10 09:09:17 +00002862 if (rx_buf_len <= IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002863 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002864 else if (rx_buf_len <= IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002865 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2866 else
2867 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2868 }
Alexander Duyck73670962010-08-19 13:38:34 +00002869 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002870}
2871
Alexander Duyck9e10e042010-08-19 13:40:06 +00002872/**
2873 * ixgbe_set_uta - Set unicast filter table address
2874 * @adapter: board private structure
2875 *
2876 * The unicast table address is a register array of 32-bit registers.
2877 * The table is meant to be used in a way similar to how the MTA is used
2878 * however due to certain limitations in the hardware it is necessary to
2879 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2880 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2881 **/
2882static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2883{
2884 struct ixgbe_hw *hw = &adapter->hw;
2885 int i;
2886
2887 /* The UTA table only exists on 82599 hardware and newer */
2888 if (hw->mac.type < ixgbe_mac_82599EB)
2889 return;
2890
2891 /* we only need to do this if VMDq is enabled */
2892 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2893 return;
2894
2895 for (i = 0; i < 128; i++)
2896 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2897}
2898
2899#define IXGBE_MAX_RX_DESC_POLL 10
2900static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2901 struct ixgbe_ring *ring)
2902{
2903 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002904 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2905 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002906 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002907
2908 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2909 if (hw->mac.type == ixgbe_mac_82598EB &&
2910 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2911 return;
2912
2913 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002914 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002915 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2916 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2917
2918 if (!wait_loop) {
2919 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2920 "the polling period\n", reg_idx);
2921 }
2922}
2923
Yi Zou2d39d572011-01-06 14:29:56 +00002924void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2925 struct ixgbe_ring *ring)
2926{
2927 struct ixgbe_hw *hw = &adapter->hw;
2928 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2929 u32 rxdctl;
2930 u8 reg_idx = ring->reg_idx;
2931
2932 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2933 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2934
2935 /* write value back with RXDCTL.ENABLE bit cleared */
2936 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2937
2938 if (hw->mac.type == ixgbe_mac_82598EB &&
2939 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2940 return;
2941
2942 /* the hardware may take up to 100us to really disable the rx queue */
2943 do {
2944 udelay(10);
2945 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2946 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2947
2948 if (!wait_loop) {
2949 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2950 "the polling period\n", reg_idx);
2951 }
2952}
2953
Alexander Duyck84418e32010-08-19 13:40:54 +00002954void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2955 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002956{
2957 struct ixgbe_hw *hw = &adapter->hw;
2958 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002959 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002960 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002961
Alexander Duyck9e10e042010-08-19 13:40:06 +00002962 /* disable queue to avoid issues while updating state */
2963 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002964 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002965
Alexander Duyckacd37172010-08-19 13:36:05 +00002966 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2967 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2968 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2969 ring->count * sizeof(union ixgbe_adv_rx_desc));
2970 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2971 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002972 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002973
2974 ixgbe_configure_srrctl(adapter, ring);
2975 ixgbe_configure_rscctl(adapter, ring);
2976
Greg Rosee9f98072011-01-26 01:06:07 +00002977 /* If operating in IOV mode set RLPML for X540 */
2978 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2979 hw->mac.type == ixgbe_mac_X540) {
2980 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2981 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2982 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2983 }
2984
Alexander Duyck9e10e042010-08-19 13:40:06 +00002985 if (hw->mac.type == ixgbe_mac_82598EB) {
2986 /*
2987 * enable cache line friendly hardware writes:
2988 * PTHRESH=32 descriptors (half the internal cache),
2989 * this also removes ugly rx_no_buffer_count increment
2990 * HTHRESH=4 descriptors (to minimize latency on fetch)
2991 * WTHRESH=8 burst writeback up to two cache lines
2992 */
2993 rxdctl &= ~0x3FFFFF;
2994 rxdctl |= 0x080420;
2995 }
2996
2997 /* enable receive descriptor ring */
2998 rxdctl |= IXGBE_RXDCTL_ENABLE;
2999 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3000
3001 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003002 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003003}
3004
Alexander Duyck48654522010-08-19 13:36:27 +00003005static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3006{
3007 struct ixgbe_hw *hw = &adapter->hw;
3008 int p;
3009
3010 /* PSRTYPE must be initialized in non 82598 adapters */
3011 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003012 IXGBE_PSRTYPE_UDPHDR |
3013 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003014 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003015 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003016
3017 if (hw->mac.type == ixgbe_mac_82598EB)
3018 return;
3019
3020 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3021 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3022
3023 for (p = 0; p < adapter->num_rx_pools; p++)
3024 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3025 psrtype);
3026}
3027
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003028static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3029{
3030 struct ixgbe_hw *hw = &adapter->hw;
3031 u32 gcr_ext;
3032 u32 vt_reg_bits;
3033 u32 reg_offset, vf_shift;
3034 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003035 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003036
3037 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3038 return;
3039
3040 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3041 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3042 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3043 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3044
3045 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00003046 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003047
3048 /* Enable only the PF's pool for Tx/Rx */
3049 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3050 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3051 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3052 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3053 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3054
3055 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3056 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3057
3058 /*
3059 * Set up VF register offsets for selected VT Mode,
3060 * i.e. 32 or 64 VFs for SR-IOV
3061 */
3062 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3063 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3064 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3065 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3066
3067 /* enable Tx loopback for VF/PF communication */
3068 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003069 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00003070 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003071 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003072 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003073 /* For VFs that have spoof checking turned off */
3074 for (i = 0; i < adapter->num_vfs; i++) {
3075 if (!adapter->vfinfo[i].spoofchk_enabled)
3076 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3077 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003078}
3079
Alexander Duyck477de6e2010-08-19 13:38:11 +00003080static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003081{
Auke Kok9a799d72007-09-15 14:07:45 -07003082 struct ixgbe_hw *hw = &adapter->hw;
3083 struct net_device *netdev = adapter->netdev;
3084 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003085 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003086 struct ixgbe_ring *rx_ring;
3087 int i;
3088 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003089
Auke Kok9a799d72007-09-15 14:07:45 -07003090 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003091 /* On by default */
3092 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3093
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003094 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003095 if (adapter->num_vfs)
3096 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3097
3098 /* Disable packet split due to 82599 erratum #45 */
3099 if (hw->mac.type == ixgbe_mac_82599EB)
3100 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003101
Alexander Duyck477de6e2010-08-19 13:38:11 +00003102#ifdef IXGBE_FCOE
3103 /* adjust max frame to be able to do baby jumbo for FCoE */
3104 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3105 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3106 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3107
3108#endif /* IXGBE_FCOE */
3109 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3110 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3111 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3112 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3113
3114 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003115 }
3116
Alexander Duyck919e78a2011-08-26 09:52:38 +00003117 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3118 max_frame += VLAN_HLEN;
3119
3120 /* Set the RX buffer length according to the mode */
3121 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3122 rx_buf_len = IXGBE_RX_HDR_SIZE;
3123 } else {
3124 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3125 (netdev->mtu <= ETH_DATA_LEN))
3126 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3127 /*
3128 * Make best use of allocation by using all but 1K of a
3129 * power of 2 allocation that will be used for skb->head.
3130 */
3131 else if (max_frame <= IXGBE_RXBUFFER_3K)
3132 rx_buf_len = IXGBE_RXBUFFER_3K;
3133 else if (max_frame <= IXGBE_RXBUFFER_7K)
3134 rx_buf_len = IXGBE_RXBUFFER_7K;
3135 else if (max_frame <= IXGBE_RXBUFFER_15K)
3136 rx_buf_len = IXGBE_RXBUFFER_15K;
3137 else
3138 rx_buf_len = IXGBE_MAX_RXBUFFER;
3139 }
3140
Auke Kok9a799d72007-09-15 14:07:45 -07003141 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003142 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3143 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003144 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3145
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003146 /*
3147 * Setup the HW Rx Head and Tail Descriptor Pointers and
3148 * the Base and Length of the Rx Descriptor Ring
3149 */
Auke Kok9a799d72007-09-15 14:07:45 -07003150 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003151 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003152 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003153
Yi Zou6e455b892009-08-06 13:05:44 +00003154 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003155 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003156 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003157 clear_ring_ps_enabled(rx_ring);
3158
3159 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3160 set_ring_rsc_enabled(rx_ring);
3161 else
3162 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003163
Yi Zou63f39bd2009-05-17 12:34:35 +00003164#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003165 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003166 struct ixgbe_ring_feature *f;
3167 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003168 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003169 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003170 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3171 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003172 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003173 } else if (!ring_is_rsc_enabled(rx_ring) &&
3174 !ring_is_ps_enabled(rx_ring)) {
3175 rx_ring->rx_buf_len =
3176 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003177 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003178 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003179#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003180 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003181}
3182
Alexander Duyck73670962010-08-19 13:38:34 +00003183static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3184{
3185 struct ixgbe_hw *hw = &adapter->hw;
3186 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3187
3188 switch (hw->mac.type) {
3189 case ixgbe_mac_82598EB:
3190 /*
3191 * For VMDq support of different descriptor types or
3192 * buffer sizes through the use of multiple SRRCTL
3193 * registers, RDRXCTL.MVMEN must be set to 1
3194 *
3195 * also, the manual doesn't mention it clearly but DCA hints
3196 * will only use queue 0's tags unless this bit is set. Side
3197 * effects of setting this bit are only that SRRCTL must be
3198 * fully programmed [0..15]
3199 */
3200 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3201 break;
3202 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003203 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003204 /* Disable RSC for ACK packets */
3205 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3206 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3207 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3208 /* hardware requires some bits to be set by default */
3209 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3210 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3211 break;
3212 default:
3213 /* We should do nothing since we don't know this hardware */
3214 return;
3215 }
3216
3217 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3218}
3219
Alexander Duyck477de6e2010-08-19 13:38:11 +00003220/**
3221 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3222 * @adapter: board private structure
3223 *
3224 * Configure the Rx unit of the MAC after a reset.
3225 **/
3226static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3227{
3228 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003229 int i;
3230 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003231
3232 /* disable receives while setting up the descriptors */
3233 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3234 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3235
3236 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003237 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003238
Alexander Duyck9e10e042010-08-19 13:40:06 +00003239 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003240 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003241
Alexander Duyck9e10e042010-08-19 13:40:06 +00003242 ixgbe_set_uta(adapter);
3243
Alexander Duyck477de6e2010-08-19 13:38:11 +00003244 /* set_rx_buffer_len must be called before ring initialization */
3245 ixgbe_set_rx_buffer_len(adapter);
3246
3247 /*
3248 * Setup the HW Rx Head and Tail Descriptor Pointers and
3249 * the Base and Length of the Rx Descriptor Ring
3250 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003251 for (i = 0; i < adapter->num_rx_queues; i++)
3252 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003253
Alexander Duyck9e10e042010-08-19 13:40:06 +00003254 /* disable drop enable for 82598 parts */
3255 if (hw->mac.type == ixgbe_mac_82598EB)
3256 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3257
3258 /* enable all receives */
3259 rxctrl |= IXGBE_RXCTRL_RXEN;
3260 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003261}
3262
Jiri Pirko8e586132011-12-08 19:52:37 -05003263static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003264{
3265 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003266 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003267 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003268
3269 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003270 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003271 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003272
3273 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003274}
3275
Jiri Pirko8e586132011-12-08 19:52:37 -05003276static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003277{
3278 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003279 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003280 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003281
Auke Kok9a799d72007-09-15 14:07:45 -07003282 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003283 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003284 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003285
3286 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003287}
3288
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003289/**
3290 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3291 * @adapter: driver data
3292 */
3293static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3294{
3295 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003296 u32 vlnctrl;
3297
3298 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3299 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3300 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3301}
3302
3303/**
3304 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3305 * @adapter: driver data
3306 */
3307static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3308{
3309 struct ixgbe_hw *hw = &adapter->hw;
3310 u32 vlnctrl;
3311
3312 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3313 vlnctrl |= IXGBE_VLNCTRL_VFE;
3314 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3315 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3316}
3317
3318/**
3319 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3320 * @adapter: driver data
3321 */
3322static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3323{
3324 struct ixgbe_hw *hw = &adapter->hw;
3325 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003326 int i, j;
3327
3328 switch (hw->mac.type) {
3329 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003330 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3331 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003332 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3333 break;
3334 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003335 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003336 for (i = 0; i < adapter->num_rx_queues; i++) {
3337 j = adapter->rx_ring[i]->reg_idx;
3338 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3339 vlnctrl &= ~IXGBE_RXDCTL_VME;
3340 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3341 }
3342 break;
3343 default:
3344 break;
3345 }
3346}
3347
3348/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003349 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003350 * @adapter: driver data
3351 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003352static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003353{
3354 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003355 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003356 int i, j;
3357
3358 switch (hw->mac.type) {
3359 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003360 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3361 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003362 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3363 break;
3364 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003365 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003366 for (i = 0; i < adapter->num_rx_queues; i++) {
3367 j = adapter->rx_ring[i]->reg_idx;
3368 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3369 vlnctrl |= IXGBE_RXDCTL_VME;
3370 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3371 }
3372 break;
3373 default:
3374 break;
3375 }
3376}
3377
Auke Kok9a799d72007-09-15 14:07:45 -07003378static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3379{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003380 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003381
Jesse Grossf62bbb52010-10-20 13:56:10 +00003382 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3383
3384 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3385 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003386}
3387
3388/**
Alexander Duyck28500622010-06-15 09:25:48 +00003389 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3390 * @netdev: network interface device structure
3391 *
3392 * Writes unicast address list to the RAR table.
3393 * Returns: -ENOMEM on failure/insufficient address space
3394 * 0 on no addresses written
3395 * X on writing X addresses to the RAR table
3396 **/
3397static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3398{
3399 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3400 struct ixgbe_hw *hw = &adapter->hw;
3401 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003402 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003403 int count = 0;
3404
3405 /* return ENOMEM indicating insufficient memory for addresses */
3406 if (netdev_uc_count(netdev) > rar_entries)
3407 return -ENOMEM;
3408
3409 if (!netdev_uc_empty(netdev) && rar_entries) {
3410 struct netdev_hw_addr *ha;
3411 /* return error if we do not support writing to RAR table */
3412 if (!hw->mac.ops.set_rar)
3413 return -ENOMEM;
3414
3415 netdev_for_each_uc_addr(ha, netdev) {
3416 if (!rar_entries)
3417 break;
3418 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3419 vfn, IXGBE_RAH_AV);
3420 count++;
3421 }
3422 }
3423 /* write the addresses in reverse order to avoid write combining */
3424 for (; rar_entries > 0 ; rar_entries--)
3425 hw->mac.ops.clear_rar(hw, rar_entries);
3426
3427 return count;
3428}
3429
3430/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003431 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003432 * @netdev: network interface device structure
3433 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003434 * The set_rx_method entry point is called whenever the unicast/multicast
3435 * address list or the network interface flags are updated. This routine is
3436 * responsible for configuring the hardware for proper unicast, multicast and
3437 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003438 **/
Greg Rose7f870472010-01-09 02:25:29 +00003439void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003440{
3441 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3442 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003443 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3444 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003445
3446 /* Check for Promiscuous and All Multicast modes */
3447
3448 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3449
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003450 /* set all bits that we expect to always be set */
3451 fctrl |= IXGBE_FCTRL_BAM;
3452 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3453 fctrl |= IXGBE_FCTRL_PMCF;
3454
Alexander Duyck28500622010-06-15 09:25:48 +00003455 /* clear the bits we are changing the status of */
3456 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3457
Auke Kok9a799d72007-09-15 14:07:45 -07003458 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003459 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003460 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003461 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003462 /* don't hardware filter vlans in promisc mode */
3463 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003464 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003465 if (netdev->flags & IFF_ALLMULTI) {
3466 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003467 vmolr |= IXGBE_VMOLR_MPE;
3468 } else {
3469 /*
3470 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003471 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003472 * that we can at least receive multicast traffic
3473 */
3474 hw->mac.ops.update_mc_addr_list(hw, netdev);
3475 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003476 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003477 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003478 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003479 /*
3480 * Write addresses to available RAR registers, if there is not
3481 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003482 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003483 */
3484 count = ixgbe_write_uc_addr_list(netdev);
3485 if (count < 0) {
3486 fctrl |= IXGBE_FCTRL_UPE;
3487 vmolr |= IXGBE_VMOLR_ROPE;
3488 }
3489 }
3490
3491 if (adapter->num_vfs) {
3492 ixgbe_restore_vf_multicasts(adapter);
3493 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3494 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3495 IXGBE_VMOLR_ROPE);
3496 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003497 }
3498
3499 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003500
3501 if (netdev->features & NETIF_F_HW_VLAN_RX)
3502 ixgbe_vlan_strip_enable(adapter);
3503 else
3504 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003505}
3506
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003507static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3508{
3509 int q_idx;
3510 struct ixgbe_q_vector *q_vector;
3511 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3512
3513 /* legacy and MSI only use one vector */
3514 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3515 q_vectors = 1;
3516
3517 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003518 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003519 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003520 }
3521}
3522
3523static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3524{
3525 int q_idx;
3526 struct ixgbe_q_vector *q_vector;
3527 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3528
3529 /* legacy and MSI only use one vector */
3530 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3531 q_vectors = 1;
3532
3533 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003534 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003535 napi_disable(&q_vector->napi);
3536 }
3537}
3538
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003539#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003540/*
3541 * ixgbe_configure_dcb - Configure DCB hardware
3542 * @adapter: ixgbe adapter struct
3543 *
3544 * This is called by the driver on open to configure the DCB hardware.
3545 * This is also called by the gennetlink interface when reconfiguring
3546 * the DCB state.
3547 */
3548static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3549{
3550 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003551 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003552
Alexander Duyck67ebd792010-08-19 13:34:04 +00003553 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3554 if (hw->mac.type == ixgbe_mac_82598EB)
3555 netif_set_gso_max_size(adapter->netdev, 65536);
3556 return;
3557 }
3558
3559 if (hw->mac.type == ixgbe_mac_82598EB)
3560 netif_set_gso_max_size(adapter->netdev, 32768);
3561
Alexander Duyck2f90b862008-11-20 20:52:10 -08003562
Alexander Duyck2f90b862008-11-20 20:52:10 -08003563 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003564 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003565
Alexander Duyck2f90b862008-11-20 20:52:10 -08003566 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003567
John Fastabendb1208182011-10-15 05:00:10 +00003568#ifdef IXGBE_FCOE
3569 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3570 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3571#endif
3572
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003573 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003574 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003575 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3576 DCB_TX_CONFIG);
3577 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3578 DCB_RX_CONFIG);
3579 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003580 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3581 ixgbe_dcb_hw_ets(&adapter->hw,
3582 adapter->ixgbe_ieee_ets,
3583 max_frame);
3584 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3585 adapter->ixgbe_ieee_pfc->pfc_en,
3586 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003587 }
John Fastabend8187cd42011-02-23 05:58:08 +00003588
3589 /* Enable RSS Hash per TC */
3590 if (hw->mac.type != ixgbe_mac_82598EB) {
3591 int i;
3592 u32 reg = 0;
3593
3594 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3595 u8 msb = 0;
3596 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3597
3598 while (cnt >>= 1)
3599 msb++;
3600
3601 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3602 }
3603 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3604 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003605}
John Fastabend9da712d2011-08-23 03:14:22 +00003606#endif
3607
3608/* Additional bittime to account for IXGBE framing */
3609#define IXGBE_ETH_FRAMING 20
3610
3611/*
3612 * ixgbe_hpbthresh - calculate high water mark for flow control
3613 *
3614 * @adapter: board private structure to calculate for
3615 * @pb - packet buffer to calculate
3616 */
3617static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3618{
3619 struct ixgbe_hw *hw = &adapter->hw;
3620 struct net_device *dev = adapter->netdev;
3621 int link, tc, kb, marker;
3622 u32 dv_id, rx_pba;
3623
3624 /* Calculate max LAN frame size */
3625 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3626
3627#ifdef IXGBE_FCOE
3628 /* FCoE traffic class uses FCOE jumbo frames */
3629 if (dev->features & NETIF_F_FCOE_MTU) {
3630 int fcoe_pb = 0;
3631
3632#ifdef CONFIG_IXGBE_DCB
3633 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003634
3635#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003636 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3637 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3638 }
3639#endif
3640
3641 /* Calculate delay value for device */
3642 switch (hw->mac.type) {
3643 case ixgbe_mac_X540:
3644 dv_id = IXGBE_DV_X540(link, tc);
3645 break;
3646 default:
3647 dv_id = IXGBE_DV(link, tc);
3648 break;
3649 }
3650
3651 /* Loopback switch introduces additional latency */
3652 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3653 dv_id += IXGBE_B2BT(tc);
3654
3655 /* Delay value is calculated in bit times convert to KB */
3656 kb = IXGBE_BT2KB(dv_id);
3657 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3658
3659 marker = rx_pba - kb;
3660
3661 /* It is possible that the packet buffer is not large enough
3662 * to provide required headroom. In this case throw an error
3663 * to user and a do the best we can.
3664 */
3665 if (marker < 0) {
3666 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3667 "headroom to support flow control."
3668 "Decrease MTU or number of traffic classes\n", pb);
3669 marker = tc + 1;
3670 }
3671
3672 return marker;
3673}
3674
3675/*
3676 * ixgbe_lpbthresh - calculate low water mark for for flow control
3677 *
3678 * @adapter: board private structure to calculate for
3679 * @pb - packet buffer to calculate
3680 */
3681static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3682{
3683 struct ixgbe_hw *hw = &adapter->hw;
3684 struct net_device *dev = adapter->netdev;
3685 int tc;
3686 u32 dv_id;
3687
3688 /* Calculate max LAN frame size */
3689 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3690
3691 /* Calculate delay value for device */
3692 switch (hw->mac.type) {
3693 case ixgbe_mac_X540:
3694 dv_id = IXGBE_LOW_DV_X540(tc);
3695 break;
3696 default:
3697 dv_id = IXGBE_LOW_DV(tc);
3698 break;
3699 }
3700
3701 /* Delay value is calculated in bit times convert to KB */
3702 return IXGBE_BT2KB(dv_id);
3703}
3704
3705/*
3706 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3707 */
3708static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3709{
3710 struct ixgbe_hw *hw = &adapter->hw;
3711 int num_tc = netdev_get_num_tc(adapter->netdev);
3712 int i;
3713
3714 if (!num_tc)
3715 num_tc = 1;
3716
3717 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3718
3719 for (i = 0; i < num_tc; i++) {
3720 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3721
3722 /* Low water marks must not be larger than high water marks */
3723 if (hw->fc.low_water > hw->fc.high_water[i])
3724 hw->fc.low_water = 0;
3725 }
3726}
John Fastabend80605c652011-05-02 12:34:10 +00003727
3728static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3729{
John Fastabend80605c652011-05-02 12:34:10 +00003730 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003731 int hdrm;
3732 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003733
3734 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3735 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003736 hdrm = 32 << adapter->fdir_pballoc;
3737 else
3738 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003739
Alexander Duyckf7e10272011-07-21 00:40:35 +00003740 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003741 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003742}
3743
Alexander Duycke4911d52011-05-11 07:18:52 +00003744static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3745{
3746 struct ixgbe_hw *hw = &adapter->hw;
3747 struct hlist_node *node, *node2;
3748 struct ixgbe_fdir_filter *filter;
3749
3750 spin_lock(&adapter->fdir_perfect_lock);
3751
3752 if (!hlist_empty(&adapter->fdir_filter_list))
3753 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3754
3755 hlist_for_each_entry_safe(filter, node, node2,
3756 &adapter->fdir_filter_list, fdir_node) {
3757 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003758 &filter->filter,
3759 filter->sw_idx,
3760 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3761 IXGBE_FDIR_DROP_QUEUE :
3762 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003763 }
3764
3765 spin_unlock(&adapter->fdir_perfect_lock);
3766}
3767
Auke Kok9a799d72007-09-15 14:07:45 -07003768static void ixgbe_configure(struct ixgbe_adapter *adapter)
3769{
John Fastabend80605c652011-05-02 12:34:10 +00003770 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003771#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003772 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003773#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003774
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003775 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003776 ixgbe_restore_vlan(adapter);
3777
Yi Zoueacd73f2009-05-13 13:11:06 +00003778#ifdef IXGBE_FCOE
3779 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3780 ixgbe_configure_fcoe(adapter);
3781
3782#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003783 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003784 ixgbe_init_fdir_signature_82599(&adapter->hw,
3785 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003786 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3787 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3788 adapter->fdir_pballoc);
3789 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003790 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003791
Alexander Duyck933d41f2010-09-07 21:34:29 +00003792 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003793
Auke Kok9a799d72007-09-15 14:07:45 -07003794 ixgbe_configure_tx(adapter);
3795 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003796}
3797
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003798static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3799{
3800 switch (hw->phy.type) {
3801 case ixgbe_phy_sfp_avago:
3802 case ixgbe_phy_sfp_ftl:
3803 case ixgbe_phy_sfp_intel:
3804 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003805 case ixgbe_phy_sfp_passive_tyco:
3806 case ixgbe_phy_sfp_passive_unknown:
3807 case ixgbe_phy_sfp_active_unknown:
3808 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003809 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003810 case ixgbe_phy_nl:
3811 if (hw->mac.type == ixgbe_mac_82598EB)
3812 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003813 default:
3814 return false;
3815 }
3816}
3817
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003818/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003819 * ixgbe_sfp_link_config - set up SFP+ link
3820 * @adapter: pointer to private adapter struct
3821 **/
3822static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3823{
Alexander Duyck70864002011-04-27 09:13:56 +00003824 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003825 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003826 * is that an SFP was inserted/removed after the reset
3827 * but before SFP detection was enabled. As such the best
3828 * solution is to just start searching as soon as we start
3829 */
3830 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3831 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003832
Alexander Duyck70864002011-04-27 09:13:56 +00003833 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003834}
3835
3836/**
3837 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003838 * @hw: pointer to private hardware struct
3839 *
3840 * Returns 0 on success, negative on failure
3841 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003842static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003843{
3844 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003845 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003846 u32 ret = IXGBE_ERR_LINK_SETUP;
3847
3848 if (hw->mac.ops.check_link)
3849 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3850
3851 if (ret)
3852 goto link_cfg_out;
3853
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003854 autoneg = hw->phy.autoneg_advertised;
3855 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003856 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3857 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003858 if (ret)
3859 goto link_cfg_out;
3860
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003861 if (hw->mac.ops.setup_link)
3862 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003863link_cfg_out:
3864 return ret;
3865}
3866
Alexander Duycka34bcff2010-08-19 13:39:20 +00003867static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003868{
Auke Kok9a799d72007-09-15 14:07:45 -07003869 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003870 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003871
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003872 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003873 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3874 IXGBE_GPIE_OCD;
3875 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003876 /*
3877 * use EIAM to auto-mask when MSI-X interrupt is asserted
3878 * this saves a register write for every interrupt
3879 */
3880 switch (hw->mac.type) {
3881 case ixgbe_mac_82598EB:
3882 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3883 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003884 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003885 case ixgbe_mac_X540:
3886 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003887 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3888 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3889 break;
3890 }
3891 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003892 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3893 * specifically only auto mask tx and rx interrupts */
3894 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003895 }
3896
Alexander Duycka34bcff2010-08-19 13:39:20 +00003897 /* XXX: to interrupt immediately for EICS writes, enable this */
3898 /* gpie |= IXGBE_GPIE_EIMEN; */
3899
3900 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3901 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3902 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003903 }
3904
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003905 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003906 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3907 switch (adapter->hw.mac.type) {
3908 case ixgbe_mac_82599EB:
3909 gpie |= IXGBE_SDP0_GPIEN;
3910 break;
3911 case ixgbe_mac_X540:
3912 gpie |= IXGBE_EIMS_TS;
3913 break;
3914 default:
3915 break;
3916 }
3917 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003918
Alexander Duycka34bcff2010-08-19 13:39:20 +00003919 /* Enable fan failure interrupt */
3920 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003921 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003922
Don Skidmore2698b202011-04-13 07:01:52 +00003923 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003924 gpie |= IXGBE_SDP1_GPIEN;
3925 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003926 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003927
3928 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3929}
3930
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003931static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003932{
3933 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003934 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003935 u32 ctrl_ext;
3936
3937 ixgbe_get_hw_control(adapter);
3938 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003939
Auke Kok9a799d72007-09-15 14:07:45 -07003940 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3941 ixgbe_configure_msix(adapter);
3942 else
3943 ixgbe_configure_msi_and_legacy(adapter);
3944
Don Skidmorec6ecf392010-12-03 03:31:51 +00003945 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3946 if (hw->mac.ops.enable_tx_laser &&
3947 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003948 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003949 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003950 hw->mac.ops.enable_tx_laser(hw);
3951
Auke Kok9a799d72007-09-15 14:07:45 -07003952 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003953 ixgbe_napi_enable_all(adapter);
3954
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003955 if (ixgbe_is_sfp(hw)) {
3956 ixgbe_sfp_link_config(adapter);
3957 } else {
3958 err = ixgbe_non_sfp_link_config(hw);
3959 if (err)
3960 e_err(probe, "link_config FAILED %d\n", err);
3961 }
3962
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003963 /* clear any pending interrupts, may auto mask */
3964 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003965 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003966
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003967 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003968 * If this adapter has a fan, check to see if we had a failure
3969 * before we enabled the interrupt.
3970 */
3971 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3972 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3973 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003974 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003975 }
3976
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003977 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003978 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003979
Auke Kok9a799d72007-09-15 14:07:45 -07003980 /* bring the link up in the watchdog, this could race with our first
3981 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003982 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3983 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003984 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003985
3986 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3987 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3988 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3989 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003990}
3991
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003992void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3993{
3994 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003995 /* put off any impending NetWatchDogTimeout */
3996 adapter->netdev->trans_start = jiffies;
3997
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003998 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003999 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004000 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004001 /*
4002 * If SR-IOV enabled then wait a bit before bringing the adapter
4003 * back up to give the VFs time to respond to the reset. The
4004 * two second wait is based upon the watchdog timer cycle in
4005 * the VF driver.
4006 */
4007 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4008 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004009 ixgbe_up(adapter);
4010 clear_bit(__IXGBE_RESETTING, &adapter->state);
4011}
4012
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004013void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004014{
4015 /* hardware has been reset, we need to reload some things */
4016 ixgbe_configure(adapter);
4017
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004018 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004019}
4020
4021void ixgbe_reset(struct ixgbe_adapter *adapter)
4022{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004023 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004024 int err;
4025
Alexander Duyck70864002011-04-27 09:13:56 +00004026 /* lock SFP init bit to prevent race conditions with the watchdog */
4027 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4028 usleep_range(1000, 2000);
4029
4030 /* clear all SFP and link config related flags while holding SFP_INIT */
4031 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4032 IXGBE_FLAG2_SFP_NEEDS_RESET);
4033 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4034
Don Skidmore8ca783a2009-05-26 20:40:47 -07004035 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004036 switch (err) {
4037 case 0:
4038 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004039 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004040 break;
4041 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004042 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004043 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004044 case IXGBE_ERR_EEPROM_VERSION:
4045 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004046 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004047 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004048 "your hardware. If you are experiencing problems "
4049 "please contact your Intel or hardware "
4050 "representative who provided you with this "
4051 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004052 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004053 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004054 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004055 }
Auke Kok9a799d72007-09-15 14:07:45 -07004056
Alexander Duyck70864002011-04-27 09:13:56 +00004057 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4058
Auke Kok9a799d72007-09-15 14:07:45 -07004059 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004060 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4061 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004062}
4063
Auke Kok9a799d72007-09-15 14:07:45 -07004064/**
4065 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004066 * @rx_ring: ring to free buffers from
4067 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004068static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004069{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004070 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004071 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 (!rx_ring->rx_buffer_info)
4076 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004077
Alexander Duyck84418e32010-08-19 13:40:54 +00004078 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004079 for (i = 0; i < rx_ring->count; i++) {
4080 struct ixgbe_rx_buffer *rx_buffer_info;
4081
4082 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4083 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004084 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004085 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004086 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004087 rx_buffer_info->dma = 0;
4088 }
4089 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004090 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004091 rx_buffer_info->skb = NULL;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004092 /* We need to clean up RSC frag lists */
4093 skb = ixgbe_merge_active_tail(skb);
4094 ixgbe_close_active_frag_list(skb);
4095 if (IXGBE_CB(skb)->delay_unmap) {
4096 dma_unmap_single(dev,
4097 IXGBE_CB(skb)->dma,
4098 rx_ring->rx_buf_len,
4099 DMA_FROM_DEVICE);
4100 IXGBE_CB(skb)->dma = 0;
4101 IXGBE_CB(skb)->delay_unmap = false;
4102 }
4103 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004104 }
4105 if (!rx_buffer_info->page)
4106 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004107 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004108 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004109 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004110 rx_buffer_info->page_dma = 0;
4111 }
Auke Kok9a799d72007-09-15 14:07:45 -07004112 put_page(rx_buffer_info->page);
4113 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004114 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004115 }
4116
4117 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4118 memset(rx_ring->rx_buffer_info, 0, size);
4119
4120 /* Zero out the descriptor ring */
4121 memset(rx_ring->desc, 0, rx_ring->size);
4122
4123 rx_ring->next_to_clean = 0;
4124 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004125}
4126
4127/**
4128 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004129 * @tx_ring: ring to be cleaned
4130 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004131static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004132{
4133 struct ixgbe_tx_buffer *tx_buffer_info;
4134 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004135 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004136
Alexander Duyck84418e32010-08-19 13:40:54 +00004137 /* ring already cleared, nothing to do */
4138 if (!tx_ring->tx_buffer_info)
4139 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004140
Alexander Duyck84418e32010-08-19 13:40:54 +00004141 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004142 for (i = 0; i < tx_ring->count; i++) {
4143 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004144 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004145 }
4146
4147 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4148 memset(tx_ring->tx_buffer_info, 0, size);
4149
4150 /* Zero out the descriptor ring */
4151 memset(tx_ring->desc, 0, tx_ring->size);
4152
4153 tx_ring->next_to_use = 0;
4154 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004155}
4156
4157/**
Auke Kok9a799d72007-09-15 14:07:45 -07004158 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4159 * @adapter: board private structure
4160 **/
4161static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4162{
4163 int i;
4164
4165 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004166 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004167}
4168
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004169/**
4170 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4171 * @adapter: board private structure
4172 **/
4173static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4174{
4175 int i;
4176
4177 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004178 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004179}
4180
Alexander Duycke4911d52011-05-11 07:18:52 +00004181static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4182{
4183 struct hlist_node *node, *node2;
4184 struct ixgbe_fdir_filter *filter;
4185
4186 spin_lock(&adapter->fdir_perfect_lock);
4187
4188 hlist_for_each_entry_safe(filter, node, node2,
4189 &adapter->fdir_filter_list, fdir_node) {
4190 hlist_del(&filter->fdir_node);
4191 kfree(filter);
4192 }
4193 adapter->fdir_filter_count = 0;
4194
4195 spin_unlock(&adapter->fdir_perfect_lock);
4196}
4197
Auke Kok9a799d72007-09-15 14:07:45 -07004198void ixgbe_down(struct ixgbe_adapter *adapter)
4199{
4200 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004201 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004202 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004203 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004204
4205 /* signal that we are down to the interrupt handler */
4206 set_bit(__IXGBE_DOWN, &adapter->state);
4207
4208 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004209 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4210 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004211
Yi Zou2d39d572011-01-06 14:29:56 +00004212 /* disable all enabled rx queues */
4213 for (i = 0; i < adapter->num_rx_queues; i++)
4214 /* this call also flushes the previous write */
4215 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4216
Don Skidmore032b4322011-03-18 09:32:53 +00004217 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004218
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004219 netif_tx_stop_all_queues(netdev);
4220
Alexander Duyck70864002011-04-27 09:13:56 +00004221 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004222 netif_carrier_off(netdev);
4223 netif_tx_disable(netdev);
4224
4225 ixgbe_irq_disable(adapter);
4226
4227 ixgbe_napi_disable_all(adapter);
4228
Alexander Duyckd034acf2011-04-27 09:25:34 +00004229 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4230 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004231 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4232
4233 del_timer_sync(&adapter->service_timer);
4234
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004235 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004236 /* Clear EITR Select mapping */
4237 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4238
4239 /* Mark all the VFs as inactive */
4240 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004241 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004242
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004243 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004244 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004245
Auke Kok9a799d72007-09-15 14:07:45 -07004246 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004247 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004248 }
4249
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004250 /* disable transmits in the hardware now that interrupts are off */
4251 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004252 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004253 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004254 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004255
4256 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004257 switch (hw->mac.type) {
4258 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004259 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004260 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004261 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4262 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004263 break;
4264 default:
4265 break;
4266 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004267
Paul Larson6f4a0e42008-06-24 17:00:56 -07004268 if (!pci_channel_offline(adapter->pdev))
4269 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004270
4271 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4272 if (hw->mac.ops.disable_tx_laser &&
4273 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004274 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004275 (hw->mac.type == ixgbe_mac_82599EB))))
4276 hw->mac.ops.disable_tx_laser(hw);
4277
Auke Kok9a799d72007-09-15 14:07:45 -07004278 ixgbe_clean_all_tx_rings(adapter);
4279 ixgbe_clean_all_rx_rings(adapter);
4280
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004281#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004282 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004283 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004284#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004285}
4286
Auke Kok9a799d72007-09-15 14:07:45 -07004287/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004288 * ixgbe_poll - NAPI Rx polling callback
4289 * @napi: structure for representing this polling device
4290 * @budget: how many packets driver is allowed to clean
4291 *
4292 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004293 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004294static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004295{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004296 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004297 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004298 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004299 struct ixgbe_ring *ring;
4300 int per_ring_budget;
4301 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004302
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004303#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004304 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4305 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004306#endif
4307
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004308 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4309 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004310
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004311 /* attempt to distribute budget to each queue fairly, but don't allow
4312 * the budget to go below 1 because we'll exit polling */
4313 if (q_vector->rx.count > 1)
4314 per_ring_budget = max(budget/q_vector->rx.count, 1);
4315 else
4316 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004317
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004318 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4319 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4320 per_ring_budget);
4321
4322 /* If all work not completed, return budget and keep polling */
4323 if (!clean_complete)
4324 return budget;
4325
4326 /* all work done, exit the polling mode */
4327 napi_complete(napi);
4328 if (adapter->rx_itr_setting & 1)
4329 ixgbe_set_itr(q_vector);
4330 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4331 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4332
4333 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004334}
4335
4336/**
4337 * ixgbe_tx_timeout - Respond to a Tx Hang
4338 * @netdev: network interface device structure
4339 **/
4340static void ixgbe_tx_timeout(struct net_device *netdev)
4341{
4342 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4343
4344 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004345 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004346}
4347
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004348/**
4349 * ixgbe_set_rss_queues: Allocate queues for RSS
4350 * @adapter: board private structure to initialize
4351 *
4352 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4353 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4354 *
4355 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004356static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4357{
4358 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004359 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004360
4361 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004362 f->mask = 0xF;
4363 adapter->num_rx_queues = f->indices;
4364 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004365 ret = true;
4366 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004367 ret = false;
4368 }
4369
4370 return ret;
4371}
4372
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004373/**
4374 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4375 * @adapter: board private structure to initialize
4376 *
4377 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4378 * to the original CPU that initiated the Tx session. This runs in addition
4379 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4380 * Rx load across CPUs using RSS.
4381 *
4382 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004383static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004384{
4385 bool ret = false;
4386 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4387
4388 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4389 f_fdir->mask = 0;
4390
Alexander Duyck24ddd962012-02-10 02:08:32 +00004391 /*
4392 * Use RSS in addition to Flow Director to ensure the best
4393 * distribution of flows across cores, even when an FDIR flow
4394 * isn't matched.
4395 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004396 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4397 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004398 adapter->num_tx_queues = f_fdir->indices;
4399 adapter->num_rx_queues = f_fdir->indices;
4400 ret = true;
4401 } else {
4402 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004403 }
4404 return ret;
4405}
4406
Yi Zou0331a832009-05-17 12:33:52 +00004407#ifdef IXGBE_FCOE
4408/**
4409 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4410 * @adapter: board private structure to initialize
4411 *
4412 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4413 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4414 * rx queues out of the max number of rx queues, instead, it is used as the
4415 * index of the first rx queue used by FCoE.
4416 *
4417 **/
4418static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4419{
Yi Zou0331a832009-05-17 12:33:52 +00004420 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4421
John Fastabende5b64632011-03-08 03:44:52 +00004422 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4423 return false;
4424
John Fastabende901acd2011-04-26 07:26:08 +00004425 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004426
John Fastabende901acd2011-04-26 07:26:08 +00004427 adapter->num_rx_queues = 1;
4428 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004429
John Fastabende901acd2011-04-26 07:26:08 +00004430 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4431 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004432 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004433 ixgbe_set_fdir_queues(adapter);
4434 else
4435 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004436 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004437
John Fastabende901acd2011-04-26 07:26:08 +00004438 /* adding FCoE rx rings to the end */
4439 f->mask = adapter->num_rx_queues;
4440 adapter->num_rx_queues += f->indices;
4441 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004442
John Fastabende5b64632011-03-08 03:44:52 +00004443 return true;
4444}
4445#endif /* IXGBE_FCOE */
4446
John Fastabende901acd2011-04-26 07:26:08 +00004447/* Artificial max queue cap per traffic class in DCB mode */
4448#define DCB_QUEUE_CAP 8
4449
John Fastabende5b64632011-03-08 03:44:52 +00004450#ifdef CONFIG_IXGBE_DCB
4451static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4452{
John Fastabende901acd2011-04-26 07:26:08 +00004453 int per_tc_q, q, i, offset = 0;
4454 struct net_device *dev = adapter->netdev;
4455 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004456
John Fastabende901acd2011-04-26 07:26:08 +00004457 if (!tcs)
4458 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004459
John Fastabende901acd2011-04-26 07:26:08 +00004460 /* Map queue offset and counts onto allocated tx queues */
4461 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4462 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004463
John Fastabend8b1c0b22011-05-03 02:26:48 +00004464 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004465 netdev_set_tc_queue(dev, i, q, offset);
4466 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004467 }
4468
John Fastabende901acd2011-04-26 07:26:08 +00004469 adapter->num_tx_queues = q * tcs;
4470 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004471
4472#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004473 /* FCoE enabled queues require special configuration indexed
4474 * by feature specific indices and mask. Here we map FCoE
4475 * indices onto the DCB queue pairs allowing FCoE to own
4476 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004477 */
John Fastabende901acd2011-04-26 07:26:08 +00004478 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4479 int tc;
4480 struct ixgbe_ring_feature *f =
4481 &adapter->ring_feature[RING_F_FCOE];
4482
4483 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4484 f->indices = dev->tc_to_txq[tc].count;
4485 f->mask = dev->tc_to_txq[tc].offset;
4486 }
John Fastabende5b64632011-03-08 03:44:52 +00004487#endif
4488
John Fastabende901acd2011-04-26 07:26:08 +00004489 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004490}
John Fastabende5b64632011-03-08 03:44:52 +00004491#endif
Yi Zou0331a832009-05-17 12:33:52 +00004492
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004493/**
4494 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4495 * @adapter: board private structure to initialize
4496 *
4497 * IOV doesn't actually use anything, so just NAK the
4498 * request for now and let the other queue routines
4499 * figure out what to do.
4500 */
4501static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4502{
4503 return false;
4504}
4505
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004506/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004507 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004508 * @adapter: board private structure to initialize
4509 *
4510 * This is the top level queue allocation routine. The order here is very
4511 * important, starting with the "most" number of features turned on at once,
4512 * and ending with the smallest set of features. This way large combinations
4513 * can be allocated if they're turned on, and smaller combinations are the
4514 * fallthrough conditions.
4515 *
4516 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004517static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004518{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004519 /* Start with base case */
4520 adapter->num_rx_queues = 1;
4521 adapter->num_tx_queues = 1;
4522 adapter->num_rx_pools = adapter->num_rx_queues;
4523 adapter->num_rx_queues_per_pool = 1;
4524
4525 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004526 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004527
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004528#ifdef CONFIG_IXGBE_DCB
4529 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004530 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004531
4532#endif
John Fastabende5b64632011-03-08 03:44:52 +00004533#ifdef IXGBE_FCOE
4534 if (ixgbe_set_fcoe_queues(adapter))
4535 goto done;
4536
4537#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004538 if (ixgbe_set_fdir_queues(adapter))
4539 goto done;
4540
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004541 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004542 goto done;
4543
4544 /* fallback to base case */
4545 adapter->num_rx_queues = 1;
4546 adapter->num_tx_queues = 1;
4547
4548done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004549 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4550 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4551 return 0;
4552
Ben Hutchings847f53f2010-09-27 08:28:56 +00004553 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004554 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004555 return netif_set_real_num_rx_queues(adapter->netdev,
4556 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004557}
4558
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004559static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004560 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004561{
4562 int err, vector_threshold;
4563
4564 /* We'll want at least 3 (vector_threshold):
4565 * 1) TxQ[0] Cleanup
4566 * 2) RxQ[0] Cleanup
4567 * 3) Other (Link Status Change, etc.)
4568 * 4) TCP Timer (optional)
4569 */
4570 vector_threshold = MIN_MSIX_COUNT;
4571
Alexander Duyck24ddd962012-02-10 02:08:32 +00004572 /*
4573 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004574 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4575 * Right now, we simply care about how many we'll get; we'll
4576 * set them up later while requesting irq's.
4577 */
4578 while (vectors >= vector_threshold) {
4579 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004580 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004581 if (!err) /* Success in acquiring all requested vectors. */
4582 break;
4583 else if (err < 0)
4584 vectors = 0; /* Nasty failure, quit now */
4585 else /* err == number of vectors we should try again with */
4586 vectors = err;
4587 }
4588
4589 if (vectors < vector_threshold) {
4590 /* Can't allocate enough MSI-X interrupts? Oh well.
4591 * This just means we'll go with either a single MSI
4592 * vector or fall back to legacy interrupts.
4593 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004594 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4595 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004596 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4597 kfree(adapter->msix_entries);
4598 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004599 } else {
4600 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004601 /*
4602 * Adjust for only the vectors we'll use, which is minimum
4603 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4604 * vectors we were allocated.
4605 */
4606 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004607 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004608 }
4609}
4610
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004611/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004612 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004613 * @adapter: board private structure to initialize
4614 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004615 * Cache the descriptor ring offsets for RSS to the assigned rings.
4616 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004617 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004618static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004619{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004620 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004621
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004622 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4623 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004624
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004625 for (i = 0; i < adapter->num_rx_queues; i++)
4626 adapter->rx_ring[i]->reg_idx = i;
4627 for (i = 0; i < adapter->num_tx_queues; i++)
4628 adapter->tx_ring[i]->reg_idx = i;
4629
4630 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004631}
4632
4633#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004634
4635/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004636static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4637 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004638{
4639 struct net_device *dev = adapter->netdev;
4640 struct ixgbe_hw *hw = &adapter->hw;
4641 u8 num_tcs = netdev_get_num_tc(dev);
4642
4643 *tx = 0;
4644 *rx = 0;
4645
4646 switch (hw->mac.type) {
4647 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004648 *tx = tc << 2;
4649 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004650 break;
4651 case ixgbe_mac_82599EB:
4652 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004653 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004654 if (tc < 3) {
4655 *tx = tc << 5;
4656 *rx = tc << 4;
4657 } else if (tc < 5) {
4658 *tx = ((tc + 2) << 4);
4659 *rx = tc << 4;
4660 } else if (tc < num_tcs) {
4661 *tx = ((tc + 8) << 3);
4662 *rx = tc << 4;
4663 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004664 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004665 *rx = tc << 5;
4666 switch (tc) {
4667 case 0:
4668 *tx = 0;
4669 break;
4670 case 1:
4671 *tx = 64;
4672 break;
4673 case 2:
4674 *tx = 96;
4675 break;
4676 case 3:
4677 *tx = 112;
4678 break;
4679 default:
4680 break;
4681 }
4682 }
4683 break;
4684 default:
4685 break;
4686 }
4687}
4688
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004689/**
4690 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4691 * @adapter: board private structure to initialize
4692 *
4693 * Cache the descriptor ring offsets for DCB to the assigned rings.
4694 *
4695 **/
4696static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4697{
John Fastabende5b64632011-03-08 03:44:52 +00004698 struct net_device *dev = adapter->netdev;
4699 int i, j, k;
4700 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004701
John Fastabend8b1c0b22011-05-03 02:26:48 +00004702 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004703 return false;
4704
John Fastabende5b64632011-03-08 03:44:52 +00004705 for (i = 0, k = 0; i < num_tcs; i++) {
4706 unsigned int tx_s, rx_s;
4707 u16 count = dev->tc_to_txq[i].count;
4708
4709 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4710 for (j = 0; j < count; j++, k++) {
4711 adapter->tx_ring[k]->reg_idx = tx_s + j;
4712 adapter->rx_ring[k]->reg_idx = rx_s + j;
4713 adapter->tx_ring[k]->dcb_tc = i;
4714 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004715 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004716 }
John Fastabende5b64632011-03-08 03:44:52 +00004717
4718 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004719}
4720#endif
4721
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004722/**
4723 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4724 * @adapter: board private structure to initialize
4725 *
4726 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4727 *
4728 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004729static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004730{
4731 int i;
4732 bool ret = false;
4733
Alexander Duyck03ecf912011-05-20 07:36:17 +00004734 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4735 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004736 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004737 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004738 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004739 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004740 ret = true;
4741 }
4742
4743 return ret;
4744}
4745
Yi Zou0331a832009-05-17 12:33:52 +00004746#ifdef IXGBE_FCOE
4747/**
4748 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4749 * @adapter: board private structure to initialize
4750 *
4751 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4752 *
4753 */
4754static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4755{
Yi Zou0331a832009-05-17 12:33:52 +00004756 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004757 int i;
4758 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004759
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004760 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4761 return false;
4762
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004763 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004764 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004765 ixgbe_cache_ring_fdir(adapter);
4766 else
4767 ixgbe_cache_ring_rss(adapter);
4768
4769 fcoe_rx_i = f->mask;
4770 fcoe_tx_i = f->mask;
4771 }
4772 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4773 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4774 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4775 }
4776 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004777}
4778
4779#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004780/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004781 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4782 * @adapter: board private structure to initialize
4783 *
4784 * SR-IOV doesn't use any descriptor rings but changes the default if
4785 * no other mapping is used.
4786 *
4787 */
4788static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4789{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004790 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4791 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004792 if (adapter->num_vfs)
4793 return true;
4794 else
4795 return false;
4796}
4797
4798/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004799 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4800 * @adapter: board private structure to initialize
4801 *
4802 * Once we know the feature-set enabled for the device, we'll cache
4803 * the register offset the descriptor ring is assigned to.
4804 *
4805 * Note, the order the various feature calls is important. It must start with
4806 * the "most" features enabled at the same time, then trickle down to the
4807 * least amount of features turned on at once.
4808 **/
4809static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4810{
4811 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004812 adapter->rx_ring[0]->reg_idx = 0;
4813 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004814
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004815 if (ixgbe_cache_ring_sriov(adapter))
4816 return;
4817
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004818#ifdef CONFIG_IXGBE_DCB
4819 if (ixgbe_cache_ring_dcb(adapter))
4820 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004821#endif
John Fastabende5b64632011-03-08 03:44:52 +00004822
4823#ifdef IXGBE_FCOE
4824 if (ixgbe_cache_ring_fcoe(adapter))
4825 return;
4826#endif /* IXGBE_FCOE */
4827
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004828 if (ixgbe_cache_ring_fdir(adapter))
4829 return;
4830
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004831 if (ixgbe_cache_ring_rss(adapter))
4832 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004833}
4834
Auke Kok9a799d72007-09-15 14:07:45 -07004835/**
4836 * ixgbe_alloc_queues - Allocate memory for all rings
4837 * @adapter: board private structure to initialize
4838 *
4839 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004840 * number of queues at compile-time. The polling_netdev array is
4841 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004842 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004843static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004844{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004845 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004846
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004847 if (nid < 0 || !node_online(nid))
4848 nid = first_online_node;
4849
4850 for (; tx < adapter->num_tx_queues; tx++) {
4851 struct ixgbe_ring *ring;
4852
4853 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004854 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004855 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004856 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004857 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004858 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004859 ring->queue_index = tx;
4860 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004861 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004862 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004863
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004864 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004865 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004866
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004867 for (; rx < adapter->num_rx_queues; rx++) {
4868 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004869
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004870 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004871 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004872 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004873 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004874 goto err_allocation;
4875 ring->count = adapter->rx_ring_count;
4876 ring->queue_index = rx;
4877 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004878 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004879 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004880
Alexander Duyck8a0da212012-01-31 02:59:49 +00004881 /*
4882 * 82599 errata, UDP frames with a 0 checksum can be marked as
4883 * checksum errors.
4884 */
4885 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4886 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4887
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004888 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004889 }
4890
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004891 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004892
4893 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004894
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004895err_allocation:
4896 while (tx)
4897 kfree(adapter->tx_ring[--tx]);
4898
4899 while (rx)
4900 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004901 return -ENOMEM;
4902}
4903
4904/**
4905 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4906 * @adapter: board private structure to initialize
4907 *
4908 * Attempt to configure the interrupts using the best available
4909 * capabilities of the hardware and the kernel.
4910 **/
Al Virofeea6a52008-11-27 15:34:07 -08004911static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004912{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004913 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004914 int err = 0;
4915 int vector, v_budget;
4916
4917 /*
4918 * It's easy to be greedy for MSI-X vectors, but it really
4919 * doesn't do us much good if we have a lot more vectors
4920 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004921 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004922 */
4923 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004924 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004925
4926 /*
4927 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004928 * hw.mac->max_msix_vectors vectors. With features
4929 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4930 * descriptor queues supported by our device. Thus, we cap it off in
4931 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004932 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004933 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004934
4935 /* A failure in MSI-X entry allocation isn't fatal, but it does
4936 * mean we disable MSI-X capabilities of the adapter. */
4937 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004938 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004939 if (adapter->msix_entries) {
4940 for (vector = 0; vector < v_budget; vector++)
4941 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004942
Alexander Duyck7a921c92009-05-06 10:43:28 +00004943 ixgbe_acquire_msix_vectors(adapter, v_budget);
4944
4945 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4946 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004947 }
David S. Miller26d27842010-05-03 15:18:22 -07004948
Alexander Duyck7a921c92009-05-06 10:43:28 +00004949 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4950 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004951 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004952 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004953 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004954 "queues are disabled. Disabling Flow Director\n");
4955 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004956 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004957 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004958 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4959 ixgbe_disable_sriov(adapter);
4960
Ben Hutchings847f53f2010-09-27 08:28:56 +00004961 err = ixgbe_set_num_queues(adapter);
4962 if (err)
4963 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004964
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004965 err = pci_enable_msi(adapter->pdev);
4966 if (!err) {
4967 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4968 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004969 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4970 "Unable to allocate MSI interrupt, "
4971 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004972 /* reset err */
4973 err = 0;
4974 }
4975
4976out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004977 return err;
4978}
4979
Alexander Duyck7a921c92009-05-06 10:43:28 +00004980/**
4981 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4982 * @adapter: board private structure to initialize
4983 *
4984 * We allocate one q_vector per queue interrupt. If allocation fails we
4985 * return -ENOMEM.
4986 **/
4987static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4988{
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004989 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004990 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004991
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004992 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004993 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004994 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004995 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004996
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004997 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004998 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004999 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005000 if (!q_vector)
5001 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005002 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005003 if (!q_vector)
5004 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005005
Alexander Duyck7a921c92009-05-06 10:43:28 +00005006 q_vector->adapter = adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005007 q_vector->v_idx = v_idx;
5008
Alexander Duyck207867f2011-07-15 03:05:37 +00005009 /* Allocate the affinity_hint cpumask, configure the mask */
5010 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
5011 goto err_out;
5012 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005013 netif_napi_add(adapter->netdev, &q_vector->napi,
5014 ixgbe_poll, 64);
5015 adapter->q_vector[v_idx] = q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005016 }
5017
5018 return 0;
5019
5020err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005021 while (v_idx) {
5022 v_idx--;
5023 q_vector = adapter->q_vector[v_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005024 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00005025 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005026 kfree(q_vector);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005027 adapter->q_vector[v_idx] = NULL;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005028 }
5029 return -ENOMEM;
5030}
5031
5032/**
5033 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5034 * @adapter: board private structure to initialize
5035 *
5036 * This function frees the memory allocated to the q_vectors. In addition if
5037 * NAPI is enabled it will delete any references to the NAPI struct prior
5038 * to freeing the q_vector.
5039 **/
5040static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5041{
Alexander Duyck207867f2011-07-15 03:05:37 +00005042 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005043
Alexander Duyck91281fd2009-06-04 16:00:27 +00005044 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005045 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005046 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005047 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005048
Alexander Duyck207867f2011-07-15 03:05:37 +00005049 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
5050 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
5051 adapter->q_vector[v_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005052 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00005053 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005054 kfree(q_vector);
5055 }
5056}
5057
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005058static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005059{
5060 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5061 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5062 pci_disable_msix(adapter->pdev);
5063 kfree(adapter->msix_entries);
5064 adapter->msix_entries = NULL;
5065 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5066 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5067 pci_disable_msi(adapter->pdev);
5068 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005069}
5070
5071/**
5072 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5073 * @adapter: board private structure to initialize
5074 *
5075 * We determine which interrupt scheme to use based on...
5076 * - Kernel support (MSI, MSI-X)
5077 * - which can be user-defined (via MODULE_PARAM)
5078 * - Hardware queue count (num_*_queues)
5079 * - defined by miscellaneous hardware support/features (RSS, etc.)
5080 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005081int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005082{
5083 int err;
5084
5085 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005086 err = ixgbe_set_num_queues(adapter);
5087 if (err)
5088 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005089
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005090 err = ixgbe_set_interrupt_capability(adapter);
5091 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005092 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005093 goto err_set_interrupt;
5094 }
5095
Alexander Duyck7a921c92009-05-06 10:43:28 +00005096 err = ixgbe_alloc_q_vectors(adapter);
5097 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005098 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005099 goto err_alloc_q_vectors;
5100 }
5101
5102 err = ixgbe_alloc_queues(adapter);
5103 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005104 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005105 goto err_alloc_queues;
5106 }
5107
Emil Tantilov849c4542010-06-03 16:53:41 +00005108 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005109 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5110 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005111
5112 set_bit(__IXGBE_DOWN, &adapter->state);
5113
5114 return 0;
5115
Alexander Duyck7a921c92009-05-06 10:43:28 +00005116err_alloc_queues:
5117 ixgbe_free_q_vectors(adapter);
5118err_alloc_q_vectors:
5119 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005120err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005121 return err;
5122}
5123
5124/**
5125 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5126 * @adapter: board private structure to clear interrupt scheme on
5127 *
5128 * We go through and clear interrupt specific resources and reset the structure
5129 * to pre-load conditions
5130 **/
5131void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5132{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005133 int i;
5134
5135 for (i = 0; i < adapter->num_tx_queues; i++) {
5136 kfree(adapter->tx_ring[i]);
5137 adapter->tx_ring[i] = NULL;
5138 }
5139 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005140 struct ixgbe_ring *ring = adapter->rx_ring[i];
5141
5142 /* ixgbe_get_stats64() might access this ring, we must wait
5143 * a grace period before freeing it.
5144 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005145 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005146 adapter->rx_ring[i] = NULL;
5147 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005148
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005149 adapter->num_tx_queues = 0;
5150 adapter->num_rx_queues = 0;
5151
Alexander Duyck7a921c92009-05-06 10:43:28 +00005152 ixgbe_free_q_vectors(adapter);
5153 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005154}
5155
5156/**
5157 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5158 * @adapter: board private structure to initialize
5159 *
5160 * ixgbe_sw_init initializes the Adapter private data structure.
5161 * Fields are initialized based on PCI device information and
5162 * OS network device settings (MTU size).
5163 **/
5164static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5165{
5166 struct ixgbe_hw *hw = &adapter->hw;
5167 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005168 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005169#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005170 int j;
5171 struct tc_configuration *tc;
5172#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005173
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005174 /* PCI config space info */
5175
5176 hw->vendor_id = pdev->vendor;
5177 hw->device_id = pdev->device;
5178 hw->revision_id = pdev->revision;
5179 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5180 hw->subsystem_device_id = pdev->subsystem_device;
5181
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005182 /* Set capability flags */
5183 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5184 adapter->ring_feature[RING_F_RSS].indices = rss;
5185 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005186 switch (hw->mac.type) {
5187 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005188 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5189 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005190 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005191 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005192 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005193 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5194 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005195 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005196 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5197 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005198 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5199 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005200 /* Flow Director hash filters enabled */
5201 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5202 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005203 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005204 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005205 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005206#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005207 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5208 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5209 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005210#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005211 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005212 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005213#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005214#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005215 break;
5216 default:
5217 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005218 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005219
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005220 /* n-tuple support exists, always init our spinlock */
5221 spin_lock_init(&adapter->fdir_perfect_lock);
5222
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005223#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005224 switch (hw->mac.type) {
5225 case ixgbe_mac_X540:
5226 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5227 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5228 break;
5229 default:
5230 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5231 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5232 break;
5233 }
5234
Alexander Duyck2f90b862008-11-20 20:52:10 -08005235 /* Configure DCB traffic classes */
5236 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5237 tc = &adapter->dcb_cfg.tc_config[j];
5238 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5239 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5240 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5241 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5242 tc->dcb_pfc = pfc_disabled;
5243 }
John Fastabend4de2a022011-09-27 03:52:01 +00005244
5245 /* Initialize default user to priority mapping, UPx->TC0 */
5246 tc = &adapter->dcb_cfg.tc_config[0];
5247 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5248 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5249
Alexander Duyck2f90b862008-11-20 20:52:10 -08005250 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5251 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005252 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005253 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005254 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005255 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005256 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005257
5258#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005259
5260 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005261 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005262 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005263#ifdef CONFIG_DCB
5264 adapter->last_lfc_mode = hw->fc.current_mode;
5265#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005266 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005267 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5268 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005269 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005270
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005271 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005272 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005273 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005274
5275 /* set defaults for eitr in MegaBytes */
5276 adapter->eitr_low = 10;
5277 adapter->eitr_high = 20;
5278
5279 /* set default ring sizes */
5280 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5281 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5282
Alexander Duyckbd198052011-06-11 01:45:08 +00005283 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005284 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005285
Auke Kok9a799d72007-09-15 14:07:45 -07005286 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005287 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005288 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005289 return -EIO;
5290 }
5291
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005292 /* get assigned NUMA node */
5293 adapter->node = dev_to_node(&pdev->dev);
5294
Auke Kok9a799d72007-09-15 14:07:45 -07005295 set_bit(__IXGBE_DOWN, &adapter->state);
5296
5297 return 0;
5298}
5299
5300/**
5301 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005302 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005303 *
5304 * Return 0 on success, negative on failure
5305 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005306int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005307{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005308 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005309 int size;
5310
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005311 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005312 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005313 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005314 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005315 if (!tx_ring->tx_buffer_info)
5316 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005317
5318 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005319 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005320 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005321
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005322 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005323 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005324 if (!tx_ring->desc)
5325 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005326
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005327 tx_ring->next_to_use = 0;
5328 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005329 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005330
5331err:
5332 vfree(tx_ring->tx_buffer_info);
5333 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005334 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005335 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005336}
5337
5338/**
Alexander Duyck69888672008-09-11 20:05:39 -07005339 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5340 * @adapter: board private structure
5341 *
5342 * If this function returns with an error, then it's possible one or
5343 * more of the rings is populated (while the rest are not). It is the
5344 * callers duty to clean those orphaned rings.
5345 *
5346 * Return 0 on success, negative on failure
5347 **/
5348static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5349{
5350 int i, err = 0;
5351
5352 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005353 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005354 if (!err)
5355 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005356 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005357 break;
5358 }
5359
5360 return err;
5361}
5362
5363/**
Auke Kok9a799d72007-09-15 14:07:45 -07005364 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005365 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005366 *
5367 * Returns 0 on success, negative on failure
5368 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005369int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005370{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005371 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005372 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005373
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005374 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005375 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005376 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005377 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005378 if (!rx_ring->rx_buffer_info)
5379 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005380
Auke Kok9a799d72007-09-15 14:07:45 -07005381 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005382 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5383 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005384
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005385 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005386 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005387
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005388 if (!rx_ring->desc)
5389 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005390
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005391 rx_ring->next_to_clean = 0;
5392 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005393
5394 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005395err:
5396 vfree(rx_ring->rx_buffer_info);
5397 rx_ring->rx_buffer_info = NULL;
5398 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005399 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005400}
5401
5402/**
Alexander Duyck69888672008-09-11 20:05:39 -07005403 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5404 * @adapter: board private structure
5405 *
5406 * If this function returns with an error, then it's possible one or
5407 * more of the rings is populated (while the rest are not). It is the
5408 * callers duty to clean those orphaned rings.
5409 *
5410 * Return 0 on success, negative on failure
5411 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005412static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5413{
5414 int i, err = 0;
5415
5416 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005417 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005418 if (!err)
5419 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005420 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005421 break;
5422 }
5423
5424 return err;
5425}
5426
5427/**
Auke Kok9a799d72007-09-15 14:07:45 -07005428 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005429 * @tx_ring: Tx descriptor ring for a specific queue
5430 *
5431 * Free all transmit software resources
5432 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005433void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005434{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005435 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005436
5437 vfree(tx_ring->tx_buffer_info);
5438 tx_ring->tx_buffer_info = NULL;
5439
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005440 /* if not set, then don't free */
5441 if (!tx_ring->desc)
5442 return;
5443
5444 dma_free_coherent(tx_ring->dev, tx_ring->size,
5445 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005446
5447 tx_ring->desc = NULL;
5448}
5449
5450/**
5451 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5452 * @adapter: board private structure
5453 *
5454 * Free all transmit software resources
5455 **/
5456static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5457{
5458 int i;
5459
5460 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005461 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005462 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005463}
5464
5465/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005466 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005467 * @rx_ring: ring to clean the resources from
5468 *
5469 * Free all receive software resources
5470 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005471void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005472{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005473 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005474
5475 vfree(rx_ring->rx_buffer_info);
5476 rx_ring->rx_buffer_info = NULL;
5477
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005478 /* if not set, then don't free */
5479 if (!rx_ring->desc)
5480 return;
5481
5482 dma_free_coherent(rx_ring->dev, rx_ring->size,
5483 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005484
5485 rx_ring->desc = NULL;
5486}
5487
5488/**
5489 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5490 * @adapter: board private structure
5491 *
5492 * Free all receive software resources
5493 **/
5494static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5495{
5496 int i;
5497
5498 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005499 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005500 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005501}
5502
5503/**
Auke Kok9a799d72007-09-15 14:07:45 -07005504 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5505 * @netdev: network interface device structure
5506 * @new_mtu: new value for maximum frame size
5507 *
5508 * Returns 0 on success, negative on failure
5509 **/
5510static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5511{
5512 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005513 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005514 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5515
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005516 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005517 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5518 hw->mac.type != ixgbe_mac_X540) {
5519 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5520 return -EINVAL;
5521 } else {
5522 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5523 return -EINVAL;
5524 }
Auke Kok9a799d72007-09-15 14:07:45 -07005525
Emil Tantilov396e7992010-07-01 20:05:12 +00005526 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005527 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005528 netdev->mtu = new_mtu;
5529
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005530 if (netif_running(netdev))
5531 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005532
5533 return 0;
5534}
5535
5536/**
5537 * ixgbe_open - Called when a network interface is made active
5538 * @netdev: network interface device structure
5539 *
5540 * Returns 0 on success, negative value on failure
5541 *
5542 * The open entry point is called when a network interface is made
5543 * active by the system (IFF_UP). At this point all resources needed
5544 * for transmit and receive operations are allocated, the interrupt
5545 * handler is registered with the OS, the watchdog timer is started,
5546 * and the stack is notified that the interface is ready.
5547 **/
5548static int ixgbe_open(struct net_device *netdev)
5549{
5550 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5551 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005552
Auke Kok4bebfaa2008-02-11 09:26:01 -08005553 /* disallow open during test */
5554 if (test_bit(__IXGBE_TESTING, &adapter->state))
5555 return -EBUSY;
5556
Jesse Brandeburg54386462009-04-17 20:44:27 +00005557 netif_carrier_off(netdev);
5558
Auke Kok9a799d72007-09-15 14:07:45 -07005559 /* allocate transmit descriptors */
5560 err = ixgbe_setup_all_tx_resources(adapter);
5561 if (err)
5562 goto err_setup_tx;
5563
Auke Kok9a799d72007-09-15 14:07:45 -07005564 /* allocate receive descriptors */
5565 err = ixgbe_setup_all_rx_resources(adapter);
5566 if (err)
5567 goto err_setup_rx;
5568
5569 ixgbe_configure(adapter);
5570
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005571 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005572 if (err)
5573 goto err_req_irq;
5574
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005575 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005576
5577 return 0;
5578
Auke Kok9a799d72007-09-15 14:07:45 -07005579err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005580err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005581 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005582err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005583 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005584 ixgbe_reset(adapter);
5585
5586 return err;
5587}
5588
5589/**
5590 * ixgbe_close - Disables a network interface
5591 * @netdev: network interface device structure
5592 *
5593 * Returns 0, this is not allowed to fail
5594 *
5595 * The close entry point is called when an interface is de-activated
5596 * by the OS. The hardware is still under the drivers control, but
5597 * needs to be disabled. A global MAC reset is issued to stop the
5598 * hardware, and all transmit and receive resources are freed.
5599 **/
5600static int ixgbe_close(struct net_device *netdev)
5601{
5602 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005603
5604 ixgbe_down(adapter);
5605 ixgbe_free_irq(adapter);
5606
Alexander Duycke4911d52011-05-11 07:18:52 +00005607 ixgbe_fdir_filter_exit(adapter);
5608
Auke Kok9a799d72007-09-15 14:07:45 -07005609 ixgbe_free_all_tx_resources(adapter);
5610 ixgbe_free_all_rx_resources(adapter);
5611
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005612 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005613
5614 return 0;
5615}
5616
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005617#ifdef CONFIG_PM
5618static int ixgbe_resume(struct pci_dev *pdev)
5619{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005620 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5621 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005622 u32 err;
5623
5624 pci_set_power_state(pdev, PCI_D0);
5625 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005626 /*
5627 * pci_restore_state clears dev->state_saved so call
5628 * pci_save_state to restore it.
5629 */
5630 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005631
5632 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005633 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005634 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005635 return err;
5636 }
5637 pci_set_master(pdev);
5638
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005639 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005640
5641 err = ixgbe_init_interrupt_scheme(adapter);
5642 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005643 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005644 return err;
5645 }
5646
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005647 ixgbe_reset(adapter);
5648
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005649 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5650
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005651 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005652 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005653 if (err)
5654 return err;
5655 }
5656
5657 netif_device_attach(netdev);
5658
5659 return 0;
5660}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005661#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005662
5663static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005664{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005665 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5666 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005667 struct ixgbe_hw *hw = &adapter->hw;
5668 u32 ctrl, fctrl;
5669 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005670#ifdef CONFIG_PM
5671 int retval = 0;
5672#endif
5673
5674 netif_device_detach(netdev);
5675
5676 if (netif_running(netdev)) {
5677 ixgbe_down(adapter);
5678 ixgbe_free_irq(adapter);
5679 ixgbe_free_all_tx_resources(adapter);
5680 ixgbe_free_all_rx_resources(adapter);
5681 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005682
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005683 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005684#ifdef CONFIG_DCB
5685 kfree(adapter->ixgbe_ieee_pfc);
5686 kfree(adapter->ixgbe_ieee_ets);
5687#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005688
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005689#ifdef CONFIG_PM
5690 retval = pci_save_state(pdev);
5691 if (retval)
5692 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005693
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005694#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005695 if (wufc) {
5696 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005697
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005698 /* turn on all-multi mode if wake on multicast is enabled */
5699 if (wufc & IXGBE_WUFC_MC) {
5700 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5701 fctrl |= IXGBE_FCTRL_MPE;
5702 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5703 }
5704
5705 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5706 ctrl |= IXGBE_CTRL_GIO_DIS;
5707 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5708
5709 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5710 } else {
5711 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5712 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5713 }
5714
Alexander Duyckbd508172010-11-16 19:27:03 -08005715 switch (hw->mac.type) {
5716 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005717 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005718 break;
5719 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005720 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005721 pci_wake_from_d3(pdev, !!wufc);
5722 break;
5723 default:
5724 break;
5725 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005726
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005727 *enable_wake = !!wufc;
5728
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005729 ixgbe_release_hw_control(adapter);
5730
5731 pci_disable_device(pdev);
5732
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005733 return 0;
5734}
5735
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005736#ifdef CONFIG_PM
5737static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5738{
5739 int retval;
5740 bool wake;
5741
5742 retval = __ixgbe_shutdown(pdev, &wake);
5743 if (retval)
5744 return retval;
5745
5746 if (wake) {
5747 pci_prepare_to_sleep(pdev);
5748 } else {
5749 pci_wake_from_d3(pdev, false);
5750 pci_set_power_state(pdev, PCI_D3hot);
5751 }
5752
5753 return 0;
5754}
5755#endif /* CONFIG_PM */
5756
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005757static void ixgbe_shutdown(struct pci_dev *pdev)
5758{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005759 bool wake;
5760
5761 __ixgbe_shutdown(pdev, &wake);
5762
5763 if (system_state == SYSTEM_POWER_OFF) {
5764 pci_wake_from_d3(pdev, wake);
5765 pci_set_power_state(pdev, PCI_D3hot);
5766 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005767}
5768
5769/**
Auke Kok9a799d72007-09-15 14:07:45 -07005770 * ixgbe_update_stats - Update the board statistics counters.
5771 * @adapter: board private structure
5772 **/
5773void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5774{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005775 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005776 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005777 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005778 u64 total_mpc = 0;
5779 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005780 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5781 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005782 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005783#ifdef IXGBE_FCOE
5784 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5785 unsigned int cpu;
5786 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5787#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005788
Don Skidmored08935c2010-06-11 13:20:29 +00005789 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5790 test_bit(__IXGBE_RESETTING, &adapter->state))
5791 return;
5792
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005793 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005794 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005795 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005796 for (i = 0; i < 16; i++)
5797 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005798 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005799 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005800 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5801 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005802 }
5803 adapter->rsc_total_count = rsc_count;
5804 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005805 }
5806
Alexander Duyck5b7da512010-11-16 19:26:50 -08005807 for (i = 0; i < adapter->num_rx_queues; i++) {
5808 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5809 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5810 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5811 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005812 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005813 bytes += rx_ring->stats.bytes;
5814 packets += rx_ring->stats.packets;
5815 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005816 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005817 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5818 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005819 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005820 netdev->stats.rx_bytes = bytes;
5821 netdev->stats.rx_packets = packets;
5822
5823 bytes = 0;
5824 packets = 0;
5825 /* gather some stats to the adapter struct that are per queue */
5826 for (i = 0; i < adapter->num_tx_queues; i++) {
5827 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5828 restart_queue += tx_ring->tx_stats.restart_queue;
5829 tx_busy += tx_ring->tx_stats.tx_busy;
5830 bytes += tx_ring->stats.bytes;
5831 packets += tx_ring->stats.packets;
5832 }
5833 adapter->restart_queue = restart_queue;
5834 adapter->tx_busy = tx_busy;
5835 netdev->stats.tx_bytes = bytes;
5836 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005837
Joe Perches7ca647b2010-09-07 21:35:40 +00005838 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005839
5840 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005841 for (i = 0; i < 8; i++) {
5842 /* for packet buffers not used, the register should read 0 */
5843 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5844 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005845 hwstats->mpc[i] += mpc;
5846 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005847 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5848 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005849 switch (hw->mac.type) {
5850 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005851 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5852 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5853 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005854 hwstats->pxonrxc[i] +=
5855 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005856 break;
5857 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005858 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005859 hwstats->pxonrxc[i] +=
5860 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005861 break;
5862 default:
5863 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005864 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005865 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005866
5867 /*16 register reads */
5868 for (i = 0; i < 16; i++) {
5869 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5870 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5871 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5872 (hw->mac.type == ixgbe_mac_X540)) {
5873 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5874 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5875 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5876 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5877 }
5878 }
5879
Joe Perches7ca647b2010-09-07 21:35:40 +00005880 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005881 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005882 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005883
John Fastabendc84d3242010-11-16 19:27:12 -08005884 ixgbe_update_xoff_received(adapter);
5885
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005886 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005887 switch (hw->mac.type) {
5888 case ixgbe_mac_82598EB:
5889 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005890 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5891 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5892 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5893 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005894 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005895 /* OS2BMC stats are X540 only*/
5896 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5897 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5898 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5899 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5900 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005901 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005902 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005903 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005904 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005905 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005906 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005907 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005908 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5909 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005910#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005911 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5912 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5913 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5914 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5915 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5916 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005917 /* Add up per cpu counters for total ddp aloc fail */
5918 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5919 for_each_possible_cpu(cpu) {
5920 fcoe_noddp_counts_sum +=
5921 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5922 fcoe_noddp_ext_buff_counts_sum +=
5923 *per_cpu_ptr(fcoe->
5924 pcpu_noddp_ext_buff, cpu);
5925 }
5926 }
5927 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5928 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005929#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005930 break;
5931 default:
5932 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005933 }
Auke Kok9a799d72007-09-15 14:07:45 -07005934 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005935 hwstats->bprc += bprc;
5936 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005937 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005938 hwstats->mprc -= bprc;
5939 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5940 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5941 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5942 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5943 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5944 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5945 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5946 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005947 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005948 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005949 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005950 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005951 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5952 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005953 /*
5954 * 82598 errata - tx of flow control packets is included in tx counters
5955 */
5956 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005957 hwstats->gptc -= xon_off_tot;
5958 hwstats->mptc -= xon_off_tot;
5959 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5960 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5961 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5962 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5963 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5964 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5965 hwstats->ptc64 -= xon_off_tot;
5966 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5967 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5968 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5969 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5970 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5971 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005972
5973 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005974 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005975
5976 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005977 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005978 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005979 netdev->stats.rx_length_errors = hwstats->rlec;
5980 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005981 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005982}
5983
5984/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005985 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5986 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005987 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005988static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005989{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005990 struct ixgbe_hw *hw = &adapter->hw;
5991 int i;
5992
Alexander Duyckd034acf2011-04-27 09:25:34 +00005993 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5994 return;
5995
5996 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5997
5998 /* if interface is down do nothing */
5999 if (test_bit(__IXGBE_DOWN, &adapter->state))
6000 return;
6001
6002 /* do nothing if we are not using signature filters */
6003 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6004 return;
6005
6006 adapter->fdir_overflow++;
6007
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006008 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6009 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006010 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006011 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006012 /* re-enable flow director interrupts */
6013 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006014 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006015 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006016 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006017 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006018}
6019
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006020/**
6021 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6022 * @adapter - pointer to the device adapter structure
6023 *
6024 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006025 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006026 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006027 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006028 */
6029static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6030{
Auke Kok9a799d72007-09-15 14:07:45 -07006031 struct ixgbe_hw *hw = &adapter->hw;
6032 u64 eics = 0;
6033 int i;
6034
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006035 /* If we're down or resetting, just bail */
6036 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6037 test_bit(__IXGBE_RESETTING, &adapter->state))
6038 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006039
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006040 /* Force detection of hung controller */
6041 if (netif_carrier_ok(adapter->netdev)) {
6042 for (i = 0; i < adapter->num_tx_queues; i++)
6043 set_check_for_tx_hang(adapter->tx_ring[i]);
6044 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006045
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006046 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006047 /*
6048 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006049 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006050 * would set *both* EIMS and EICS for any bit in EIAM
6051 */
6052 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6053 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006054 } else {
6055 /* get one bit for every active tx/rx interrupt vector */
6056 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6057 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006058 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006059 eics |= ((u64)1 << i);
6060 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006061 }
6062
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006063 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006064 ixgbe_irq_rearm_queues(adapter, eics);
6065
Alexander Duyckfe49f042009-06-04 16:00:09 +00006066}
6067
6068/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006069 * ixgbe_watchdog_update_link - update the link status
6070 * @adapter - pointer to the device adapter structure
6071 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006072 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006073static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006074{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006075 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006076 u32 link_speed = adapter->link_speed;
6077 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006078 int i;
6079
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006080 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6081 return;
6082
6083 if (hw->mac.ops.check_link) {
6084 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006085 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006086 /* always assume link is up, if no check link function */
6087 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6088 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006089 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006090 if (link_up) {
6091 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6092 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6093 hw->mac.ops.fc_enable(hw, i);
6094 } else {
6095 hw->mac.ops.fc_enable(hw, 0);
6096 }
6097 }
6098
6099 if (link_up ||
6100 time_after(jiffies, (adapter->link_check_timeout +
6101 IXGBE_TRY_LINK_TIMEOUT))) {
6102 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6103 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6104 IXGBE_WRITE_FLUSH(hw);
6105 }
6106
6107 adapter->link_up = link_up;
6108 adapter->link_speed = link_speed;
6109}
6110
6111/**
6112 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6113 * print link up message
6114 * @adapter - pointer to the device adapter structure
6115 **/
6116static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6117{
6118 struct net_device *netdev = adapter->netdev;
6119 struct ixgbe_hw *hw = &adapter->hw;
6120 u32 link_speed = adapter->link_speed;
6121 bool flow_rx, flow_tx;
6122
6123 /* only continue if link was previously down */
6124 if (netif_carrier_ok(netdev))
6125 return;
6126
6127 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6128
6129 switch (hw->mac.type) {
6130 case ixgbe_mac_82598EB: {
6131 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6132 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6133 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6134 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6135 }
6136 break;
6137 case ixgbe_mac_X540:
6138 case ixgbe_mac_82599EB: {
6139 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6140 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6141 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6142 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6143 }
6144 break;
6145 default:
6146 flow_tx = false;
6147 flow_rx = false;
6148 break;
6149 }
6150 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6151 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6152 "10 Gbps" :
6153 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6154 "1 Gbps" :
6155 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6156 "100 Mbps" :
6157 "unknown speed"))),
6158 ((flow_rx && flow_tx) ? "RX/TX" :
6159 (flow_rx ? "RX" :
6160 (flow_tx ? "TX" : "None"))));
6161
6162 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006163 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006164}
6165
6166/**
6167 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6168 * print link down message
6169 * @adapter - pointer to the adapter structure
6170 **/
6171static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6172{
6173 struct net_device *netdev = adapter->netdev;
6174 struct ixgbe_hw *hw = &adapter->hw;
6175
6176 adapter->link_up = false;
6177 adapter->link_speed = 0;
6178
6179 /* only continue if link was up previously */
6180 if (!netif_carrier_ok(netdev))
6181 return;
6182
6183 /* poll for SFP+ cable when link is down */
6184 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6185 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6186
6187 e_info(drv, "NIC Link is Down\n");
6188 netif_carrier_off(netdev);
6189}
6190
6191/**
6192 * ixgbe_watchdog_flush_tx - flush queues on link down
6193 * @adapter - pointer to the device adapter structure
6194 **/
6195static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6196{
6197 int i;
6198 int some_tx_pending = 0;
6199
6200 if (!netif_carrier_ok(adapter->netdev)) {
6201 for (i = 0; i < adapter->num_tx_queues; i++) {
6202 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6203 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6204 some_tx_pending = 1;
6205 break;
6206 }
6207 }
6208
6209 if (some_tx_pending) {
6210 /* We've lost link, so the controller stops DMA,
6211 * but we've got queued Tx work that's never going
6212 * to get done, so reset controller to flush Tx.
6213 * (Do the reset outside of interrupt context).
6214 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006215 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006216 }
6217 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006218}
6219
Greg Rosea985b6c32010-11-18 03:02:52 +00006220static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6221{
6222 u32 ssvpc;
6223
6224 /* Do not perform spoof check for 82598 */
6225 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6226 return;
6227
6228 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6229
6230 /*
6231 * ssvpc register is cleared on read, if zero then no
6232 * spoofed packets in the last interval.
6233 */
6234 if (!ssvpc)
6235 return;
6236
6237 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6238}
6239
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006240/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006241 * ixgbe_watchdog_subtask - check and bring link up
6242 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006243 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006244static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006245{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006246 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006247 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6248 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006249 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006250
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006251 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006252
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006253 if (adapter->link_up)
6254 ixgbe_watchdog_link_is_up(adapter);
6255 else
6256 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006257
Greg Rosea985b6c32010-11-18 03:02:52 +00006258 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006259 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006260
6261 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006262}
6263
Alexander Duyck70864002011-04-27 09:13:56 +00006264/**
6265 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6266 * @adapter - the ixgbe adapter structure
6267 **/
6268static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6269{
6270 struct ixgbe_hw *hw = &adapter->hw;
6271 s32 err;
6272
6273 /* not searching for SFP so there is nothing to do here */
6274 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6275 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6276 return;
6277
6278 /* someone else is in init, wait until next service event */
6279 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6280 return;
6281
6282 err = hw->phy.ops.identify_sfp(hw);
6283 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6284 goto sfp_out;
6285
6286 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6287 /* If no cable is present, then we need to reset
6288 * the next time we find a good cable. */
6289 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6290 }
6291
6292 /* exit on error */
6293 if (err)
6294 goto sfp_out;
6295
6296 /* exit if reset not needed */
6297 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6298 goto sfp_out;
6299
6300 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6301
6302 /*
6303 * A module may be identified correctly, but the EEPROM may not have
6304 * support for that module. setup_sfp() will fail in that case, so
6305 * we should not allow that module to load.
6306 */
6307 if (hw->mac.type == ixgbe_mac_82598EB)
6308 err = hw->phy.ops.reset(hw);
6309 else
6310 err = hw->mac.ops.setup_sfp(hw);
6311
6312 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6313 goto sfp_out;
6314
6315 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6316 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6317
6318sfp_out:
6319 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6320
6321 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6322 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6323 e_dev_err("failed to initialize because an unsupported "
6324 "SFP+ module type was detected.\n");
6325 e_dev_err("Reload the driver after installing a "
6326 "supported module.\n");
6327 unregister_netdev(adapter->netdev);
6328 }
6329}
6330
6331/**
6332 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6333 * @adapter - the ixgbe adapter structure
6334 **/
6335static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6336{
6337 struct ixgbe_hw *hw = &adapter->hw;
6338 u32 autoneg;
6339 bool negotiation;
6340
6341 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6342 return;
6343
6344 /* someone else is in init, wait until next service event */
6345 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6346 return;
6347
6348 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6349
6350 autoneg = hw->phy.autoneg_advertised;
6351 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6352 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006353 if (hw->mac.ops.setup_link)
6354 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6355
6356 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6357 adapter->link_check_timeout = jiffies;
6358 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6359}
6360
Greg Rose83c61fa2011-09-07 05:59:35 +00006361#ifdef CONFIG_PCI_IOV
6362static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6363{
6364 int vf;
6365 struct ixgbe_hw *hw = &adapter->hw;
6366 struct net_device *netdev = adapter->netdev;
6367 u32 gpc;
6368 u32 ciaa, ciad;
6369
6370 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6371 if (gpc) /* If incrementing then no need for the check below */
6372 return;
6373 /*
6374 * Check to see if a bad DMA write target from an errant or
6375 * malicious VF has caused a PCIe error. If so then we can
6376 * issue a VFLR to the offending VF(s) and then resume without
6377 * requesting a full slot reset.
6378 */
6379
6380 for (vf = 0; vf < adapter->num_vfs; vf++) {
6381 ciaa = (vf << 16) | 0x80000000;
6382 /* 32 bit read so align, we really want status at offset 6 */
6383 ciaa |= PCI_COMMAND;
6384 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6385 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6386 ciaa &= 0x7FFFFFFF;
6387 /* disable debug mode asap after reading data */
6388 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6389 /* Get the upper 16 bits which will be the PCI status reg */
6390 ciad >>= 16;
6391 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6392 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6393 /* Issue VFLR */
6394 ciaa = (vf << 16) | 0x80000000;
6395 ciaa |= 0xA8;
6396 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6397 ciad = 0x00008000; /* VFLR */
6398 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6399 ciaa &= 0x7FFFFFFF;
6400 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6401 }
6402 }
6403}
6404
6405#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006406/**
6407 * ixgbe_service_timer - Timer Call-back
6408 * @data: pointer to adapter cast into an unsigned long
6409 **/
6410static void ixgbe_service_timer(unsigned long data)
6411{
6412 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6413 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006414 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006415
Greg Rose83c61fa2011-09-07 05:59:35 +00006416#ifdef CONFIG_PCI_IOV
6417 ready = false;
6418
6419 /*
6420 * don't bother with SR-IOV VF DMA hang check if there are
6421 * no VFs or the link is down
6422 */
6423 if (!adapter->num_vfs ||
6424 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6425 ready = true;
6426 goto normal_timer_service;
6427 }
6428
6429 /* If we have VFs allocated then we must check for DMA hangs */
6430 ixgbe_check_for_bad_vf(adapter);
6431 next_event_offset = HZ / 50;
6432 adapter->timer_event_accumulator++;
6433
6434 if (adapter->timer_event_accumulator >= 100) {
6435 ready = true;
6436 adapter->timer_event_accumulator = 0;
6437 }
6438
6439 goto schedule_event;
6440
6441normal_timer_service:
6442#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006443 /* poll faster when waiting for link */
6444 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6445 next_event_offset = HZ / 10;
6446 else
6447 next_event_offset = HZ * 2;
6448
Greg Rose83c61fa2011-09-07 05:59:35 +00006449#ifdef CONFIG_PCI_IOV
6450schedule_event:
6451#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006452 /* Reset the timer */
6453 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6454
Greg Rose83c61fa2011-09-07 05:59:35 +00006455 if (ready)
6456 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006457}
6458
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006459static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6460{
6461 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6462 return;
6463
6464 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6465
6466 /* If we're already down or resetting, just bail */
6467 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6468 test_bit(__IXGBE_RESETTING, &adapter->state))
6469 return;
6470
6471 ixgbe_dump(adapter);
6472 netdev_err(adapter->netdev, "Reset adapter\n");
6473 adapter->tx_timeout_count++;
6474
6475 ixgbe_reinit_locked(adapter);
6476}
6477
Alexander Duyck70864002011-04-27 09:13:56 +00006478/**
6479 * ixgbe_service_task - manages and runs subtasks
6480 * @work: pointer to work_struct containing our data
6481 **/
6482static void ixgbe_service_task(struct work_struct *work)
6483{
6484 struct ixgbe_adapter *adapter = container_of(work,
6485 struct ixgbe_adapter,
6486 service_task);
6487
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006488 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006489 ixgbe_sfp_detection_subtask(adapter);
6490 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006491 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006492 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006493 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006494 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006495
6496 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006497}
6498
Alexander Duyck897ab152011-05-27 05:31:47 +00006499void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6500 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006501{
6502 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006503 u16 i = tx_ring->next_to_use;
6504
Alexander Duycke4f74022012-01-31 02:59:44 +00006505 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006506
6507 i++;
6508 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6509
6510 /* set bits to identify this as an advanced context descriptor */
6511 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6512
6513 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6514 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6515 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6516 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6517}
6518
6519static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6520 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6521{
Auke Kok9a799d72007-09-15 14:07:45 -07006522 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006523 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006524 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006525
Alexander Duyck897ab152011-05-27 05:31:47 +00006526 if (!skb_is_gso(skb))
6527 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006528
Alexander Duyck897ab152011-05-27 05:31:47 +00006529 if (skb_header_cloned(skb)) {
6530 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6531 if (err)
6532 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006533 }
6534
Alexander Duyck897ab152011-05-27 05:31:47 +00006535 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6536 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6537
6538 if (protocol == __constant_htons(ETH_P_IP)) {
6539 struct iphdr *iph = ip_hdr(skb);
6540 iph->tot_len = 0;
6541 iph->check = 0;
6542 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6543 iph->daddr, 0,
6544 IPPROTO_TCP,
6545 0);
6546 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6547 } else if (skb_is_gso_v6(skb)) {
6548 ipv6_hdr(skb)->payload_len = 0;
6549 tcp_hdr(skb)->check =
6550 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6551 &ipv6_hdr(skb)->daddr,
6552 0, IPPROTO_TCP, 0);
6553 }
6554
6555 l4len = tcp_hdrlen(skb);
6556 *hdr_len = skb_transport_offset(skb) + l4len;
6557
6558 /* mss_l4len_id: use 1 as index for TSO */
6559 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6560 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6561 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6562
6563 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6564 vlan_macip_lens = skb_network_header_len(skb);
6565 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6566 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6567
6568 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6569 mss_l4len_idx);
6570
6571 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006572}
6573
Alexander Duyck897ab152011-05-27 05:31:47 +00006574static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006575 struct sk_buff *skb, u32 tx_flags,
6576 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006577{
Alexander Duyck897ab152011-05-27 05:31:47 +00006578 u32 vlan_macip_lens = 0;
6579 u32 mss_l4len_idx = 0;
6580 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006581
Alexander Duyck897ab152011-05-27 05:31:47 +00006582 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006583 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6584 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006585 return false;
6586 } else {
6587 u8 l4_hdr = 0;
6588 switch (protocol) {
6589 case __constant_htons(ETH_P_IP):
6590 vlan_macip_lens |= skb_network_header_len(skb);
6591 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6592 l4_hdr = ip_hdr(skb)->protocol;
6593 break;
6594 case __constant_htons(ETH_P_IPV6):
6595 vlan_macip_lens |= skb_network_header_len(skb);
6596 l4_hdr = ipv6_hdr(skb)->nexthdr;
6597 break;
6598 default:
6599 if (unlikely(net_ratelimit())) {
6600 dev_warn(tx_ring->dev,
6601 "partial checksum but proto=%x!\n",
6602 skb->protocol);
6603 }
6604 break;
6605 }
Auke Kok9a799d72007-09-15 14:07:45 -07006606
Alexander Duyck897ab152011-05-27 05:31:47 +00006607 switch (l4_hdr) {
6608 case IPPROTO_TCP:
6609 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6610 mss_l4len_idx = tcp_hdrlen(skb) <<
6611 IXGBE_ADVTXD_L4LEN_SHIFT;
6612 break;
6613 case IPPROTO_SCTP:
6614 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6615 mss_l4len_idx = sizeof(struct sctphdr) <<
6616 IXGBE_ADVTXD_L4LEN_SHIFT;
6617 break;
6618 case IPPROTO_UDP:
6619 mss_l4len_idx = sizeof(struct udphdr) <<
6620 IXGBE_ADVTXD_L4LEN_SHIFT;
6621 break;
6622 default:
6623 if (unlikely(net_ratelimit())) {
6624 dev_warn(tx_ring->dev,
6625 "partial checksum but l4 proto=%x!\n",
6626 skb->protocol);
6627 }
6628 break;
6629 }
Auke Kok9a799d72007-09-15 14:07:45 -07006630 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006631
Alexander Duyck897ab152011-05-27 05:31:47 +00006632 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6633 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6634
6635 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6636 type_tucmd, mss_l4len_idx);
6637
6638 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006639}
6640
Alexander Duyckd3d00232011-07-15 02:31:25 +00006641static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6642{
6643 /* set type for advanced descriptor with frame checksum insertion */
6644 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6645 IXGBE_ADVTXD_DCMD_IFCS |
6646 IXGBE_ADVTXD_DCMD_DEXT);
6647
6648 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006649 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006650 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6651
6652 /* set segmentation enable bits for TSO/FSO */
6653#ifdef IXGBE_FCOE
6654 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6655#else
6656 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6657#endif
6658 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6659
6660 return cmd_type;
6661}
6662
6663static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6664{
6665 __le32 olinfo_status =
6666 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6667
6668 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6669 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6670 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6671 /* enble IPv4 checksum for TSO */
6672 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6673 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6674 }
6675
6676 /* enable L4 checksum for TSO and TX checksum offload */
6677 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6678 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6679
6680#ifdef IXGBE_FCOE
6681 /* use index 1 context for FCOE/FSO */
6682 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6683 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6684 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6685
6686#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006687 /*
6688 * Check Context must be set if Tx switch is enabled, which it
6689 * always is for case where virtual functions are running
6690 */
6691 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6692 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6693
Alexander Duyckd3d00232011-07-15 02:31:25 +00006694 return olinfo_status;
6695}
6696
6697#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6698 IXGBE_TXD_CMD_RS)
6699
6700static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6701 struct sk_buff *skb,
6702 struct ixgbe_tx_buffer *first,
6703 u32 tx_flags,
6704 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006705{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006706 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006707 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006708 union ixgbe_adv_tx_desc *tx_desc;
6709 dma_addr_t dma;
6710 __le32 cmd_type, olinfo_status;
6711 struct skb_frag_struct *frag;
6712 unsigned int f = 0;
6713 unsigned int data_len = skb->data_len;
6714 unsigned int size = skb_headlen(skb);
6715 u32 offset = 0;
6716 u32 paylen = skb->len - hdr_len;
6717 u16 i = tx_ring->next_to_use;
6718 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006719
Alexander Duyckd3d00232011-07-15 02:31:25 +00006720#ifdef IXGBE_FCOE
6721 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6722 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6723 data_len -= sizeof(struct fcoe_crc_eof);
6724 } else {
6725 size -= sizeof(struct fcoe_crc_eof) - data_len;
6726 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006727 }
Auke Kok9a799d72007-09-15 14:07:45 -07006728 }
6729
Alexander Duyckd3d00232011-07-15 02:31:25 +00006730#endif
6731 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6732 if (dma_mapping_error(dev, dma))
6733 goto dma_error;
6734
6735 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6736 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6737
Alexander Duycke4f74022012-01-31 02:59:44 +00006738 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006739
6740 for (;;) {
6741 while (size > IXGBE_MAX_DATA_PER_TXD) {
6742 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6743 tx_desc->read.cmd_type_len =
6744 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6745 tx_desc->read.olinfo_status = olinfo_status;
6746
6747 offset += IXGBE_MAX_DATA_PER_TXD;
6748 size -= IXGBE_MAX_DATA_PER_TXD;
6749
6750 tx_desc++;
6751 i++;
6752 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006753 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006754 i = 0;
6755 }
6756 }
6757
6758 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6759 tx_buffer_info->length = offset + size;
6760 tx_buffer_info->tx_flags = tx_flags;
6761 tx_buffer_info->dma = dma;
6762
6763 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6764 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6765 tx_desc->read.olinfo_status = olinfo_status;
6766
6767 if (!data_len)
6768 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006769
6770 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006771#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006772 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006773#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006774 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006775#endif
6776 data_len -= size;
6777 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006778
Alexander Duyckd3d00232011-07-15 02:31:25 +00006779 offset = 0;
6780 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006781
Ian Campbell877749b2011-08-29 23:18:26 +00006782 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006783 if (dma_mapping_error(dev, dma))
6784 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006785
Alexander Duyckd3d00232011-07-15 02:31:25 +00006786 tx_desc++;
6787 i++;
6788 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006789 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006790 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006791 }
6792 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006793
Alexander Duyckd3d00232011-07-15 02:31:25 +00006794 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6795
6796 i++;
6797 if (i == tx_ring->count)
6798 i = 0;
6799
6800 tx_ring->next_to_use = i;
6801
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006802 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6803 gso_segs = skb_shinfo(skb)->gso_segs;
6804#ifdef IXGBE_FCOE
6805 /* adjust for FCoE Sequence Offload */
6806 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6807 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6808 skb_shinfo(skb)->gso_size);
6809#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006810 else
6811 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006812
6813 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006814 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6815 tx_buffer_info->gso_segs = gso_segs;
6816 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006817
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006818 netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount);
6819
Alexander Duyckd3d00232011-07-15 02:31:25 +00006820 /* set the timestamp */
6821 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006822
6823 /*
6824 * Force memory writes to complete before letting h/w
6825 * know there are new descriptors to fetch. (Only
6826 * applicable for weak-ordered memory model archs,
6827 * such as IA-64).
6828 */
6829 wmb();
6830
Alexander Duyckd3d00232011-07-15 02:31:25 +00006831 /* set next_to_watch value indicating a packet is present */
6832 first->next_to_watch = tx_desc;
6833
6834 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006835 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006836
6837 return;
6838dma_error:
6839 dev_err(dev, "TX DMA map failed\n");
6840
6841 /* clear dma mappings for failed tx_buffer_info map */
6842 for (;;) {
6843 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6844 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6845 if (tx_buffer_info == first)
6846 break;
6847 if (i == 0)
6848 i = tx_ring->count;
6849 i--;
6850 }
6851
6852 dev_kfree_skb_any(skb);
6853
6854 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006855}
6856
Alexander Duyck69830522011-01-06 14:29:58 +00006857static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6858 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006859{
Alexander Duyck69830522011-01-06 14:29:58 +00006860 struct ixgbe_q_vector *q_vector = ring->q_vector;
6861 union ixgbe_atr_hash_dword input = { .dword = 0 };
6862 union ixgbe_atr_hash_dword common = { .dword = 0 };
6863 union {
6864 unsigned char *network;
6865 struct iphdr *ipv4;
6866 struct ipv6hdr *ipv6;
6867 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006868 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006869 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006870
Alexander Duyck69830522011-01-06 14:29:58 +00006871 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6872 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006873 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006874
Alexander Duyck69830522011-01-06 14:29:58 +00006875 /* do nothing if sampling is disabled */
6876 if (!ring->atr_sample_rate)
6877 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006878
Alexander Duyck69830522011-01-06 14:29:58 +00006879 ring->atr_count++;
6880
6881 /* snag network header to get L4 type and address */
6882 hdr.network = skb_network_header(skb);
6883
6884 /* Currently only IPv4/IPv6 with TCP is supported */
6885 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6886 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6887 (protocol != __constant_htons(ETH_P_IP) ||
6888 hdr.ipv4->protocol != IPPROTO_TCP))
6889 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006890
6891 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006892
Alexander Duyck66f32a82011-06-29 05:43:22 +00006893 /* skip this packet since it is invalid or the socket is closing */
6894 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006895 return;
6896
6897 /* sample on all syn packets or once every atr sample count */
6898 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6899 return;
6900
6901 /* reset sample count */
6902 ring->atr_count = 0;
6903
6904 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6905
6906 /*
6907 * src and dst are inverted, think how the receiver sees them
6908 *
6909 * The input is broken into two sections, a non-compressed section
6910 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6911 * is XORed together and stored in the compressed dword.
6912 */
6913 input.formatted.vlan_id = vlan_id;
6914
6915 /*
6916 * since src port and flex bytes occupy the same word XOR them together
6917 * and write the value to source port portion of compressed dword
6918 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006919 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006920 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6921 else
6922 common.port.src ^= th->dest ^ protocol;
6923 common.port.dst ^= th->source;
6924
6925 if (protocol == __constant_htons(ETH_P_IP)) {
6926 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6927 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6928 } else {
6929 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6930 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6931 hdr.ipv6->saddr.s6_addr32[1] ^
6932 hdr.ipv6->saddr.s6_addr32[2] ^
6933 hdr.ipv6->saddr.s6_addr32[3] ^
6934 hdr.ipv6->daddr.s6_addr32[0] ^
6935 hdr.ipv6->daddr.s6_addr32[1] ^
6936 hdr.ipv6->daddr.s6_addr32[2] ^
6937 hdr.ipv6->daddr.s6_addr32[3];
6938 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006939
6940 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006941 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6942 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006943}
6944
Alexander Duyck63544e92011-05-27 05:31:42 +00006945static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006946{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006947 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006948 /* Herbert's original patch had:
6949 * smp_mb__after_netif_stop_queue();
6950 * but since that doesn't exist yet, just open code it. */
6951 smp_mb();
6952
6953 /* We need to check again in a case another CPU has just
6954 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006955 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006956 return -EBUSY;
6957
6958 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006959 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006960 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006961 return 0;
6962}
6963
Alexander Duyck82d4e462011-06-11 01:44:58 +00006964static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006965{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006966 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006967 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006968 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006969}
6970
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006971static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6972{
6973 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006974 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6975 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006976#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006977 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006978
John Fastabende5b64632011-03-08 03:44:52 +00006979 if (((protocol == htons(ETH_P_FCOE)) ||
6980 (protocol == htons(ETH_P_FIP))) &&
6981 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6982 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6983 txq += adapter->ring_feature[RING_F_FCOE].mask;
6984 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006985 }
6986#endif
6987
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006988 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6989 while (unlikely(txq >= dev->real_num_tx_queues))
6990 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006991 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006992 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006993
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006994 return skb_tx_hash(dev, skb);
6995}
6996
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006997netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006998 struct ixgbe_adapter *adapter,
6999 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007000{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007001 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007002 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007003 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007004#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7005 unsigned short f;
7006#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007007 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007008 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007009 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007010
Alexander Duycka535c302011-05-27 05:31:52 +00007011 /*
7012 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007013 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007014 * + 2 desc gap to keep tail from touching head,
7015 * + 1 desc for context descriptor,
7016 * otherwise try next time
7017 */
7018#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7019 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7020 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7021#else
7022 count += skb_shinfo(skb)->nr_frags;
7023#endif
7024 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7025 tx_ring->tx_stats.tx_busy++;
7026 return NETDEV_TX_BUSY;
7027 }
7028
Alexander Duyck66f32a82011-06-29 05:43:22 +00007029 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007030 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007031 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7032 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7033 /* else if it is a SW VLAN check the next protocol and store the tag */
7034 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7035 struct vlan_hdr *vhdr, _vhdr;
7036 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7037 if (!vhdr)
7038 goto out_drop;
7039
7040 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007041 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7042 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007043 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007044 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007045
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007046#ifdef CONFIG_PCI_IOV
7047 /*
7048 * Use the l2switch_enable flag - would be false if the DMA
7049 * Tx switch had been disabled.
7050 */
7051 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7052 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7053
7054#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007055 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007056 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007057 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7058 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007059 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007060 tx_flags |= (skb->priority & 0x7) <<
7061 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007062 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7063 struct vlan_ethhdr *vhdr;
7064 if (skb_header_cloned(skb) &&
7065 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7066 goto out_drop;
7067 vhdr = (struct vlan_ethhdr *)skb->data;
7068 vhdr->h_vlan_TCI = htons(tx_flags >>
7069 IXGBE_TX_FLAGS_VLAN_SHIFT);
7070 } else {
7071 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7072 }
7073 }
Alexander Duycka535c302011-05-27 05:31:52 +00007074
Alexander Duycka535c302011-05-27 05:31:52 +00007075 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007076 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007077
Yi Zoueacd73f2009-05-13 13:11:06 +00007078#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007079 /* setup tx offload for FCoE */
7080 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7081 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007082 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7083 if (tso < 0)
7084 goto out_drop;
7085 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007086 tx_flags |= IXGBE_TX_FLAGS_FSO |
7087 IXGBE_TX_FLAGS_FCOE;
7088 else
7089 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007090
Alexander Duyck66f32a82011-06-29 05:43:22 +00007091 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007092 }
Auke Kok9a799d72007-09-15 14:07:45 -07007093
Auke Kok9a799d72007-09-15 14:07:45 -07007094#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007095 /* setup IPv4/IPv6 offloads */
7096 if (protocol == __constant_htons(ETH_P_IP))
7097 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007098
Alexander Duyck66f32a82011-06-29 05:43:22 +00007099 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7100 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007101 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007102 else if (tso)
7103 tx_flags |= IXGBE_TX_FLAGS_TSO;
7104 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7105 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7106
7107 /* add the ATR filter if ATR is on */
7108 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7109 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7110
7111#ifdef IXGBE_FCOE
7112xmit_fcoe:
7113#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007114 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7115
7116 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007117
7118 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007119
7120out_drop:
7121 dev_kfree_skb_any(skb);
7122 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007123}
7124
7125static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7126{
7127 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7128 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007129
Auke Kok9a799d72007-09-15 14:07:45 -07007130 tx_ring = adapter->tx_ring[skb->queue_mapping];
7131 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7132}
7133
7134/**
7135 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007136 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007137 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007138 *
Auke Kok9a799d72007-09-15 14:07:45 -07007139 * Returns 0 on success, negative on failure
7140 **/
7141static int ixgbe_set_mac(struct net_device *netdev, void *p)
7142{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007143 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7144 struct ixgbe_hw *hw = &adapter->hw;
7145 struct sockaddr *addr = p;
7146
7147 if (!is_valid_ether_addr(addr->sa_data))
7148 return -EADDRNOTAVAIL;
7149
7150 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7151 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7152
7153 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7154 IXGBE_RAH_AV);
7155
7156 return 0;
7157}
7158
7159static int
7160ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7161{
7162 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7163 struct ixgbe_hw *hw = &adapter->hw;
7164 u16 value;
7165 int rc;
7166
7167 if (prtad != hw->phy.mdio.prtad)
7168 return -EINVAL;
7169 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7170 if (!rc)
7171 rc = value;
7172 return rc;
7173}
7174
7175static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7176 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007177{
7178 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007179 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007180
7181 if (prtad != hw->phy.mdio.prtad)
7182 return -EINVAL;
7183 return hw->phy.ops.write_reg(hw, addr, devad, value);
7184}
7185
7186static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7187{
7188 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7189
7190 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7191}
7192
7193/**
7194 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7195 * netdev->dev_addrs
7196 * @netdev: network interface device structure
7197 *
7198 * Returns non-zero on failure
7199 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007200static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007201{
7202 int err = 0;
7203 struct ixgbe_adapter *adapter = netdev_priv(dev);
7204 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7205
7206 if (is_valid_ether_addr(mac->san_addr)) {
7207 rtnl_lock();
7208 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7209 rtnl_unlock();
7210 }
7211 return err;
7212}
7213
7214/**
7215 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7216 * netdev->dev_addrs
7217 * @netdev: network interface device structure
7218 *
Auke Kok9a799d72007-09-15 14:07:45 -07007219 * Returns non-zero on failure
7220 **/
7221static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7222{
7223 int err = 0;
7224 struct ixgbe_adapter *adapter = netdev_priv(dev);
7225 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7226
7227 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007228 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007229 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007230 rtnl_unlock();
7231 }
7232 return err;
7233}
Auke Kok9a799d72007-09-15 14:07:45 -07007234
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007235#ifdef CONFIG_NET_POLL_CONTROLLER
7236/*
7237 * Polling 'interrupt' - used by things like netconsole to send skbs
7238 * without having to re-enable interrupts. It's not called while
7239 * the interrupt routine is executing.
7240 */
7241static void ixgbe_netpoll(struct net_device *netdev)
7242{
7243 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007244 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007245
7246 /* if interface is down do nothing */
7247 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007248 return;
7249
7250 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007251 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007252 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007253 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007254 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007255 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007256 }
7257 } else {
7258 ixgbe_intr(adapter->pdev->irq, netdev);
7259 }
7260 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7261}
7262#endif
7263
Eric Dumazetde1036b2010-10-20 23:00:04 +00007264static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7265 struct rtnl_link_stats64 *stats)
7266{
7267 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7268 int i;
7269
Eric Dumazet1a515022010-11-16 19:26:42 -08007270 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007271 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007272 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007273 u64 bytes, packets;
7274 unsigned int start;
7275
Eric Dumazet1a515022010-11-16 19:26:42 -08007276 if (ring) {
7277 do {
7278 start = u64_stats_fetch_begin_bh(&ring->syncp);
7279 packets = ring->stats.packets;
7280 bytes = ring->stats.bytes;
7281 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7282 stats->rx_packets += packets;
7283 stats->rx_bytes += bytes;
7284 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007285 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007286
7287 for (i = 0; i < adapter->num_tx_queues; i++) {
7288 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7289 u64 bytes, packets;
7290 unsigned int start;
7291
7292 if (ring) {
7293 do {
7294 start = u64_stats_fetch_begin_bh(&ring->syncp);
7295 packets = ring->stats.packets;
7296 bytes = ring->stats.bytes;
7297 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7298 stats->tx_packets += packets;
7299 stats->tx_bytes += bytes;
7300 }
7301 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007302 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007303 /* following stats updated by ixgbe_watchdog_task() */
7304 stats->multicast = netdev->stats.multicast;
7305 stats->rx_errors = netdev->stats.rx_errors;
7306 stats->rx_length_errors = netdev->stats.rx_length_errors;
7307 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7308 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7309 return stats;
7310}
7311
John Fastabend8b1c0b22011-05-03 02:26:48 +00007312/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7313 * #adapter: pointer to ixgbe_adapter
7314 * @tc: number of traffic classes currently enabled
7315 *
7316 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7317 * 802.1Q priority maps to a packet buffer that exists.
7318 */
7319static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7320{
7321 struct ixgbe_hw *hw = &adapter->hw;
7322 u32 reg, rsave;
7323 int i;
7324
7325 /* 82598 have a static priority to TC mapping that can not
7326 * be changed so no validation is needed.
7327 */
7328 if (hw->mac.type == ixgbe_mac_82598EB)
7329 return;
7330
7331 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7332 rsave = reg;
7333
7334 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7335 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7336
7337 /* If up2tc is out of bounds default to zero */
7338 if (up2tc > tc)
7339 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7340 }
7341
7342 if (reg != rsave)
7343 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7344
7345 return;
7346}
7347
7348
7349/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7350 * classes.
7351 *
7352 * @netdev: net device to configure
7353 * @tc: number of traffic classes to enable
7354 */
7355int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7356{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007357 struct ixgbe_adapter *adapter = netdev_priv(dev);
7358 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007359
John Fastabende7589ea2011-07-18 22:38:36 +00007360 /* Multiple traffic classes requires multiple queues */
7361 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7362 e_err(drv, "Enable failed, needs MSI-X\n");
7363 return -EINVAL;
7364 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007365
7366 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007367 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007368 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7369 return -EINVAL;
7370
7371 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007372 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007373 * hardware is not flexible enough to do this dynamically.
7374 */
7375 if (netif_running(dev))
7376 ixgbe_close(dev);
7377 ixgbe_clear_interrupt_scheme(adapter);
7378
John Fastabende7589ea2011-07-18 22:38:36 +00007379 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007380 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007381 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7382
7383 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7384 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7385
7386 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7387 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7388 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007389 netdev_reset_tc(dev);
7390
John Fastabende7589ea2011-07-18 22:38:36 +00007391 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7392
7393 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7394 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7395
7396 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7397 adapter->dcb_cfg.pfc_mode_enable = false;
7398 }
7399
John Fastabend8b1c0b22011-05-03 02:26:48 +00007400 ixgbe_init_interrupt_scheme(adapter);
7401 ixgbe_validate_rtr(adapter, tc);
7402 if (netif_running(dev))
7403 ixgbe_open(dev);
7404
7405 return 0;
7406}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007407
Don Skidmore082757a2011-07-21 05:55:00 +00007408void ixgbe_do_reset(struct net_device *netdev)
7409{
7410 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7411
7412 if (netif_running(netdev))
7413 ixgbe_reinit_locked(adapter);
7414 else
7415 ixgbe_reset(adapter);
7416}
7417
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007418static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7419 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007420{
7421 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7422
7423#ifdef CONFIG_DCB
7424 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7425 data &= ~NETIF_F_HW_VLAN_RX;
7426#endif
7427
7428 /* return error if RXHASH is being enabled when RSS is not supported */
7429 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7430 data &= ~NETIF_F_RXHASH;
7431
7432 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7433 if (!(data & NETIF_F_RXCSUM))
7434 data &= ~NETIF_F_LRO;
7435
7436 /* Turn off LRO if not RSC capable or invalid ITR settings */
7437 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7438 data &= ~NETIF_F_LRO;
7439 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7440 (adapter->rx_itr_setting != 1 &&
7441 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7442 data &= ~NETIF_F_LRO;
7443 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7444 }
7445
7446 return data;
7447}
7448
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007449static int ixgbe_set_features(struct net_device *netdev,
7450 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007451{
7452 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7453 bool need_reset = false;
7454
Don Skidmore082757a2011-07-21 05:55:00 +00007455 /* Make sure RSC matches LRO, reset if change */
7456 if (!!(data & NETIF_F_LRO) !=
7457 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7458 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7459 switch (adapter->hw.mac.type) {
7460 case ixgbe_mac_X540:
7461 case ixgbe_mac_82599EB:
7462 need_reset = true;
7463 break;
7464 default:
7465 break;
7466 }
7467 }
7468
7469 /*
7470 * Check if Flow Director n-tuple support was enabled or disabled. If
7471 * the state changed, we need to reset.
7472 */
7473 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7474 /* turn off ATR, enable perfect filters and reset */
7475 if (data & NETIF_F_NTUPLE) {
7476 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7477 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7478 need_reset = true;
7479 }
7480 } else if (!(data & NETIF_F_NTUPLE)) {
7481 /* turn off Flow Director, set ATR and reset */
7482 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7483 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7484 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7485 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7486 need_reset = true;
7487 }
7488
7489 if (need_reset)
7490 ixgbe_do_reset(netdev);
7491
7492 return 0;
7493
7494}
7495
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007496static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007497 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007498 .ndo_stop = ixgbe_close,
7499 .ndo_start_xmit = ixgbe_xmit_frame,
7500 .ndo_select_queue = ixgbe_select_queue,
7501 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007502 .ndo_validate_addr = eth_validate_addr,
7503 .ndo_set_mac_address = ixgbe_set_mac,
7504 .ndo_change_mtu = ixgbe_change_mtu,
7505 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007506 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7507 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007508 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007509 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7510 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7511 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007512 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007513 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007514 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007515 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007516#ifdef CONFIG_NET_POLL_CONTROLLER
7517 .ndo_poll_controller = ixgbe_netpoll,
7518#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007519#ifdef IXGBE_FCOE
7520 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007521 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007522 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007523 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7524 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007525 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007526 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007527#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007528 .ndo_set_features = ixgbe_set_features,
7529 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007530};
7531
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007532static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7533 const struct ixgbe_info *ii)
7534{
7535#ifdef CONFIG_PCI_IOV
7536 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007537
Greg Rosec6bda302011-08-24 02:37:55 +00007538 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007539 return;
7540
7541 /* The 82599 supports up to 64 VFs per physical function
7542 * but this implementation limits allocation to 63 so that
7543 * basic networking resources are still available to the
7544 * physical function
7545 */
7546 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007547 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007548#endif /* CONFIG_PCI_IOV */
7549}
7550
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007551/**
Auke Kok9a799d72007-09-15 14:07:45 -07007552 * ixgbe_probe - Device Initialization Routine
7553 * @pdev: PCI device information struct
7554 * @ent: entry in ixgbe_pci_tbl
7555 *
7556 * Returns 0 on success, negative on failure
7557 *
7558 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7559 * The OS initialization, configuring of the adapter private structure,
7560 * and a hardware reset occur.
7561 **/
7562static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007563 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007564{
7565 struct net_device *netdev;
7566 struct ixgbe_adapter *adapter = NULL;
7567 struct ixgbe_hw *hw;
7568 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007569 static int cards_found;
7570 int i, err, pci_using_dac;
Don Skidmore289700d2010-12-03 03:32:58 +00007571 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007572 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007573#ifdef IXGBE_FCOE
7574 u16 device_caps;
7575#endif
Don Skidmore289700d2010-12-03 03:32:58 +00007576 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007577 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007578
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007579 /* Catch broken hardware that put the wrong VF device ID in
7580 * the PCIe SR-IOV capability.
7581 */
7582 if (pdev->is_virtfn) {
7583 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7584 pci_name(pdev), pdev->vendor, pdev->device);
7585 return -EINVAL;
7586 }
7587
gouji-new9ce77662009-05-06 10:44:45 +00007588 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007589 if (err)
7590 return err;
7591
Nick Nunley1b507732010-04-27 13:10:27 +00007592 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7593 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007594 pci_using_dac = 1;
7595 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007596 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007597 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007598 err = dma_set_coherent_mask(&pdev->dev,
7599 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007600 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007601 dev_err(&pdev->dev,
7602 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007603 goto err_dma;
7604 }
7605 }
7606 pci_using_dac = 0;
7607 }
7608
gouji-new9ce77662009-05-06 10:44:45 +00007609 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007610 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007611 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007612 dev_err(&pdev->dev,
7613 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007614 goto err_pci_reg;
7615 }
7616
Frans Pop19d5afd2009-10-02 10:04:12 -07007617 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007618
Auke Kok9a799d72007-09-15 14:07:45 -07007619 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007620 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007621
John Fastabende901acd2011-04-26 07:26:08 +00007622#ifdef CONFIG_IXGBE_DCB
7623 indices *= MAX_TRAFFIC_CLASS;
7624#endif
7625
John Fastabendc85a2612010-02-25 23:15:21 +00007626 if (ii->mac == ixgbe_mac_82598EB)
7627 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7628 else
7629 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7630
John Fastabende901acd2011-04-26 07:26:08 +00007631#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007632 indices += min_t(unsigned int, num_possible_cpus(),
7633 IXGBE_MAX_FCOE_INDICES);
7634#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007635 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007636 if (!netdev) {
7637 err = -ENOMEM;
7638 goto err_alloc_etherdev;
7639 }
7640
Auke Kok9a799d72007-09-15 14:07:45 -07007641 SET_NETDEV_DEV(netdev, &pdev->dev);
7642
Auke Kok9a799d72007-09-15 14:07:45 -07007643 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007644 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007645
7646 adapter->netdev = netdev;
7647 adapter->pdev = pdev;
7648 hw = &adapter->hw;
7649 hw->back = adapter;
7650 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7651
Jeff Kirsher05857982008-09-11 19:57:00 -07007652 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007653 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007654 if (!hw->hw_addr) {
7655 err = -EIO;
7656 goto err_ioremap;
7657 }
7658
7659 for (i = 1; i <= 5; i++) {
7660 if (pci_resource_len(pdev, i) == 0)
7661 continue;
7662 }
7663
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007664 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007665 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007666 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007667 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007668
Auke Kok9a799d72007-09-15 14:07:45 -07007669 adapter->bd_number = cards_found;
7670
Auke Kok9a799d72007-09-15 14:07:45 -07007671 /* Setup hw api */
7672 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007673 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007674
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007675 /* EEPROM */
7676 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7677 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7678 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7679 if (!(eec & (1 << 8)))
7680 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7681
7682 /* PHY */
7683 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007684 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007685 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7686 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7687 hw->phy.mdio.mmds = 0;
7688 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7689 hw->phy.mdio.dev = netdev;
7690 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7691 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007692
Don Skidmore8ca783a2009-05-26 20:40:47 -07007693 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007694
7695 /* setup the private structure */
7696 err = ixgbe_sw_init(adapter);
7697 if (err)
7698 goto err_sw_init;
7699
Don Skidmoree86bff02010-02-11 04:14:08 +00007700 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007701 switch (adapter->hw.mac.type) {
7702 case ixgbe_mac_82599EB:
7703 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007704 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007705 break;
7706 default:
7707 break;
7708 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007709
Don Skidmorebf069c92009-05-07 10:39:54 +00007710 /*
7711 * If there is a fan on this device and it has failed log the
7712 * failure.
7713 */
7714 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7715 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7716 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007717 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007718 }
7719
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007720 if (allow_unsupported_sfp)
7721 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7722
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007723 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007724 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007725 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007726 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007727 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7728 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007729 err = 0;
7730 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007731 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007732 "module type was detected.\n");
7733 e_dev_err("Reload the driver after installing a supported "
7734 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007735 goto err_sw_init;
7736 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007737 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007738 goto err_sw_init;
7739 }
7740
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007741 ixgbe_probe_vf(adapter, ii);
7742
Emil Tantilov396e7992010-07-01 20:05:12 +00007743 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007744 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007745 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007746 NETIF_F_HW_VLAN_TX |
7747 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007748 NETIF_F_HW_VLAN_FILTER |
7749 NETIF_F_TSO |
7750 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007751 NETIF_F_RXHASH |
7752 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007753
Don Skidmore082757a2011-07-21 05:55:00 +00007754 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007755
Don Skidmore58be7662011-04-12 09:42:11 +00007756 switch (adapter->hw.mac.type) {
7757 case ixgbe_mac_82599EB:
7758 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007759 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007760 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7761 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007762 break;
7763 default:
7764 break;
7765 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007766
Jeff Kirsherad31c402008-06-05 04:05:30 -07007767 netdev->vlan_features |= NETIF_F_TSO;
7768 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007769 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007770 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007771 netdev->vlan_features |= NETIF_F_SG;
7772
Jiri Pirko01789342011-08-16 06:29:00 +00007773 netdev->priv_flags |= IFF_UNICAST_FLT;
7774
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007775 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7776 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7777 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007778
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007779#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007780 netdev->dcbnl_ops = &dcbnl_ops;
7781#endif
7782
Yi Zoueacd73f2009-05-13 13:11:06 +00007783#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007784 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007785 if (hw->mac.ops.get_device_caps) {
7786 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007787 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7788 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007789 }
7790 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007791 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7792 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7793 netdev->vlan_features |= NETIF_F_FSO;
7794 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7795 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007796#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007797 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007798 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007799 netdev->vlan_features |= NETIF_F_HIGHDMA;
7800 }
Auke Kok9a799d72007-09-15 14:07:45 -07007801
Don Skidmore082757a2011-07-21 05:55:00 +00007802 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7803 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007804 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007805 netdev->features |= NETIF_F_LRO;
7806
Auke Kok9a799d72007-09-15 14:07:45 -07007807 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007808 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007809 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007810 err = -EIO;
7811 goto err_eeprom;
7812 }
7813
7814 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7815 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7816
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007817 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007818 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007819 err = -EIO;
7820 goto err_eeprom;
7821 }
7822
Alexander Duyck70864002011-04-27 09:13:56 +00007823 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7824 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007825
Alexander Duyck70864002011-04-27 09:13:56 +00007826 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7827 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007828
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007829 err = ixgbe_init_interrupt_scheme(adapter);
7830 if (err)
7831 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007832
Don Skidmore082757a2011-07-21 05:55:00 +00007833 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7834 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007835 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007836 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007837
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007838 /* WOL not supported for all but the following */
7839 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007840 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007841 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007842 /* Only these subdevice supports WOL */
7843 switch (pdev->subsystem_device) {
7844 case IXGBE_SUBDEV_ID_82599_560FLR:
7845 /* only support first port */
7846 if (hw->bus.func != 0)
7847 break;
7848 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007849 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007850 break;
7851 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007852 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007853 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7854 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007855 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007856 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007857 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007858 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007859 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007860 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007861 case IXGBE_DEV_ID_X540T:
7862 /* Check eeprom to see if it is enabled */
7863 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7864 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7865
7866 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7867 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7868 (hw->bus.func == 0)))
7869 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007870 break;
7871 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007872 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7873
Emil Tantilov15e52092011-09-29 05:01:29 +00007874 /* save off EEPROM version number */
7875 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7876 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7877
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007878 /* pick up the PCI bus settings for reporting later */
7879 hw->mac.ops.get_bus_info(hw);
7880
Auke Kok9a799d72007-09-15 14:07:45 -07007881 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007882 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007883 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7884 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007885 "Unknown"),
7886 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7887 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7888 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7889 "Unknown"),
7890 netdev->dev_addr);
Don Skidmore289700d2010-12-03 03:32:58 +00007891
7892 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7893 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007894 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007895 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700d2010-12-03 03:32:58 +00007896 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007897 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700d2010-12-03 03:32:58 +00007898 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007899 else
Don Skidmore289700d2010-12-03 03:32:58 +00007900 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7901 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007902
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007903 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007904 e_dev_warn("PCI-Express bandwidth available for this card is "
7905 "not sufficient for optimal performance.\n");
7906 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7907 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007908 }
7909
Auke Kok9a799d72007-09-15 14:07:45 -07007910 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007911 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007912
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007913 if (err == IXGBE_ERR_EEPROM_VERSION) {
7914 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007915 e_dev_warn("This device is a pre-production adapter/LOM. "
7916 "Please be aware there may be issues associated "
7917 "with your hardware. If you are experiencing "
7918 "problems please contact your Intel or hardware "
7919 "representative who provided you with this "
7920 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007921 }
Auke Kok9a799d72007-09-15 14:07:45 -07007922 strcpy(netdev->name, "eth%d");
7923 err = register_netdev(netdev);
7924 if (err)
7925 goto err_register;
7926
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007927 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7928 if (hw->mac.ops.disable_tx_laser &&
7929 ((hw->phy.multispeed_fiber) ||
7930 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7931 (hw->mac.type == ixgbe_mac_82599EB))))
7932 hw->mac.ops.disable_tx_laser(hw);
7933
Jesse Brandeburg54386462009-04-17 20:44:27 +00007934 /* carrier off reporting is important to ethtool even BEFORE open */
7935 netif_carrier_off(netdev);
7936
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007937#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007938 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007939 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007940 ixgbe_setup_dca(adapter);
7941 }
7942#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007943 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007944 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007945 for (i = 0; i < adapter->num_vfs; i++)
7946 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7947 }
7948
Jacob Keller2466dd92011-09-08 03:50:54 +00007949 /* firmware requires driver version to be 0xFFFFFFFF
7950 * since os does not support feature
7951 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007952 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007953 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7954 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007955
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007956 /* add san mac addr to netdev */
7957 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007958
Neerav Parikhea818752012-01-04 20:23:40 +00007959 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007960 cards_found++;
7961 return 0;
7962
7963err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007964 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007965 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007966err_sw_init:
7967err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007968 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7969 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007970 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007971 iounmap(hw->hw_addr);
7972err_ioremap:
7973 free_netdev(netdev);
7974err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007975 pci_release_selected_regions(pdev,
7976 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007977err_pci_reg:
7978err_dma:
7979 pci_disable_device(pdev);
7980 return err;
7981}
7982
7983/**
7984 * ixgbe_remove - Device Removal Routine
7985 * @pdev: PCI device information struct
7986 *
7987 * ixgbe_remove is called by the PCI subsystem to alert the driver
7988 * that it should release a PCI device. The could be caused by a
7989 * Hot-Plug event, or because the driver is going to be removed from
7990 * memory.
7991 **/
7992static void __devexit ixgbe_remove(struct pci_dev *pdev)
7993{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007994 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7995 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007996
7997 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007998 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007999
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008000#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008001 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8002 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8003 dca_remove_requester(&pdev->dev);
8004 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8005 }
8006
8007#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008008#ifdef IXGBE_FCOE
8009 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8010 ixgbe_cleanup_fcoe(adapter);
8011
8012#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008013
8014 /* remove the added san mac */
8015 ixgbe_del_sanmac_netdev(netdev);
8016
Donald Skidmorec4900be2008-11-20 21:11:42 -08008017 if (netdev->reg_state == NETREG_REGISTERED)
8018 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008019
Greg Rosec6bda302011-08-24 02:37:55 +00008020 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8021 if (!(ixgbe_check_vf_assignment(adapter)))
8022 ixgbe_disable_sriov(adapter);
8023 else
8024 e_dev_warn("Unloading driver while VFs are assigned "
8025 "- VFs will not be deallocated\n");
8026 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008027
Alexander Duyck7a921c92009-05-06 10:43:28 +00008028 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008029
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008030 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008031
8032 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008033 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008034 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008035
Emil Tantilov849c4542010-06-03 16:53:41 +00008036 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008037
Auke Kok9a799d72007-09-15 14:07:45 -07008038 free_netdev(netdev);
8039
Frans Pop19d5afd2009-10-02 10:04:12 -07008040 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008041
Auke Kok9a799d72007-09-15 14:07:45 -07008042 pci_disable_device(pdev);
8043}
8044
8045/**
8046 * ixgbe_io_error_detected - called when PCI error is detected
8047 * @pdev: Pointer to PCI device
8048 * @state: The current pci connection state
8049 *
8050 * This function is called after a PCI bus error affecting
8051 * this device has been detected.
8052 */
8053static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008054 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008055{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008056 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8057 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008058
Greg Rose83c61fa2011-09-07 05:59:35 +00008059#ifdef CONFIG_PCI_IOV
8060 struct pci_dev *bdev, *vfdev;
8061 u32 dw0, dw1, dw2, dw3;
8062 int vf, pos;
8063 u16 req_id, pf_func;
8064
8065 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8066 adapter->num_vfs == 0)
8067 goto skip_bad_vf_detection;
8068
8069 bdev = pdev->bus->self;
8070 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8071 bdev = bdev->bus->self;
8072
8073 if (!bdev)
8074 goto skip_bad_vf_detection;
8075
8076 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8077 if (!pos)
8078 goto skip_bad_vf_detection;
8079
8080 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8081 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8082 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8083 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8084
8085 req_id = dw1 >> 16;
8086 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8087 if (!(req_id & 0x0080))
8088 goto skip_bad_vf_detection;
8089
8090 pf_func = req_id & 0x01;
8091 if ((pf_func & 1) == (pdev->devfn & 1)) {
8092 unsigned int device_id;
8093
8094 vf = (req_id & 0x7F) >> 1;
8095 e_dev_err("VF %d has caused a PCIe error\n", vf);
8096 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8097 "%8.8x\tdw3: %8.8x\n",
8098 dw0, dw1, dw2, dw3);
8099 switch (adapter->hw.mac.type) {
8100 case ixgbe_mac_82599EB:
8101 device_id = IXGBE_82599_VF_DEVICE_ID;
8102 break;
8103 case ixgbe_mac_X540:
8104 device_id = IXGBE_X540_VF_DEVICE_ID;
8105 break;
8106 default:
8107 device_id = 0;
8108 break;
8109 }
8110
8111 /* Find the pci device of the offending VF */
8112 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8113 while (vfdev) {
8114 if (vfdev->devfn == (req_id & 0xFF))
8115 break;
8116 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8117 device_id, vfdev);
8118 }
8119 /*
8120 * There's a slim chance the VF could have been hot plugged,
8121 * so if it is no longer present we don't need to issue the
8122 * VFLR. Just clean up the AER in that case.
8123 */
8124 if (vfdev) {
8125 e_dev_err("Issuing VFLR to VF %d\n", vf);
8126 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8127 }
8128
8129 pci_cleanup_aer_uncorrect_error_status(pdev);
8130 }
8131
8132 /*
8133 * Even though the error may have occurred on the other port
8134 * we still need to increment the vf error reference count for
8135 * both ports because the I/O resume function will be called
8136 * for both of them.
8137 */
8138 adapter->vferr_refcount++;
8139
8140 return PCI_ERS_RESULT_RECOVERED;
8141
8142skip_bad_vf_detection:
8143#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008144 netif_device_detach(netdev);
8145
Breno Leitao3044b8d2009-05-06 10:44:26 +00008146 if (state == pci_channel_io_perm_failure)
8147 return PCI_ERS_RESULT_DISCONNECT;
8148
Auke Kok9a799d72007-09-15 14:07:45 -07008149 if (netif_running(netdev))
8150 ixgbe_down(adapter);
8151 pci_disable_device(pdev);
8152
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008153 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008154 return PCI_ERS_RESULT_NEED_RESET;
8155}
8156
8157/**
8158 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8159 * @pdev: Pointer to PCI device
8160 *
8161 * Restart the card from scratch, as if from a cold-boot.
8162 */
8163static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8164{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008165 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008166 pci_ers_result_t result;
8167 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008168
gouji-new9ce77662009-05-06 10:44:45 +00008169 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008170 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008171 result = PCI_ERS_RESULT_DISCONNECT;
8172 } else {
8173 pci_set_master(pdev);
8174 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008175 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008176
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008177 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008178
8179 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008180 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008181 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008182 }
Auke Kok9a799d72007-09-15 14:07:45 -07008183
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008184 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8185 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008186 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8187 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008188 /* non-fatal, continue */
8189 }
Auke Kok9a799d72007-09-15 14:07:45 -07008190
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008191 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008192}
8193
8194/**
8195 * ixgbe_io_resume - called when traffic can start flowing again.
8196 * @pdev: Pointer to PCI device
8197 *
8198 * This callback is called when the error recovery driver tells us that
8199 * its OK to resume normal operation.
8200 */
8201static void ixgbe_io_resume(struct pci_dev *pdev)
8202{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008203 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8204 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008205
Greg Rose83c61fa2011-09-07 05:59:35 +00008206#ifdef CONFIG_PCI_IOV
8207 if (adapter->vferr_refcount) {
8208 e_info(drv, "Resuming after VF err\n");
8209 adapter->vferr_refcount--;
8210 return;
8211 }
8212
8213#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008214 if (netif_running(netdev))
8215 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008216
8217 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008218}
8219
8220static struct pci_error_handlers ixgbe_err_handler = {
8221 .error_detected = ixgbe_io_error_detected,
8222 .slot_reset = ixgbe_io_slot_reset,
8223 .resume = ixgbe_io_resume,
8224};
8225
8226static struct pci_driver ixgbe_driver = {
8227 .name = ixgbe_driver_name,
8228 .id_table = ixgbe_pci_tbl,
8229 .probe = ixgbe_probe,
8230 .remove = __devexit_p(ixgbe_remove),
8231#ifdef CONFIG_PM
8232 .suspend = ixgbe_suspend,
8233 .resume = ixgbe_resume,
8234#endif
8235 .shutdown = ixgbe_shutdown,
8236 .err_handler = &ixgbe_err_handler
8237};
8238
8239/**
8240 * ixgbe_init_module - Driver Registration Routine
8241 *
8242 * ixgbe_init_module is the first routine called when the driver is
8243 * loaded. All it does is register with the PCI subsystem.
8244 **/
8245static int __init ixgbe_init_module(void)
8246{
8247 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008248 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008249 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008250
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008251#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008252 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008253#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008254
Auke Kok9a799d72007-09-15 14:07:45 -07008255 ret = pci_register_driver(&ixgbe_driver);
8256 return ret;
8257}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008258
Auke Kok9a799d72007-09-15 14:07:45 -07008259module_init(ixgbe_init_module);
8260
8261/**
8262 * ixgbe_exit_module - Driver Exit Cleanup Routine
8263 *
8264 * ixgbe_exit_module is called just before the driver is removed
8265 * from memory.
8266 **/
8267static void __exit ixgbe_exit_module(void)
8268{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008269#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008270 dca_unregister_notify(&dca_notifier);
8271#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008272 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008273 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008274}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008275
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008276#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008277static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008278 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008279{
8280 int ret_val;
8281
8282 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008283 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008284
8285 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8286}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008287
Alexander Duyckb4533682009-03-31 21:32:42 +00008288#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008289
Auke Kok9a799d72007-09-15 14:07:45 -07008290module_exit(ixgbe_exit_module);
8291
8292/* ixgbe_main.c */